Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Refactoring System Registration (#765)
Browse files Browse the repository at this point in the history
* First pass at core system refactor

* fixed compiler errors

added a way to get the system profile
added a way to check if a system is enabled

* use interface type

* better null check for extension services

* fixed system registration

* updated examples checkout

* updated root profile inspector

* removed the core system accessors from the xrtk service locator (#769)

* removed the core system accessors from the xrtk service locator

* updated examples

* updated examples

* Fixed tests

* updated wmr submodule

* updated core access usage

* updated wmr checkout

fixed some componet accessors in teleport system

* updated submodules

* updated packages-lock file

* fixed unit tests

* fixed up the root profile inspector a bit to prevent it from throwing serializable object exceptions

* updated spatail awareness layer utitites

* fixed some some issues with the MixedRealityToolkit.TryGetSystem<T>

added tests to make sure we cannot register a system twice
added icons
  • Loading branch information
StephenHodgson committed Feb 9, 2021
1 parent 011a4d7 commit 7d2d803
Show file tree
Hide file tree
Showing 75 changed files with 1,285 additions and 1,595 deletions.
27 changes: 21 additions & 6 deletions Editor/EditorActiveProfileChangeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

using UnityEditor;
using UnityEngine;
using XRTK.Definitions.SpatialAwarenessSystem;
using XRTK.Editor.Utilities;
using XRTK.Interfaces.InputSystem;
using XRTK.Interfaces.SpatialAwarenessSystem;
using XRTK.Services;

namespace XRTK.Editor
Expand All @@ -19,15 +23,26 @@ private static void EditorApplication_hierarchyChanged()
{
if (MixedRealityToolkit.HasActiveProfile)
{
if (MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled &&
Utilities.InputMappingAxisUtility.CheckUnityInputManagerMappings(Utilities.ControllerMappingUtilities.UnityInputManagerAxes))
if (MixedRealityToolkit.IsSystemEnabled<IMixedRealityInputSystem>() &&
InputMappingAxisUtility.CheckUnityInputManagerMappings(ControllerMappingUtilities.UnityInputManagerAxes))
{
Debug.Log("XRTK Input System was enabled, updated input axis mappings.");
Debug.Log($"{nameof(IMixedRealityInputSystem)} was enabled, updated input axis mappings.");
}
else if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled &&
Utilities.InputMappingAxisUtility.RemoveMappings(Utilities.ControllerMappingUtilities.UnityInputManagerAxes))
else if (!MixedRealityToolkit.IsSystemEnabled<IMixedRealityInputSystem>() &&
InputMappingAxisUtility.RemoveMappings(ControllerMappingUtilities.UnityInputManagerAxes))
{
Debug.Log("XRTK Input System was disabled, removed input axis mappings.");
Debug.Log($"{nameof(IMixedRealityInputSystem)} was disabled, removed input axis mappings.");
}

if (MixedRealityToolkit.IsSystemEnabled<IMixedRealitySpatialAwarenessSystem>() &&
LayerUtilities.CheckLayers(MixedRealitySpatialAwarenessSystemProfile.SpatialAwarenessLayers))
{
Debug.Log($"{nameof(IMixedRealitySpatialAwarenessSystem)} was enabled, spatial mapping layers added to project.");
}
else if (!MixedRealityToolkit.IsSystemEnabled<IMixedRealitySpatialAwarenessSystem>() &&
LayerUtilities.RemoveLayers(MixedRealitySpatialAwarenessSystemProfile.SpatialAwarenessLayers))
{
Debug.Log($"{nameof(IMixedRealitySpatialAwarenessSystem)} was disabled, spatial mapping layers removed to project.");
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion Editor/MixedRealityToolkitInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class MixedRealityToolkitInspector : UnityEditor.Editor
private SerializedProperty activeProfile;
private int currentPickerWindow = -1;
private bool checkChange;
private UnityEditor.Editor profileInspector;

private void Awake()
{
Expand All @@ -38,6 +39,11 @@ private void OnEnable()
checkChange = activeProfile.objectReferenceValue.IsNull();
}

private void OnDestroy()
{
profileInspector.Destroy();
}

public override void OnInspectorGUI()
{
MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo();
Expand Down Expand Up @@ -120,7 +126,11 @@ public override void OnInspectorGUI()
if (activeProfile.objectReferenceValue != null)
{
var rootProfile = activeProfile.objectReferenceValue as MixedRealityToolkitRootProfile;
var profileInspector = CreateEditor(rootProfile);

if (profileInspector.IsNull())
{
profileInspector = CreateEditor(rootProfile);
}

if (profileInspector is MixedRealityToolkitRootProfileInspector rootProfileInspector)
{
Expand Down
53 changes: 32 additions & 21 deletions Editor/PackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
using UnityEditor;
using UnityEngine;
using XRTK.Definitions;
using XRTK.Definitions.CameraSystem;
using XRTK.Definitions.InputSystem;
using XRTK.Definitions.SpatialAwarenessSystem;
using XRTK.Editor.Extensions;
using XRTK.Editor.Utilities;
using XRTK.Extensions;
using XRTK.Interfaces.CameraSystem;
using XRTK.Interfaces.InputSystem;
using XRTK.Interfaces.Providers;
using XRTK.Interfaces.Providers.SpatialObservers;
using XRTK.Interfaces.SpatialAwarenessSystem;
using XRTK.Services;

namespace XRTK.Editor
Expand Down Expand Up @@ -211,38 +216,44 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration
switch (configurationType)
{
case Type _ when typeof(IMixedRealityCameraDataProvider).IsAssignableFrom(configurationType):
var cameraSystemProfile = rootProfile.CameraSystemProfile;
var cameraDataProviderConfiguration = new MixedRealityServiceConfiguration<IMixedRealityCameraDataProvider>(configuration);

if (cameraSystemProfile.RegisteredServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != cameraDataProviderConfiguration.InstancedType.Type))
if (MixedRealityToolkit.TryGetSystemProfile<IMixedRealityCameraSystem, MixedRealityCameraSystemProfile>(out var cameraSystemProfile))
{
Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
cameraSystemProfile.RegisteredServiceConfigurations = cameraSystemProfile.RegisteredServiceConfigurations.AddItem(cameraDataProviderConfiguration);
EditorUtility.SetDirty(cameraSystemProfile);
var cameraDataProviderConfiguration = new MixedRealityServiceConfiguration<IMixedRealityCameraDataProvider>(configuration);

if (cameraSystemProfile.RegisteredServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != cameraDataProviderConfiguration.InstancedType.Type))
{
Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
cameraSystemProfile.RegisteredServiceConfigurations = cameraSystemProfile.RegisteredServiceConfigurations.AddItem(cameraDataProviderConfiguration);
EditorUtility.SetDirty(cameraSystemProfile);
}
}
break;

case Type _ when typeof(IMixedRealityInputDataProvider).IsAssignableFrom(configurationType):
var inputSystemProfile = rootProfile.InputSystemProfile;
var inputDataProviderConfiguration = new MixedRealityServiceConfiguration<IMixedRealityInputDataProvider>(configuration);

if (inputSystemProfile.RegisteredServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != inputDataProviderConfiguration.InstancedType.Type))
if (MixedRealityToolkit.TryGetSystemProfile<IMixedRealityInputSystem, MixedRealityInputSystemProfile>(out var inputSystemProfile))
{
Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
inputSystemProfile.RegisteredServiceConfigurations = inputSystemProfile.RegisteredServiceConfigurations.AddItem(inputDataProviderConfiguration);
EditorUtility.SetDirty(inputSystemProfile);
var inputDataProviderConfiguration = new MixedRealityServiceConfiguration<IMixedRealityInputDataProvider>(configuration);

if (inputSystemProfile.RegisteredServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != inputDataProviderConfiguration.InstancedType.Type))
{
Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
inputSystemProfile.RegisteredServiceConfigurations = inputSystemProfile.RegisteredServiceConfigurations.AddItem(inputDataProviderConfiguration);
EditorUtility.SetDirty(inputSystemProfile);
}
}
break;

case Type _ when typeof(IMixedRealitySpatialAwarenessDataProvider).IsAssignableFrom(configurationType):
var spatialAwarenessSystemProfile = rootProfile.SpatialAwarenessProfile;
var spatialObserverConfiguration = new MixedRealityServiceConfiguration<IMixedRealitySpatialAwarenessDataProvider>(configuration);

if (spatialAwarenessSystemProfile.RegisteredServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != spatialObserverConfiguration.InstancedType.Type))
if (MixedRealityToolkit.TryGetSystemProfile<IMixedRealitySpatialAwarenessSystem, MixedRealitySpatialAwarenessSystemProfile>(out var spatialAwarenessSystemProfile))
{
Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
spatialAwarenessSystemProfile.RegisteredServiceConfigurations = spatialAwarenessSystemProfile.RegisteredServiceConfigurations.AddItem(spatialObserverConfiguration);
EditorUtility.SetDirty(spatialAwarenessSystemProfile);
var spatialObserverConfiguration = new MixedRealityServiceConfiguration<IMixedRealitySpatialAwarenessDataProvider>(configuration);

if (spatialAwarenessSystemProfile.RegisteredServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != spatialObserverConfiguration.InstancedType.Type))
{
Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
spatialAwarenessSystemProfile.RegisteredServiceConfigurations = spatialAwarenessSystemProfile.RegisteredServiceConfigurations.AddItem(spatialObserverConfiguration);
EditorUtility.SetDirty(spatialAwarenessSystemProfile);
}
}
break;
}
Expand Down
1 change: 1 addition & 0 deletions Editor/Profiles/BaseMixedRealityProfileInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class BaseMixedRealityProfileInspector : UnityEditor.Editor
protected virtual void OnEnable()
{
targetProfile = serializedObject;

currentlySelectedProfile = target as BaseMixedRealityProfile;
Debug.Assert(!currentlySelectedProfile.IsNull());
ThisProfile = currentlySelectedProfile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ private void RenderInputProcessors(SerializedProperty inputProcessorList, AxisTy
processorEditor.serializedObject.ApplyModifiedProperties();
}

processorEditor.Destroy();
EditorGUI.indentLevel--;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ public override void OnInspectorGUI()
{
inspector.RenderControllerMappingButton(mappingProfile);
}

profileEditor.Destroy();
}
}

