Skip to content

Commit

Permalink
NRE protections and disabling of the Unity log for the camera being r…
Browse files Browse the repository at this point in the history
…ecreated in the editor

See - realitycollective/realitytoolkit.dev#49
  • Loading branch information
SimonDarksideJ committed Sep 3, 2022
1 parent 108eeb7 commit ea26f02
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
27 changes: 22 additions & 5 deletions Editor/PackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration
}

var didInstallConfigurations = false;
var configurationsAlreadyInstalled = false;
foreach (var configuration in platformConfigurationProfile.Configurations)
{
var configurationType = configuration.InstancedType.Type;
Expand Down Expand Up @@ -298,7 +299,11 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration
{
var cameraDataProviderConfiguration = new ServiceConfiguration<IMixedRealityCameraDataProvider>(configuration);

if (cameraSystemProfile.ServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != cameraDataProviderConfiguration.InstancedType.Type))
if (cameraSystemProfile.ServiceConfigurations.Any(serviceConfiguration => serviceConfiguration.InstancedType.Type == cameraDataProviderConfiguration.InstancedType.Type))
{
configurationsAlreadyInstalled = true;
}
else if (cameraSystemProfile.ServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != cameraDataProviderConfiguration.InstancedType.Type))
{
Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
cameraSystemProfile.AddConfiguration(cameraDataProviderConfiguration);
Expand All @@ -313,7 +318,11 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration
{
var inputDataProviderConfiguration = new ServiceConfiguration<IMixedRealityInputDataProvider>(configuration);

if (inputSystemProfile.ServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != inputDataProviderConfiguration.InstancedType.Type))
if (inputSystemProfile.ServiceConfigurations.Any(serviceConfiguration => serviceConfiguration.InstancedType.Type == inputDataProviderConfiguration.InstancedType.Type))
{
configurationsAlreadyInstalled = true;
}
else if (inputSystemProfile.ServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != inputDataProviderConfiguration.InstancedType.Type))
{
Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
inputSystemProfile.AddConfiguration(inputDataProviderConfiguration);
Expand All @@ -328,7 +337,11 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration
{
var spatialObserverConfiguration = new ServiceConfiguration<IMixedRealitySpatialAwarenessDataProvider>(configuration);

if (spatialAwarenessSystemProfile.ServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != spatialObserverConfiguration.InstancedType.Type))
if (spatialAwarenessSystemProfile.ServiceConfigurations.Any(serviceConfiguration => serviceConfiguration.InstancedType.Type == spatialObserverConfiguration.InstancedType.Type))
{
configurationsAlreadyInstalled = true;
}
else if (spatialAwarenessSystemProfile.ServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != spatialObserverConfiguration.InstancedType.Type))
{
Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
spatialAwarenessSystemProfile.AddConfiguration(spatialObserverConfiguration);
Expand All @@ -342,7 +355,11 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration
{
var boundarySystemConfiguration = new ServiceConfiguration<IMixedRealityBoundaryDataProvider>(configuration);

if (boundarySystemProfile.ServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != boundarySystemConfiguration.InstancedType.Type))
if (boundarySystemProfile.ServiceConfigurations.Any(serviceConfiguration => serviceConfiguration.InstancedType.Type != boundarySystemConfiguration.InstancedType.Type))
{
configurationsAlreadyInstalled = true;
}
else if (boundarySystemProfile.ServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != boundarySystemConfiguration.InstancedType.Type))
{
Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
boundarySystemProfile.AddConfiguration(boundarySystemConfiguration);
Expand All @@ -357,7 +374,7 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration
AssetDatabase.SaveAssets();
EditorApplication.delayCall += () => AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);

if (didInstallConfigurations)
if (didInstallConfigurations || configurationsAlreadyInstalled)
{
ServiceManager.Instance.ResetProfile(ServiceManager.Instance.ActiveProfile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ public override void OnInspectorGUI()

if (GUILayout.Button("Install Platform Service Configuration"))
{
EditorApplication.delayCall += () => PackageInstaller.InstallConfiguration(target as MixedRealityPlatformServiceConfigurationProfile, ServiceManager.Instance.ActiveProfile);
if (!(ServiceManager.Instance is null) && ServiceManager.Instance.HasActiveProfile)
{
EditorApplication.delayCall += () => PackageInstaller.InstallConfiguration(target as MixedRealityPlatformServiceConfigurationProfile, ServiceManager.Instance.ActiveProfile);
}
else
{
Debug.LogError("Unable to install profile as the Service Framework could not be found.\nIs there a Service Framework instance in the scene and the Reality Toolkit configured?");
}
}

EditorGUILayout.Space();
Expand Down
2 changes: 2 additions & 0 deletions Runtime/CameraSystem/Providers/BaseCameraDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ private void EnsureCameraRigSetup(bool resetCameraToOrigin)

CameraRig = CameraCache.Main.transform.parent.gameObject.EnsureComponent(cameraRigType) as IMixedRealityCameraRig;
Debug.Assert(CameraRig != null);
#if !UNITY_EDITOR
Debug.Log($"There was no {MixedRealityCameraSystem.DefaultXRCameraRigName} in the scene. The {GetType().Name} requires one and added it, as well as making the main camera a child of the rig.");
#endif
}

if (!string.Equals(CameraRig.RigTransform.name, MixedRealityCameraSystem.DefaultXRCameraRigName))
Expand Down

0 comments on commit ea26f02

Please sign in to comment.