Expand Down
58 changes: 50 additions & 8 deletions Editor/Profiles/MixedRealityServiceProviderProfileInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@
using UnityEditorInternal;
using UnityEngine;
using XRTK.Definitions;
using XRTK.Definitions.Platforms;
using XRTK.Definitions.Utilities;
using XRTK.Editor.Extensions;
using XRTK.Editor.PropertyDrawers;
using XRTK.Extensions;
using XRTK.Interfaces;
using XRTK.Services;

namespace XRTK.Editor.Profiles
{
[CustomEditor(typeof(BaseMixedRealityServiceProfile<>), true, isFallback = true)]
public class MixedRealityServiceProfileInspector : BaseMixedRealityProfileInspector
{
private static readonly Type AllPlatformsType = typeof(AllPlatforms);
private static readonly Guid AllPlatformsGuid = AllPlatformsType.GUID;
private readonly GUIContent profileContent = new GUIContent("Profile", "The settings profile for this service.");
private ReorderableList configurationList;
private int currentlySelectedConfigurationOption;

[SerializeField]
private SerializedProperty configurations; // Cannot be auto property bc field is serialized.

protected SerializedProperty Configurations => configurations;
Expand All @@ -35,6 +38,8 @@ public class MixedRealityServiceProfileInspector : BaseMixedRealityProfileInspec
/// </summary>
protected Type ServiceConstraint { get; set; } = null;

private bool IsSystemConfiguration => typeof(IMixedRealitySystem).IsAssignableFrom(ServiceConstraint);

private List<Tuple<bool, bool>> configListHeightFlags;

protected override void OnEnable()
Expand Down Expand Up @@ -69,6 +74,11 @@ public override void OnInspectorGUI()
{
RenderHeader();
EditorGUILayout.Space();
RenderConfigurationOptions();
}

protected void RenderConfigurationOptions()
{
configurations.isExpanded = EditorGUILayoutExtensions.FoldoutWithBoldLabel(configurations.isExpanded, new GUIContent($"{ServiceConstraint.Name} Configuration Options"));

if (configurations.isExpanded)
Expand Down Expand Up @@ -98,7 +108,9 @@ private float ElementHeightCallback(int index)
var (isExpanded, hasProfile) = configListHeightFlags[index];
var modifier = isExpanded
? hasProfile
? 5.5f
? IsSystemConfiguration
? 4f
: 5.5f
: 4f
: 1.5f;
return EditorGUIUtility.singleLineHeight * modifier;
Expand All @@ -124,7 +136,6 @@ private void DrawConfigurationOptionElement(Rect rect, int index, bool isActive,
var configurationProfileProperty = configurationProperty.FindPropertyRelative("profile");

var hasProfile = false;

Type profileType = null;

if (systemTypeReference.Type != null)
Expand Down Expand Up @@ -197,15 +208,46 @@ private void DrawConfigurationOptionElement(Rect rect, int index, bool isActive,
{
TypeReferencePropertyDrawer.FilterConstraintOverride = type =>
{
return !type.IsAbstract &&
type.GetInterfaces().Any(interfaceType => interfaceType == ServiceConstraint);
var isValid = !type.IsAbstract &&
type.GetInterfaces().Any(interfaceType => interfaceType == ServiceConstraint);
return isValid && (!IsSystemConfiguration || MixedRealityToolkit.Instance.ActiveProfile.RegisteredServiceConfigurations.All(configuration => configuration.InstancedType.Type != type));
};
TypeReferencePropertyDrawer.CreateNewTypeOverride = ServiceConstraint;

EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(typeRect, instanceTypeProperty);
systemTypeReference = new SystemType(instanceTypeProperty.FindPropertyRelative("reference").stringValue);

EditorGUI.PropertyField(runtimeRect, platformEntriesProperty);
runtimePlatformProperty = platformEntriesProperty.FindPropertyRelative("runtimePlatforms");
if (EditorGUI.EndChangeCheck())
{
if (systemTypeReference.Type == null)
{
nameProperty.stringValue = string.Empty;
configurationProfileProperty.objectReferenceValue = null;
}
else
{
nameProperty.stringValue = systemTypeReference.Type.Name.ToProperCase();

if (IsSystemConfiguration)
{
configurationProfileProperty.objectReferenceValue = null;
}
}
}

if (!IsSystemConfiguration)
{
EditorGUI.PropertyField(runtimeRect, platformEntriesProperty);
runtimePlatformProperty = platformEntriesProperty.FindPropertyRelative("runtimePlatforms");
}
else
{
runtimePlatformProperty = platformEntriesProperty.FindPropertyRelative("runtimePlatforms");
runtimePlatformProperty.arraySize = 1;
runtimePlatformProperty.GetArrayElementAtIndex(0).FindPropertyRelative("reference").stringValue = AllPlatformsGuid.ToString();
}

if (hasProfile)
{
Expand All @@ -232,7 +274,7 @@ private void DrawConfigurationOptionElement(Rect rect, int index, bool isActive,

if (MixedRealityToolkit.IsInitialized &&
runtimePlatformProperty.arraySize > 0 &&
systemTypeReference?.Type != null)
systemTypeReference.Type != null)
{
MixedRealityToolkit.Instance.ResetProfile(MixedRealityToolkit.Instance.ActiveProfile);
}
Expand Down
Loading

0 comments on commit 7d2d803

Please sign in to comment.