From 07f8b832cef1b4be7f441d47beb0170d3eba899b Mon Sep 17 00:00:00 2001 From: StephenHodgson Date: Mon, 6 May 2019 09:57:36 -0700 Subject: [PATCH] No longer require the service locator to configure profiles --- Submodules/SDK | 2 +- Submodules/WindowsMixedReality | 2 +- .../Definitions/BaseMixedRealityProfile.cs | 12 ++ .../Devices/ControllerMappingLibrary.cs | 38 +++--- .../Inspectors/ControllerPopupWindow.cs | 53 ++++---- .../MixedRealityStandardShaderGUI.cs | 32 ++--- ...ealityControllerMappingProfileInspector.cs | 65 +++------- .../BaseMixedRealityProfileInspector.cs | 30 ++++- ...tyBoundaryVisualizationProfileInspector.cs | 17 +-- .../MixedRealityCameraProfileInspector.cs | 17 +-- ...yControllerDataProviderProfileInspector.cs | 42 +----- ...alityControllerMappingProfilesInspector.cs | 52 +------- ...ControllerVisualizationProfileInspector.cs | 62 +++------ ...ealityDiagnosticsSystemProfileInspector.cs | 19 +-- .../MixedRealityGesturesProfileInspector.cs | 58 ++++----- .../MixedRealityInputActionRulesInspector.cs | 121 +++++++++--------- ...ixedRealityInputActionsProfileInspector.cs | 37 ++---- ...MixedRealityInputSystemProfileInspector.cs | 36 ++---- ...xedRealityNetworkSystemProfileInspector.cs | 20 +-- .../MixedRealityPointerProfileInspector.cs | 19 +-- ...gisteredServiceProviderProfileInspector.cs | 26 ++-- ...edRealitySpeechCommandsProfileInspector.cs | 57 ++++----- ...ityToolkitConfigurationProfileInspector.cs | 35 ++--- ...litySpatialMeshObserverProfileInspector.cs | 10 -- ...dRealitySpatialObserverProfileInspector.cs | 36 +----- ...dRealitySurfaceObserverProfileInspector.cs | 11 -- ...ySpatialAwarenessSystemProfileInspector.cs | 24 +--- .../InputActionPropertyDrawer.cs | 50 ++++---- .../CameraSystem/MixedRealityCameraSystem.cs | 8 +- .../Services/MixedRealityToolkit.cs | 25 ++-- 30 files changed, 370 insertions(+), 646 deletions(-) diff --git a/Submodules/SDK b/Submodules/SDK index bff35f28c..774b53954 160000 --- a/Submodules/SDK +++ b/Submodules/SDK @@ -1 +1 @@ -Subproject commit bff35f28c306b2ac8ec6a7f09d1eb015215afde8 +Subproject commit 774b539544955a33e79e623aa29593ba5e4479ba diff --git a/Submodules/WindowsMixedReality b/Submodules/WindowsMixedReality index 9126a4932..43b42fff8 160000 --- a/Submodules/WindowsMixedReality +++ b/Submodules/WindowsMixedReality @@ -1 +1 @@ -Subproject commit 9126a4932608695f74555f490e49e6f1de5d15f0 +Subproject commit 43b42fff81df9532a6de01eafebe1bae57108026 diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/BaseMixedRealityProfile.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/BaseMixedRealityProfile.cs index 45dcd0a33..104609785 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Definitions/BaseMixedRealityProfile.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/BaseMixedRealityProfile.cs @@ -11,5 +11,17 @@ public abstract class BaseMixedRealityProfile : ScriptableObject private bool isCustomProfile = true; internal bool IsCustomProfile => isCustomProfile; + + [SerializeField] + private BaseMixedRealityProfile parentProfile = null; + + /// + /// The profile's parent. + /// + public BaseMixedRealityProfile ParentProfile + { + get => parentProfile; + internal set => parentProfile = value; + } } } \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Devices/ControllerMappingLibrary.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Devices/ControllerMappingLibrary.cs index c0b5c44bf..37079cb34 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Definitions/Devices/ControllerMappingLibrary.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Devices/ControllerMappingLibrary.cs @@ -238,12 +238,13 @@ public static class ControllerMappingLibrary /// /// Gets a texture for the based on a list of the active . /// + /// /// /// /// The texture for the controller type, if none found then a generic texture is returned. - public static Texture2D GetControllerTexture(SupportedControllerType controllerType, Handedness handedness) + public static Texture2D GetControllerTexture(BaseMixedRealityControllerMappingProfile mappingProfile, SupportedControllerType controllerType, Handedness handedness) { - return GetControllerTextureCached(controllerType, handedness); + return GetControllerTextureCached(mappingProfile, controllerType, handedness); } /// @@ -252,44 +253,35 @@ public static Texture2D GetControllerTexture(SupportedControllerType controllerT /// /// /// The scaled texture for the controller type, if none found then a generic texture is returned. - public static Texture2D GetControllerTextureScaled(SupportedControllerType controllerType, Handedness handedness) + public static Texture2D GetControllerTextureScaled(BaseMixedRealityControllerMappingProfile mappingProfile, SupportedControllerType controllerType, Handedness handedness) { - return GetControllerTextureCached(controllerType, handedness, true); + return GetControllerTextureCached(mappingProfile, controllerType, handedness, true); } - private static Texture2D GetControllerTextureCached(SupportedControllerType controllerType, Handedness handedness, bool scaled = false) + private static Texture2D GetControllerTextureCached(BaseMixedRealityControllerMappingProfile mappingProfile, SupportedControllerType controllerType, Handedness handedness, bool scaled = false) { var key = new Tuple(controllerType, handedness, scaled); - if (CachedTextures.TryGetValue(key, out Texture2D texture)) + if (CachedTextures.TryGetValue(key, out var texture)) { return texture; } - texture = GetControllerTextureInternal(controllerType, handedness, scaled); + texture = GetControllerTextureInternal(mappingProfile, controllerType, handedness, scaled); CachedTextures.Add(key, texture); return texture; } - private static Texture2D GetControllerTextureInternal(SupportedControllerType controllerType, Handedness handedness, bool scaled) + private static Texture2D GetControllerTextureInternal(BaseMixedRealityControllerMappingProfile mappingProfile, SupportedControllerType controllerType, Handedness handedness, bool scaled) { - var profiles = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.ControllerMappingProfiles; - - if (MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled && - profiles != null) + if (mappingProfile != null && + mappingProfile.ControllerType == controllerType) { - foreach (var profile in profiles.ControllerMappingProfiles) + var texture = GetControllerTextureInternal(mappingProfile.TexturePath, handedness, scaled); + + if (texture != null) { - if (profile != null && - profile.ControllerType == controllerType) - { - var texture = GetControllerTextureInternal(profile.TexturePath, handedness, scaled); - - if (texture != null) - { - return texture; - } - } + return texture; } } diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/ControllerPopupWindow.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/ControllerPopupWindow.cs index 432bd2cf9..d90d97393 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/ControllerPopupWindow.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/ControllerPopupWindow.cs @@ -11,7 +11,9 @@ using XRTK.Definitions.InputSystem; using XRTK.Definitions.Utilities; using XRTK.Inspectors.Data; +using XRTK.Inspectors.Profiles; using XRTK.Inspectors.Utilities; +using XRTK.Providers.Controllers; using XRTK.Services; using XRTK.Utilities.Editor; @@ -92,17 +94,22 @@ public class ControllerPopupWindow : EditorWindow private Texture2D currentControllerTexture; private ControllerInputActionOption currentControllerOption; + private MixedRealityInputSystemProfile inputSystemProfile; + private static BaseMixedRealityControllerMappingProfile mappingProfile; + private bool IsCustomController => currentControllerType == SupportedControllerType.GenericOpenVR || currentControllerType == SupportedControllerType.GenericUnity; private static string EditorWindowOptionsPath => $"{MixedRealityEditorSettings.MixedRealityToolkit_RelativeFolderPath}/Inspectors/Data/EditorWindowOptions.json"; private void OnFocus() { - currentControllerTexture = ControllerMappingLibrary.GetControllerTexture(currentControllerType, currentHandedness); + currentControllerTexture = ControllerMappingLibrary.GetControllerTexture(mappingProfile, currentControllerType, currentHandedness); + inputSystemProfile = mappingProfile.ParentProfile.ParentProfile as MixedRealityInputSystemProfile; #region Interaction Constraint Setup - actionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + + actionIds = inputSystemProfile.InputActionsProfile.InputActions .Select(action => (int)action.Id) .Prepend(0).ToArray(); @@ -110,81 +117,81 @@ private void OnFocus() .Select(axis => new GUIContent(axis.Name)) .Prepend(new GUIContent("None")).ToArray(); - actionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + actionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.None) .Select(action => (int)action.Id) .Prepend(0).ToArray(); - actionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + actionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.None) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); - rawActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + rawActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.Raw) .Select(action => (int)action.Id) .Prepend(0).ToArray(); - rawActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + rawActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.Raw) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); - digitalActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + digitalActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.Digital) .Select(action => (int)action.Id) .Prepend(0).ToArray(); - digitalActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + digitalActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.Digital) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); - singleAxisActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + singleAxisActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.SingleAxis) .Select(action => (int)action.Id) .Prepend(0).ToArray(); - singleAxisActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + singleAxisActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.SingleAxis) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); - dualAxisActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + dualAxisActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.DualAxis) .Select(action => (int)action.Id).Prepend(0).ToArray(); - dualAxisActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + dualAxisActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.DualAxis) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); - threeDofPositionActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + threeDofPositionActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofPosition) .Select(action => (int)action.Id) .Prepend(0).ToArray(); - threeDofPositionActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + threeDofPositionActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofPosition) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); - threeDofRotationActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + threeDofRotationActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofRotation) .Select(action => (int)action.Id) .Prepend(0).ToArray(); - threeDofRotationActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + threeDofRotationActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofRotation) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); - sixDofActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + sixDofActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.SixDof) .Select(action => (int)action.Id) .Prepend(0).ToArray(); - sixDofActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + sixDofActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == AxisType.SixDof) .Select(inputAction => new GUIContent(inputAction.Description)) .Prepend(new GUIContent("None")).ToArray(); @@ -192,10 +199,8 @@ private void OnFocus() #endregion Interaction Constraint Setup } - public static void Show(SupportedControllerType controllerType, SerializedProperty interactionsList, Handedness handedness = Handedness.None, bool isLocked = false) + public static void Show(BaseMixedRealityControllerMappingProfile profile, SupportedControllerType controllerType, SerializedProperty interactionsList, Handedness handedness = Handedness.None, bool isLocked = false) { - window = (ControllerPopupWindow)GetWindow(typeof(ControllerPopupWindow)); - window.Close(); window = (ControllerPopupWindow)CreateInstance(typeof(ControllerPopupWindow)); var handednessTitleText = handedness != Handedness.None ? $"{handedness} Hand " : string.Empty; window.titleContent = new GUIContent($"{controllerType} {handednessTitleText}Input Action Assignment"); @@ -204,7 +209,7 @@ public static void Show(SupportedControllerType controllerType, SerializedProper window.isLocked = isLocked; window.currentInteractionList = interactionsList; isMouseInRects = new bool[interactionsList.arraySize]; - + mappingProfile = profile; var asset = AssetDatabase.LoadAssetAtPath(EditorWindowOptionsPath); if (asset == null) @@ -492,7 +497,7 @@ private void RenderInteractionList(SerializedProperty interactionList, bool useC if (EditorGUI.EndChangeCheck()) { - var inputAction = actionId.intValue == 0 ? MixedRealityInputAction.None : MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1]; + var inputAction = actionId.intValue == 0 ? MixedRealityInputAction.None : inputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1]; actionDescription.stringValue = inputAction.Description; actionConstraint.enumValueIndex = (int)inputAction.AxisConstraint; } @@ -732,7 +737,7 @@ private void RenderInteractionList(SerializedProperty interactionList, bool useC { MixedRealityInputAction inputAction = actionId.intValue == 0 ? MixedRealityInputAction.None : - MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1]; + inputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1]; actionId.intValue = (int)inputAction.Id; actionDescription.stringValue = inputAction.Description; actionConstraint.enumValueIndex = (int)inputAction.AxisConstraint; diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/MixedRealityStandardShaderGUI.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/MixedRealityStandardShaderGUI.cs index 88075c6a7..31e4ea2b0 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/MixedRealityStandardShaderGUI.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/MixedRealityStandardShaderGUI.cs @@ -345,32 +345,32 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader) { // Cache old shader properties with potentially different names than the new shader. - float? smoothness = GetFloatProperty(material, "_Glossiness"); + float? smoothnessProperty = GetFloatProperty(material, "_Glossiness"); float? diffuse = GetFloatProperty(material, "_UseDiffuse"); - float? specularHighlights = GetFloatProperty(material, "_SpecularHighlights"); - float? normalMap = null; + float? specularHighlightsProperty = GetFloatProperty(material, "_SpecularHighlights"); + float? normalMapProperty = null; Texture normalMapTexture = material.GetTexture(BumpMap); - float? normalMapScale = GetFloatProperty(material, "_BumpScale"); + float? normalMapScaleProperty = GetFloatProperty(material, "_BumpScale"); float? emission = null; Color? emissionColor = GetColorProperty(material, "_EmissionColor"); - float? reflections = null; + float? reflectionsProperty = null; float? rimLighting = null; Vector4? textureScaleOffset = null; - float? cullMode = GetFloatProperty(material, "_Cull"); + float? cullModeProperty = GetFloatProperty(material, "_Cull"); if (oldShader) { if (oldShader.name.Contains("Standard")) { - normalMap = material.IsKeywordEnabled("_NORMALMAP") ? 1.0f : 0.0f; + normalMapProperty = material.IsKeywordEnabled("_NORMALMAP") ? 1.0f : 0.0f; emission = material.IsKeywordEnabled("_EMISSION") ? 1.0f : 0.0f; - reflections = GetFloatProperty(material, "_GlossyReflections"); + reflectionsProperty = GetFloatProperty(material, "_GlossyReflections"); } else if (oldShader.name.Contains("Fast Configurable")) { - normalMap = material.IsKeywordEnabled("_USEBUMPMAP_ON") ? 1.0f : 0.0f; + normalMapProperty = material.IsKeywordEnabled("_USEBUMPMAP_ON") ? 1.0f : 0.0f; emission = GetFloatProperty(material, "_UseEmissionColor"); - reflections = GetFloatProperty(material, "_UseReflections"); + reflectionsProperty = GetFloatProperty(material, "_UseReflections"); rimLighting = GetFloatProperty(material, "_UseRimLighting"); textureScaleOffset = GetVectorProperty(material, "_TextureScaleOffset"); } @@ -379,23 +379,23 @@ public override void AssignNewShaderToMaterial(Material material, Shader oldShad base.AssignNewShaderToMaterial(material, oldShader, newShader); // Apply old shader properties to the new shader. - SetFloatProperty(material, null, "_Smoothness", smoothness); + SetFloatProperty(material, null, "_Smoothness", smoothnessProperty); SetFloatProperty(material, "_DIRECTIONAL_LIGHT", "_DirectionalLight", diffuse); - SetFloatProperty(material, "_SPECULAR_HIGHLIGHTS", "_SpecularHighlights", specularHighlights); - SetFloatProperty(material, "_NORMAL_MAP", "_EnableNormalMap", normalMap); + SetFloatProperty(material, "_SPECULAR_HIGHLIGHTS", "_SpecularHighlights", specularHighlightsProperty); + SetFloatProperty(material, "_NORMAL_MAP", "_EnableNormalMap", normalMapProperty); if (normalMapTexture) { material.SetTexture(NormalMap, normalMapTexture); } - SetFloatProperty(material, null, "_NormalMapScale", normalMapScale); + SetFloatProperty(material, null, "_NormalMapScale", normalMapScaleProperty); SetFloatProperty(material, "_EMISSION", "_EnableEmission", emission); SetColorProperty(material, "_EmissiveColor", emissionColor); - SetFloatProperty(material, "_REFLECTIONS", "_Reflections", reflections); + SetFloatProperty(material, "_REFLECTIONS", "_Reflections", reflectionsProperty); SetFloatProperty(material, "_RIM_LIGHT", "_RimLight", rimLighting); SetVectorProperty(material, "_MainTex_ST", textureScaleOffset); - SetFloatProperty(material, null, "_CullMode", cullMode); + SetFloatProperty(material, null, "_CullMode", cullModeProperty); // Setup the rendering mode based on the old shader. if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/")) diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/BaseMixedRealityControllerMappingProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/BaseMixedRealityControllerMappingProfileInspector.cs index cfd1806d4..c2526506a 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/BaseMixedRealityControllerMappingProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/BaseMixedRealityControllerMappingProfileInspector.cs @@ -4,12 +4,10 @@ using System.Collections.Generic; using UnityEditor; using UnityEngine; -using XRTK.Definitions; using XRTK.Definitions.Devices; using XRTK.Definitions.Utilities; using XRTK.Inspectors.Utilities; using XRTK.Providers.Controllers; -using XRTK.Services; namespace XRTK.Inspectors.Profiles { @@ -18,9 +16,9 @@ public class BaseMixedRealityControllerMappingProfileInspector : BaseMixedRealit { private struct ControllerItem { - public SupportedControllerType ControllerType; - public Handedness Handedness; - public MixedRealityInteractionMapping[] Interactions; + public readonly SupportedControllerType ControllerType; + public readonly Handedness Handedness; + public readonly MixedRealityInteractionMapping[] Interactions; public ControllerItem(SupportedControllerType controllerType, Handedness handedness, MixedRealityInteractionMapping[] interactions) { @@ -34,7 +32,7 @@ public ControllerItem(SupportedControllerType controllerType, Handedness handedn private SerializedProperty controllerMappings; - private BaseMixedRealityControllerMappingProfile profile; + private BaseMixedRealityControllerMappingProfile controllerMappingProfile; private GUIStyle controllerButtonStyle; @@ -42,58 +40,25 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled || - MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile == null) - { - return; - } - controllerMappings = serializedObject.FindProperty("controllerMappings"); - profile = target as BaseMixedRealityControllerMappingProfile; + controllerMappingProfile = target as BaseMixedRealityControllerMappingProfile; } public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to controller mapping list")) { - return; - } - - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled) - { - EditorGUILayout.HelpBox("No input system is enabled, or you need to specify the type in the main configuration profile.", MessageType.Error); - - if (GUILayout.Button("Back to Configuration Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; - } - - return; - } - - if (GUILayout.Button("Back to controller mapping list")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.ControllerMappingProfiles; + Selection.activeObject = thisProfile.ParentProfile; } EditorGUILayout.Space(); - var deviceName = profile.ControllerType == SupportedControllerType.None ? "Custom Device" : profile.ControllerType.ToString(); + var deviceName = controllerMappingProfile.ControllerType == SupportedControllerType.None ? "Custom Device" : controllerMappingProfile.ControllerType.ToString(); EditorGUILayout.LabelField($"{deviceName} Mappings", EditorStyles.boldLabel); - if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile == null) - { - EditorGUILayout.HelpBox("No input actions found, please specify a input action profile in the main configuration.", MessageType.Error); - return; - } - - (target as BaseMixedRealityProfile).CheckProfileLock(false); + controllerMappingProfile.CheckProfileLock(false); if (controllerButtonStyle == null) { @@ -120,7 +85,7 @@ public override void OnInspectorGUI() for (int i = 0; i < controllerMappings?.arraySize; i++) { - var supportedControllerType = profile.ControllerType; + var supportedControllerType = controllerMappingProfile.ControllerType; var controllerMapping = controllerMappings.GetArrayElementAtIndex(i); var handednessValue = controllerMapping.FindPropertyRelative("handedness"); var handedness = (Handedness)handednessValue.intValue; @@ -134,7 +99,7 @@ public override void OnInspectorGUI() if (controllerItems[j].ControllerType == supportedControllerType && controllerItems[j].Handedness == handedness) { - profile.ControllerMappings[i].SynchronizeInputActions(controllerItems[j].Interactions); + controllerMappingProfile.ControllerMappings[i].SynchronizeInputActions(controllerItems[j].Interactions); serializedObject.ApplyModifiedProperties(); skip = true; } @@ -142,7 +107,7 @@ public override void OnInspectorGUI() if (skip) { continue; } - controllerItems.Add(new ControllerItem(supportedControllerType, handedness, profile.ControllerMappings[i].Interactions)); + controllerItems.Add(new ControllerItem(supportedControllerType, handedness, controllerMappingProfile.ControllerMappings[i].Interactions)); string handednessContent = string.Empty; @@ -163,12 +128,12 @@ public override void OnInspectorGUI() GUILayout.BeginHorizontal(); } - var buttonContent = new GUIContent($"Edit {description.stringValue}{handednessContent}", ControllerMappingLibrary.GetControllerTextureScaled(supportedControllerType, handedness)); + var buttonContent = new GUIContent($"Edit {description.stringValue}{handednessContent}", ControllerMappingLibrary.GetControllerTextureScaled(controllerMappingProfile, supportedControllerType, handedness)); if (GUILayout.Button(buttonContent, controllerButtonStyle, GUILayout.Height(128f), GUILayout.MinWidth(32f), GUILayout.ExpandWidth(true))) { serializedObject.ApplyModifiedProperties(); - ControllerPopupWindow.Show(profile.ControllerType, interactions, handedness, MixedRealityPreferences.LockProfiles && !((BaseMixedRealityProfile)target).IsCustomProfile); + EditorApplication.delayCall += () => ControllerPopupWindow.Show(controllerMappingProfile, controllerMappingProfile.ControllerType, interactions, handedness, MixedRealityPreferences.LockProfiles && !thisProfile.IsCustomProfile); } if (handedness != Handedness.Left) diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/BaseMixedRealityProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/BaseMixedRealityProfileInspector.cs index e46099d5c..9930b7006 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/BaseMixedRealityProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/BaseMixedRealityProfileInspector.cs @@ -24,36 +24,42 @@ public abstract class BaseMixedRealityProfileInspector : Editor private static BaseMixedRealityProfile profile; private static BaseMixedRealityProfile profileToCopy; + protected BaseMixedRealityProfile thisProfile; + protected virtual void OnEnable() { targetProfile = serializedObject; profile = target as BaseMixedRealityProfile; + Debug.Assert(profile != null); + thisProfile = profile; } /// /// Renders a . /// + /// The parent of the profile being rendered. /// the property. /// The GUIContent for the field. /// Optional flag to hide the create button. /// True, if the profile changed. - protected static bool RenderProfile(SerializedProperty property, GUIContent guiContent, bool showAddButton = true) + protected static bool RenderProfile(BaseMixedRealityProfile parentProfile, SerializedProperty property, GUIContent guiContent, bool showAddButton = true) { - return RenderProfileInternal(property, guiContent, showAddButton); + return RenderProfileInternal(parentProfile, property, guiContent, showAddButton); } /// /// Renders a . /// + /// The parent of the profile being rendered. /// the property. /// Optional flag to hide the create button. /// True, if the profile changed. - protected static bool RenderProfile(SerializedProperty property, bool showAddButton = true) + protected static bool RenderProfile(BaseMixedRealityProfile parentProfile, SerializedProperty property, bool showAddButton = true) { - return RenderProfileInternal(property, null, showAddButton); + return RenderProfileInternal(parentProfile, property, null, showAddButton); } - private static bool RenderProfileInternal(SerializedProperty property, GUIContent guiContent, bool showAddButton) + private static bool RenderProfileInternal(BaseMixedRealityProfile parentProfile, SerializedProperty property, GUIContent guiContent, bool showAddButton) { bool changed = false; EditorGUILayout.BeginHorizontal(); @@ -107,6 +113,20 @@ private static bool RenderProfileInternal(SerializedProperty property, GUIConten } } + if (property.objectReferenceValue != null) + { + var renderedProfile = property.objectReferenceValue as BaseMixedRealityProfile; + Debug.Assert(renderedProfile != null); + + if (renderedProfile.ParentProfile == null) + { + renderedProfile.ParentProfile = parentProfile; + EditorUtility.SetDirty(renderedProfile); + property.objectReferenceValue = renderedProfile; + property.serializedObject.ApplyModifiedProperties(); + } + } + if (oldObject != property.objectReferenceValue) { changed = true; diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityBoundaryVisualizationProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityBoundaryVisualizationProfileInspector.cs index 9e2e2f3d7..3e3f68d20 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityBoundaryVisualizationProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityBoundaryVisualizationProfileInspector.cs @@ -5,9 +5,7 @@ using UnityEngine; using XRTK.Definitions; using XRTK.Definitions.BoundarySystem; -using XRTK.Definitions.Utilities; using XRTK.Inspectors.Utilities; -using XRTK.Services; namespace XRTK.Inspectors.Profiles { @@ -44,11 +42,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - boundaryHeight = serializedObject.FindProperty("boundaryHeight"); showFloor = serializedObject.FindProperty("showFloor"); @@ -77,14 +70,10 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) - { - return; - } - - if (GUILayout.Button("Back to Configuration Profile")) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Configuration Profile")) { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; + Selection.activeObject = thisProfile.ParentProfile; } EditorGUILayout.Space(); diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityCameraProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityCameraProfileInspector.cs index c779fb8ff..055aa0153 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityCameraProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityCameraProfileInspector.cs @@ -5,7 +5,6 @@ using UnityEngine; using XRTK.Definitions; using XRTK.Inspectors.Utilities; -using XRTK.Services; namespace XRTK.Inspectors.Profiles { @@ -30,11 +29,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - isCameraPersistent = serializedObject.FindProperty("isCameraPersistent"); opaqueNearClip = serializedObject.FindProperty("nearClipPlaneOpaqueDisplay"); opaqueClearFlags = serializedObject.FindProperty("cameraClearFlagsOpaqueDisplay"); @@ -50,21 +44,18 @@ protected override void OnEnable() public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) - { - return; - } - if (GUILayout.Button("Back to Configuration Profile")) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Configuration Profile")) { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; + Selection.activeObject = thisProfile.ParentProfile; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Camera Profile", EditorStyles.boldLabel); EditorGUILayout.HelpBox("The Camera Profile helps tweak camera settings no matter what platform you're building for.", MessageType.Info); - (target as BaseMixedRealityProfile).CheckProfileLock(); + thisProfile.CheckProfileLock(); serializedObject.Update(); diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityControllerDataProviderProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityControllerDataProviderProfileInspector.cs index 0102dfa37..0ecbdcc66 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityControllerDataProviderProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityControllerDataProviderProfileInspector.cs @@ -3,9 +3,8 @@ using UnityEditor; using UnityEngine; -using XRTK.Providers.Controllers; -using XRTK.Definitions; using XRTK.Inspectors.Utilities; +using XRTK.Providers.Controllers; using XRTK.Services; namespace XRTK.Inspectors.Profiles @@ -25,17 +24,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled || - MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile == null) - { - return; - } - controllerDataProviders = serializedObject.FindProperty("registeredControllerDataProviders"); foldouts = new bool[controllerDataProviders.arraySize]; } @@ -44,33 +32,17 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) - { - return; - } - - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled) - { - EditorGUILayout.HelpBox("No input system is enabled, or you need to specify the type in the main configuration profile.", MessageType.Error); - - if (GUILayout.Button("Back to Configuration Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; - } - - return; - } - - if (GUILayout.Button("Back to Input Profile")) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Input Profile")) { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile; + Selection.activeObject = thisProfile.ParentProfile; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Controller Data Providers", EditorStyles.boldLabel); EditorGUILayout.HelpBox("Use this profile to define all the input sources your application can get input data from.", MessageType.Info); - (target as BaseMixedRealityProfile).CheckProfileLock(); + thisProfile.CheckProfileLock(); serializedObject.Update(); @@ -135,7 +107,7 @@ public override void OnInspectorGUI() EditorGUILayout.PropertyField(dataProviderName); EditorGUILayout.PropertyField(priority); EditorGUILayout.PropertyField(runtimePlatform); - RenderProfile(profile, ProfileContent, false); + RenderProfile(thisProfile, profile, ProfileContent, false); if (EditorGUI.EndChangeCheck()) { @@ -152,7 +124,7 @@ public override void OnInspectorGUI() serializedObject.ApplyModifiedProperties(); - if (changed) + if (changed && MixedRealityToolkit.IsInitialized) { EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetConfiguration(MixedRealityToolkit.Instance.ActiveProfile); } diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityControllerMappingProfilesInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityControllerMappingProfilesInspector.cs index ab7bdaafb..b3e4c3112 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityControllerMappingProfilesInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityControllerMappingProfilesInspector.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using UnityEditor; using UnityEngine; -using XRTK.Definitions; using XRTK.Extensions; using XRTK.Inspectors.Utilities; using XRTK.Providers.Controllers; @@ -24,17 +23,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled || - MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile == null) - { - return; - } - controllerMappingProfiles = serializedObject.FindProperty("controllerMappingProfiles"); } @@ -42,26 +30,10 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) - { - return; - } - - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled) - { - EditorGUILayout.HelpBox("No input system is enabled, or you need to specify the type in the main configuration profile.", MessageType.Error); - - if (GUILayout.Button("Back to Configuration Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; - } - - return; - } - - if (GUILayout.Button("Back to Input Profile")) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Input Profile")) { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile; + Selection.activeObject = thisProfile.ParentProfile; } EditorGUILayout.Space(); @@ -69,19 +41,7 @@ public override void OnInspectorGUI() EditorGUILayout.HelpBox("Use this profile to define all the controllers and their inputs your users will be able to use in your application.\n\n" + "You'll want to define all your Input Actions and Controller Data Providers first so you can wire up actions to hardware sensors, controllers, gestures, and other input devices.", MessageType.Info); - if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile == null) - { - EditorGUILayout.HelpBox("No input actions found, please specify a input action profile in the input system profile.", MessageType.Error); - return; - } - - if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.ControllerDataProvidersProfile == null) - { - EditorGUILayout.HelpBox("No input actions found, please specify a controller data providers profile in the input system profile.", MessageType.Error); - return; - } - - (target as BaseMixedRealityProfile).CheckProfileLock(); + thisProfile.CheckProfileLock(); serializedObject.Update(); @@ -112,7 +72,7 @@ public override void OnInspectorGUI() } EditorGUILayout.BeginHorizontal(); - profileChanged |= RenderProfile(controllerProfile, new GUIContent(profileName), false); + profileChanged |= RenderProfile(thisProfile, controllerProfile, new GUIContent(profileName), false); if (profileChanged && controllerProfile.objectReferenceValue != null) { @@ -160,7 +120,7 @@ public override void OnInspectorGUI() serializedObject.ApplyModifiedProperties(); - if (changed) + if (changed && MixedRealityToolkit.IsInitialized) { EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetConfiguration(MixedRealityToolkit.Instance.ActiveProfile); } diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityControllerVisualizationProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityControllerVisualizationProfileInspector.cs index 3c58d218b..682a04a3b 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityControllerVisualizationProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityControllerVisualizationProfileInspector.cs @@ -1,16 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using XRTK.Extensions; using UnityEditor; using UnityEngine; -using XRTK.Providers.Controllers; -using XRTK.Providers.Controllers.UnityInput; -using XRTK.Definitions; using XRTK.Definitions.Utilities; +using XRTK.Extensions; using XRTK.Inspectors.Utilities; using XRTK.Interfaces.Providers.Controllers; -using XRTK.Services; +using XRTK.Providers.Controllers; +using XRTK.Providers.Controllers.UnityInput; namespace XRTK.Inspectors.Profiles { @@ -33,7 +31,7 @@ public class MixedRealityControllerVisualizationProfileInspector : BaseMixedReal private SerializedProperty globalRightHandModel; private SerializedProperty controllerVisualizationSettings; - private MixedRealityControllerVisualizationProfile thisProfile; + private MixedRealityControllerVisualizationProfile controllerVisualizationProfile; private float defaultLabelWidth; private float defaultFieldWidth; @@ -45,12 +43,7 @@ protected override void OnEnable() defaultLabelWidth = EditorGUIUtility.labelWidth; defaultFieldWidth = EditorGUIUtility.fieldWidth; - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - - thisProfile = target as MixedRealityControllerVisualizationProfile; + controllerVisualizationProfile = target as MixedRealityControllerVisualizationProfile; renderMotionControllers = serializedObject.FindProperty("renderMotionControllers"); controllerVisualizationType = serializedObject.FindProperty("controllerVisualizationType"); @@ -64,35 +57,20 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Input Profile")) { - return; - } - - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled) - { - EditorGUILayout.HelpBox("No input system is enabled, or you need to specify the type in the main configuration profile.", MessageType.Error); - - if (GUILayout.Button("Back to Configuration Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; - } - - return; - } - - if (GUILayout.Button("Back to Input Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile; + Selection.activeObject = controllerVisualizationProfile.ParentProfile; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Controller Visualizations", EditorStyles.boldLabel); EditorGUILayout.HelpBox("Define all the custom controller visualizations you'd like to use for each controller type when they're rendered in the scene.\n\n" + "Global settings are the default fallback, and any specific controller definitions take precedence.", MessageType.Info); + serializedObject.Update(); - (target as BaseMixedRealityProfile).CheckProfileLock(); + controllerVisualizationProfile.CheckProfileLock(); EditorGUIUtility.labelWidth = 168f; EditorGUILayout.PropertyField(renderMotionControllers); @@ -104,8 +82,8 @@ public override void OnInspectorGUI() EditorGUILayout.PropertyField(controllerVisualizationType); - if (thisProfile.ControllerVisualizationType == null || - thisProfile.ControllerVisualizationType.Type == null) + if (controllerVisualizationProfile.ControllerVisualizationType == null || + controllerVisualizationProfile.ControllerVisualizationType.Type == null) { EditorGUILayout.HelpBox("A controller visualization type must be defined!", MessageType.Error); } @@ -143,7 +121,7 @@ public override void OnInspectorGUI() private void RenderControllerList(SerializedProperty controllerList) { - if (thisProfile.ControllerVisualizationSettings.Length != controllerList.arraySize) { return; } + if (controllerVisualizationProfile.ControllerVisualizationSettings.Length != controllerList.arraySize) { return; } EditorGUILayout.Space(); @@ -157,7 +135,7 @@ private void RenderControllerList(SerializedProperty controllerList) var mixedRealityControllerHandedness = controllerSetting.FindPropertyRelative("handedness"); mixedRealityControllerHandedness.intValue = 1; serializedObject.ApplyModifiedProperties(); - thisProfile.ControllerVisualizationSettings[index].ControllerType.Type = typeof(GenericJoystickController); + controllerVisualizationProfile.ControllerVisualizationSettings[index].ControllerType.Type = typeof(GenericJoystickController); return; } @@ -170,11 +148,11 @@ private void RenderControllerList(SerializedProperty controllerList) EditorGUIUtility.fieldWidth = 64f; var controllerSetting = controllerList.GetArrayElementAtIndex(i); var mixedRealityControllerMappingDescription = controllerSetting.FindPropertyRelative("description"); - bool hasValidType = thisProfile.ControllerVisualizationSettings[i].ControllerType != null && - thisProfile.ControllerVisualizationSettings[i].ControllerType.Type != null; + bool hasValidType = controllerVisualizationProfile.ControllerVisualizationSettings[i].ControllerType != null && + controllerVisualizationProfile.ControllerVisualizationSettings[i].ControllerType.Type != null; mixedRealityControllerMappingDescription.stringValue = hasValidType - ? thisProfile.ControllerVisualizationSettings[i].ControllerType.Type.Name.ToProperCase() + ? controllerVisualizationProfile.ControllerVisualizationSettings[i].ControllerType.Type.Name.ToProperCase() : "Undefined Controller"; serializedObject.ApplyModifiedProperties(); @@ -257,10 +235,10 @@ private bool CheckVisualizer(GameObject modelPrefab) if (componentList == null || componentList.Length == 0) { - if (thisProfile.ControllerVisualizationType != null && - thisProfile.ControllerVisualizationType.Type != null) + if (controllerVisualizationProfile.ControllerVisualizationType != null && + controllerVisualizationProfile.ControllerVisualizationType.Type != null) { - modelPrefab.AddComponent(thisProfile.ControllerVisualizationType.Type); + modelPrefab.AddComponent(controllerVisualizationProfile.ControllerVisualizationType.Type); return true; } diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityDiagnosticsSystemProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityDiagnosticsSystemProfileInspector.cs index 74c191624..aa5165b00 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityDiagnosticsSystemProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityDiagnosticsSystemProfileInspector.cs @@ -3,10 +3,8 @@ using UnityEditor; using UnityEngine; -using XRTK.Definitions; using XRTK.Definitions.Diagnostics; using XRTK.Inspectors.Utilities; -using XRTK.Services; namespace XRTK.Inspectors.Profiles { @@ -26,11 +24,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - visible = serializedObject.FindProperty("visible"); handlerType = serializedObject.FindProperty("handlerType"); showCpu = serializedObject.FindProperty("showCpu"); @@ -45,17 +38,13 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) - { - return; - } - - if (GUILayout.Button("Back to Configuration Profile")) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Configuration Profile")) { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; + Selection.activeObject = thisProfile.ParentProfile; } - (target as BaseMixedRealityProfile).CheckProfileLock(); + thisProfile.CheckProfileLock(); serializedObject.Update(); diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityGesturesProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityGesturesProfileInspector.cs index c2f114171..6e7207f0a 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityGesturesProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityGesturesProfileInspector.cs @@ -6,11 +6,9 @@ using System.Linq; using UnityEditor; using UnityEngine; -using XRTK.Definitions; using XRTK.Definitions.Devices; using XRTK.Definitions.InputSystem; using XRTK.Inspectors.Utilities; -using XRTK.Services; namespace XRTK.Inspectors.Profiles { @@ -25,7 +23,9 @@ public class MixedRealityGesturesProfileInspector : BaseMixedRealityProfileInspe private SerializedProperty gestures; - private MixedRealityGesturesProfile thisProfile; + private MixedRealityGesturesProfile gesturesProfile; + private MixedRealityInputSystemProfile inputSystemProfile; + private static GUIContent[] allGestureLabels; private static int[] allGestureIds; private static GUIContent[] actionLabels; @@ -35,19 +35,20 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) { return; } - gestures = serializedObject.FindProperty("gestures"); - thisProfile = target as MixedRealityGesturesProfile; - Debug.Assert(thisProfile != null); - if (MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled && - MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile != null) + gesturesProfile = target as MixedRealityGesturesProfile; + Debug.Assert(gesturesProfile != null); + + inputSystemProfile = gesturesProfile.ParentProfile as MixedRealityInputSystemProfile; + Debug.Assert(inputSystemProfile != null); + + if (inputSystemProfile.InputActionsProfile != null) { - actionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + actionLabels = inputSystemProfile.InputActionsProfile.InputActions .Select(action => new GUIContent(action.Description)) .Prepend(new GUIContent("None")).ToArray(); - actionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + actionIds = inputSystemProfile.InputActionsProfile.InputActions .Select(action => (int)action.Id) .Prepend(0).ToArray(); } @@ -65,7 +66,7 @@ private void UpdateGestureLabels() for (int i = 0; i < allGestureTypeNames.Length; i++) { if (allGestureTypeNames[i].Equals("None") || - thisProfile.Gestures.All(mapping => !allGestureTypeNames[i].Equals(mapping.GestureType.ToString()))) + gesturesProfile.Gestures.All(mapping => !allGestureTypeNames[i].Equals(mapping.GestureType.ToString()))) { tempContent.Add(new GUIContent(allGestureTypeNames[i])); tempIds.Add(i); @@ -80,36 +81,29 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) { return; } - - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled) + if (inputSystemProfile != null && + GUILayout.Button("Back to Input Profile")) { - EditorGUILayout.HelpBox("No input system is enabled, or you need to specify the type in the main configuration profile.", MessageType.Error); - - if (GUILayout.Button("Back to Configuration Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; - } - - return; - } - - if (GUILayout.Button("Back to Input Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile; + Selection.activeObject = inputSystemProfile; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Gesture Input", EditorStyles.boldLabel); EditorGUILayout.HelpBox("This gesture map is any and all movements of part the user's body, especially a hand or the head, that raise actions through the input system.\n\nNote: Defined controllers can look up the list of gestures and raise the events based on specific criteria.", MessageType.Info); - if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile == null) + if (inputSystemProfile == null) + { + EditorGUILayout.HelpBox("No input system profile found, please specify a input system profile in the main configuration.", MessageType.Error); + return; + } + + if (inputSystemProfile.InputActionsProfile == null) { EditorGUILayout.HelpBox("No input actions found, please specify a input action profile in the main configuration.", MessageType.Error); return; } - (target as BaseMixedRealityProfile).CheckProfileLock(); + gesturesProfile.CheckProfileLock(); serializedObject.Update(); EditorGUILayout.Space(); @@ -165,7 +159,7 @@ private void RenderList(SerializedProperty list) for (int i = 0; i < list.arraySize; i++) { EditorGUILayout.BeginHorizontal(); - SerializedProperty gesture = list.GetArrayElementAtIndex(i); + var gesture = list.GetArrayElementAtIndex(i); var keyword = gesture.FindPropertyRelative("description"); var gestureType = gesture.FindPropertyRelative("gestureType"); var action = gesture.FindPropertyRelative("action"); @@ -203,7 +197,7 @@ private void RenderList(SerializedProperty list) if (EditorGUI.EndChangeCheck()) { - MixedRealityInputAction inputAction = actionId.intValue == 0 ? MixedRealityInputAction.None : MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1]; + MixedRealityInputAction inputAction = actionId.intValue == 0 ? MixedRealityInputAction.None : inputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1]; actionDescription.stringValue = inputAction.Description; actionConstraint.enumValueIndex = (int)inputAction.AxisConstraint; serializedObject.ApplyModifiedProperties(); diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityInputActionRulesInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityInputActionRulesInspector.cs index 4237e134a..efa7f3124 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityInputActionRulesInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityInputActionRulesInspector.cs @@ -1,16 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using XRTK.Definitions; -using XRTK.Definitions.InputSystem; -using XRTK.Definitions.Utilities; -using XRTK.Inspectors; -using XRTK.Inspectors.Profiles; -using XRTK.Inspectors.Utilities; -using XRTK.Services; using System.Linq; using UnityEditor; using UnityEngine; +using XRTK.Definitions.InputSystem; +using XRTK.Definitions.Utilities; +using XRTK.Inspectors.Utilities; namespace XRTK.Inspectors.Profiles { @@ -55,15 +51,20 @@ public class MixedRealityInputActionRulesInspector : BaseMixedRealityProfileInsp private bool[] quaternionFoldouts; private bool[] poseFoldouts; - private MixedRealityInputActionRulesProfile thisProfile; + private MixedRealityInputActionRulesProfile inputActionRulesProfile; + private MixedRealityInputSystemProfile inputSystemProfile; protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false) || - !MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled || - MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile == null) + inputActionRulesProfile = target as MixedRealityInputActionRulesProfile; + Debug.Assert(inputActionRulesProfile != null); + + inputSystemProfile = inputActionRulesProfile.ParentProfile as MixedRealityInputSystemProfile; + Debug.Assert(inputSystemProfile != null); + + if (inputSystemProfile.InputActionsProfile == null) { return; } @@ -75,17 +76,16 @@ protected override void OnEnable() inputActionRulesQuaternionAxis = serializedObject.FindProperty("inputActionRulesQuaternionAxis"); inputActionRulesPoseAxis = serializedObject.FindProperty("inputActionRulesPoseAxis"); - baseActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + baseActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(action => action.AxisConstraint != AxisType.None && action.AxisConstraint != AxisType.Raw) .Select(action => action.Description) .ToArray(); - baseActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + baseActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(action => action.AxisConstraint != AxisType.None && action.AxisConstraint != AxisType.Raw) .Select(action => (int)action.Id) .ToArray(); - thisProfile = target as MixedRealityInputActionRulesProfile; ResetCriteria(); } @@ -94,38 +94,12 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) - { - return; - } - - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled) - { - EditorGUILayout.HelpBox("No input system is enabled, or you need to specify the type in the main configuration profile.", MessageType.Error); - - if (GUILayout.Button("Back to Configuration Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; - } - - return; - } - - if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile == null) - { - EditorGUILayout.HelpBox("No Input Actions profile was specified.", MessageType.Error); - - if (GUILayout.Button("Back to Input Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile; - } - - return; - } + Debug.Assert(inputActionRulesProfile != null); - if (GUILayout.Button("Back to Input Profile")) + if (inputSystemProfile != null && + GUILayout.Button("Back to Input Profile")) { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile; + Selection.activeObject = inputSystemProfile; } EditorGUILayout.Space(); @@ -133,12 +107,17 @@ public override void OnInspectorGUI() EditorGUILayout.HelpBox("Input Action Rules help define alternative Actions that will be raised based on specific criteria.\n\n" + "You can create new rules by assigning a base Input Action below, then assigning the criteria you'd like to meet. When the criteria is met, the Rule's Action will be raised with the criteria value.\n\n" + "Note: Rules can only be created for the same axis constraints.", MessageType.Info); - EditorGUILayout.Space(); - (target as BaseMixedRealityProfile).CheckProfileLock(); + if (inputSystemProfile == null) + { + EditorGUILayout.HelpBox("No input system profile found, please specify an input system profile in the main configuration profile.", MessageType.Error); + return; + } + + inputActionRulesProfile.CheckProfileLock(); - var isGuiLocked = !(MixedRealityPreferences.LockProfiles && !((BaseMixedRealityProfile)target).IsCustomProfile); + var isGuiLocked = !(MixedRealityPreferences.LockProfiles && !inputActionRulesProfile.IsCustomProfile); GUI.enabled = isGuiLocked; serializedObject.Update(); @@ -194,17 +173,35 @@ private bool RuleExists() default: return false; case AxisType.Digital: - return thisProfile.InputActionRulesDigital.Any(digitalRule => digitalRule.BaseAction == currentBaseAction && digitalRule.RuleAction == currentRuleAction && digitalRule.Criteria == currentBoolCriteria); + return inputActionRulesProfile.InputActionRulesDigital.Any(digitalRule => + digitalRule.BaseAction == currentBaseAction && + digitalRule.RuleAction == currentRuleAction && + digitalRule.Criteria == currentBoolCriteria); case AxisType.SingleAxis: - return thisProfile.InputActionRulesSingleAxis.Any(singleAxisRule => singleAxisRule.BaseAction == currentBaseAction && singleAxisRule.RuleAction == currentRuleAction && singleAxisRule.Criteria.Equals(currentSingleAxisCriteria)); + return inputActionRulesProfile.InputActionRulesSingleAxis.Any(singleAxisRule => + singleAxisRule.BaseAction == currentBaseAction && + singleAxisRule.RuleAction == currentRuleAction && + singleAxisRule.Criteria.Equals(currentSingleAxisCriteria)); case AxisType.DualAxis: - return thisProfile.InputActionRulesDualAxis.Any(dualAxisRule => dualAxisRule.BaseAction == currentBaseAction && dualAxisRule.RuleAction == currentRuleAction && dualAxisRule.Criteria == currentDualAxisCriteria); + return inputActionRulesProfile.InputActionRulesDualAxis.Any(dualAxisRule => + dualAxisRule.BaseAction == currentBaseAction && + dualAxisRule.RuleAction == currentRuleAction && + dualAxisRule.Criteria == currentDualAxisCriteria); case AxisType.ThreeDofPosition: - return thisProfile.InputActionRulesVectorAxis.Any(vectorAxisRule => vectorAxisRule.BaseAction == currentBaseAction && vectorAxisRule.RuleAction == currentRuleAction && vectorAxisRule.Criteria == currentVectorCriteria); + return inputActionRulesProfile.InputActionRulesVectorAxis.Any(vectorAxisRule => + vectorAxisRule.BaseAction == currentBaseAction && + vectorAxisRule.RuleAction == currentRuleAction && + vectorAxisRule.Criteria == currentVectorCriteria); case AxisType.ThreeDofRotation: - return thisProfile.InputActionRulesQuaternionAxis.Any(quaternionRule => quaternionRule.BaseAction == currentBaseAction && quaternionRule.RuleAction == currentRuleAction && quaternionRule.Criteria == currentQuaternionCriteria); + return inputActionRulesProfile.InputActionRulesQuaternionAxis.Any(quaternionRule => + quaternionRule.BaseAction == currentBaseAction && + quaternionRule.RuleAction == currentRuleAction && + quaternionRule.Criteria == currentQuaternionCriteria); case AxisType.SixDof: - return thisProfile.InputActionRulesPoseAxis.Any(poseRule => poseRule.BaseAction == currentBaseAction && poseRule.RuleAction == currentRuleAction && poseRule.Criteria == currentPoseCriteria); + return inputActionRulesProfile.InputActionRulesPoseAxis.Any(poseRule => + poseRule.BaseAction == currentBaseAction && + poseRule.RuleAction == currentRuleAction && + poseRule.Criteria == currentPoseCriteria); } } @@ -229,14 +226,14 @@ private void ResetCriteria() poseFoldouts = new bool[inputActionRulesPoseAxis.arraySize]; } - private static void GetCompatibleActions(MixedRealityInputAction baseAction) + private void GetCompatibleActions(MixedRealityInputAction baseAction) { - ruleActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + ruleActionLabels = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == baseAction.AxisConstraint && inputAction.Id != baseAction.Id) .Select(action => action.Description) .ToArray(); - ruleActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions + ruleActionIds = inputSystemProfile.InputActionsProfile.InputActions .Where(inputAction => inputAction.AxisConstraint == baseAction.AxisConstraint && inputAction.Id != baseAction.Id) .Select(action => (int)action.Id) .ToArray(); @@ -466,11 +463,11 @@ private int RenderBaseInputAction(int baseActionId, out MixedRealityInputAction baseActionId = EditorGUILayout.IntPopup(baseActionId, baseActionLabels, baseActionIds, GUILayout.ExpandWidth(true)); } - for (int i = 0; i < MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions.Length; i++) + for (int i = 0; i < inputSystemProfile.InputActionsProfile.InputActions.Length; i++) { - if (baseActionId == (int)MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[i].Id) + if (baseActionId == (int)inputSystemProfile.InputActionsProfile.InputActions[i].Id) { - action = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[i]; + action = inputSystemProfile.InputActionsProfile.InputActions[i]; } } @@ -496,11 +493,11 @@ private int RenderRuleInputAction(int ruleActionId, out MixedRealityInputAction EditorGUI.BeginChangeCheck(); ruleActionId = EditorGUILayout.IntPopup(ruleActionId, ruleActionLabels, ruleActionIds, GUILayout.ExpandWidth(true)); - for (int i = 0; i < MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions.Length; i++) + for (int i = 0; i < inputSystemProfile.InputActionsProfile.InputActions.Length; i++) { - if (ruleActionId == (int)MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[i].Id) + if (ruleActionId == (int)inputSystemProfile.InputActionsProfile.InputActions[i].Id) { - action = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[i]; + action = inputSystemProfile.InputActionsProfile.InputActions[i]; } } diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityInputActionsProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityInputActionsProfileInspector.cs index 7aaaa7d76..db68e888f 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityInputActionsProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityInputActionsProfileInspector.cs @@ -3,10 +3,8 @@ using UnityEditor; using UnityEngine; -using XRTK.Definitions; using XRTK.Definitions.InputSystem; using XRTK.Inspectors.Utilities; -using XRTK.Services; namespace XRTK.Inspectors.Profiles { @@ -26,11 +24,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - inputActionList = serializedObject.FindProperty("inputActions"); } @@ -38,27 +31,13 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Input Profile")) { - return; + Selection.activeObject = thisProfile.ParentProfile; } - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled) - { - EditorGUILayout.HelpBox("No input system is enabled, or you need to specify the type in the main configuration profile.", MessageType.Error); - - if (GUILayout.Button("Back to Configuration Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; - } - - return; - } - - if (GUILayout.Button("Back to Input Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile; - } + thisProfile.CheckProfileLock(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Input Actions", EditorStyles.boldLabel); @@ -66,7 +45,7 @@ public override void OnInspectorGUI() EditorGUILayout.HelpBox("Input Actions are any/all actions your users will be able to make when interacting with your application.\n\n" + "After defining all your actions, you can then wire up these actions to hardware sensors, controllers, and other input devices.", MessageType.Info); - (target as BaseMixedRealityProfile).CheckProfileLock(); + thisProfile.CheckProfileLock(); serializedObject.Update(); RenderList(inputActionList); @@ -77,6 +56,7 @@ private static void RenderList(SerializedProperty list) { EditorGUILayout.Space(); GUILayout.BeginVertical(); + if (GUILayout.Button(AddButtonContent, EditorStyles.miniButton)) { list.arraySize += 1; @@ -89,7 +69,6 @@ private static void RenderList(SerializedProperty list) } GUILayout.Space(12f); - GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); @@ -108,8 +87,8 @@ private static void RenderList(SerializedProperty list) EditorGUILayout.BeginHorizontal(); var previousLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 64f; - SerializedProperty inputAction = list.GetArrayElementAtIndex(i); - SerializedProperty inputActionDescription = inputAction.FindPropertyRelative("description"); + var inputAction = list.GetArrayElementAtIndex(i); + var inputActionDescription = inputAction.FindPropertyRelative("description"); var inputActionConstraint = inputAction.FindPropertyRelative("axisConstraint"); EditorGUILayout.PropertyField(inputActionDescription, GUIContent.none); EditorGUILayout.PropertyField(inputActionConstraint, GUIContent.none, GUILayout.Width(96f)); diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityInputSystemProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityInputSystemProfileInspector.cs index 60887a295..7722bf983 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityInputSystemProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityInputSystemProfileInspector.cs @@ -3,7 +3,6 @@ using UnityEditor; using UnityEngine; -using XRTK.Definitions; using XRTK.Definitions.InputSystem; using XRTK.Inspectors.Utilities; using XRTK.Services; @@ -27,11 +26,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - focusProviderType = serializedObject.FindProperty("focusProviderType"); inputActionsProfile = serializedObject.FindProperty("inputActionsProfile"); inputActionRulesProfile = serializedObject.FindProperty("inputActionRulesProfile"); @@ -47,21 +41,17 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) - { - return; - } - - if (GUILayout.Button("Back to Configuration Profile")) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Configuration Profile")) { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; + Selection.activeObject = thisProfile.ParentProfile; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Input System Profile", EditorStyles.boldLabel); EditorGUILayout.HelpBox("The Input System Profile helps developers configure input no matter what platform you're building for.", MessageType.Info); - (target as BaseMixedRealityProfile).CheckProfileLock(); + thisProfile.CheckProfileLock(); serializedObject.Update(); bool changed = false; @@ -74,18 +64,18 @@ public override void OnInspectorGUI() changed = true; } - changed |= RenderProfile(inputActionsProfile); - changed |= RenderProfile(inputActionRulesProfile); - changed |= RenderProfile(pointerProfile); - changed |= RenderProfile(gesturesProfile); - changed |= RenderProfile(speechCommandsProfile); - changed |= RenderProfile(controllerVisualizationProfile); - changed |= RenderProfile(controllerDataProvidersProfile); - changed |= RenderProfile(controllerMappingProfiles); + changed |= RenderProfile(thisProfile, inputActionsProfile); + changed |= RenderProfile(thisProfile, inputActionRulesProfile); + changed |= RenderProfile(thisProfile, pointerProfile); + changed |= RenderProfile(thisProfile, gesturesProfile); + changed |= RenderProfile(thisProfile, speechCommandsProfile); + changed |= RenderProfile(thisProfile, controllerVisualizationProfile); + changed |= RenderProfile(thisProfile, controllerDataProvidersProfile); + changed |= RenderProfile(thisProfile, controllerMappingProfiles); serializedObject.ApplyModifiedProperties(); - if (changed) + if (changed && MixedRealityToolkit.IsInitialized) { EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetConfiguration(MixedRealityToolkit.Instance.ActiveProfile); } diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityNetworkSystemProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityNetworkSystemProfileInspector.cs index dfaff8220..f92d69a38 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityNetworkSystemProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityNetworkSystemProfileInspector.cs @@ -3,7 +3,6 @@ using UnityEditor; using UnityEngine; -using XRTK.Definitions; using XRTK.Definitions.NetworkingSystem; using XRTK.Inspectors.Utilities; using XRTK.Services; @@ -19,11 +18,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - registeredNetworkDataProviders = serializedObject.FindProperty("registeredNetworkDataProviders"); } @@ -31,28 +25,24 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) - { - return; - } - - if (GUILayout.Button("Back to Configuration Profile")) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Configuration Profile")) { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; + Selection.activeObject = thisProfile.ParentProfile; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Network System Profile", EditorStyles.boldLabel); EditorGUILayout.HelpBox("The Network System Profile helps developers configure networking messages no matter what platform you're building for.", MessageType.Info); - (target as BaseMixedRealityProfile).CheckProfileLock(); + thisProfile.CheckProfileLock(); serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(registeredNetworkDataProviders, true); - if (EditorGUI.EndChangeCheck()) + if (EditorGUI.EndChangeCheck() && MixedRealityToolkit.IsInitialized) { EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetConfiguration(MixedRealityToolkit.Instance.ActiveProfile); } diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityPointerProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityPointerProfileInspector.cs index 5cc95856c..b17cacbdd 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityPointerProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityPointerProfileInspector.cs @@ -4,10 +4,8 @@ using UnityEditor; using UnityEditorInternal; using UnityEngine; -using XRTK.Definitions; using XRTK.Definitions.InputSystem; using XRTK.Inspectors.Utilities; -using XRTK.Services; using XRTK.Utilities; namespace XRTK.Inspectors.Profiles @@ -32,11 +30,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - pointingExtent = serializedObject.FindProperty("pointingExtent"); pointingRaycastLayerMasks = serializedObject.FindProperty("pointingRaycastLayerMasks"); debugDrawPointingRays = serializedObject.FindProperty("debugDrawPointingRays"); @@ -58,14 +51,11 @@ protected override void OnEnable() public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) - { - return; - } - if (GUILayout.Button("Back to Input Profile")) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Input Profile")) { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile; + Selection.activeObject = thisProfile.ParentProfile; } EditorGUILayout.Space(); @@ -73,7 +63,7 @@ public override void OnInspectorGUI() EditorGUILayout.HelpBox("Pointers attach themselves onto controllers as they are initialized.", MessageType.Info); EditorGUILayout.Space(); - (target as BaseMixedRealityProfile).CheckProfileLock(); + thisProfile.CheckProfileLock(); serializedObject.Update(); currentlySelectedPointerOption = -1; @@ -90,6 +80,7 @@ public override void OnInspectorGUI() EditorGUILayout.PropertyField(gazeProviderType); EditorGUILayout.Space(); + if (GUILayout.Button("Customize Gaze Provider Settings")) { Selection.activeObject = CameraCache.Main.gameObject; diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityRegisteredServiceProviderProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityRegisteredServiceProviderProfileInspector.cs index ddd08a2ef..58984194f 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityRegisteredServiceProviderProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityRegisteredServiceProviderProfileInspector.cs @@ -21,11 +21,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - configurations = serializedObject.FindProperty("configurations"); configurationList = new ReorderableList(serializedObject, configurations, true, false, true, true) @@ -42,14 +37,10 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Configuration Profile")) { - return; - } - - if (GUILayout.Button("Back to Configuration Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; + Selection.activeObject = thisProfile.ParentProfile; } EditorGUILayout.Space(); @@ -57,7 +48,7 @@ public override void OnInspectorGUI() EditorGUILayout.HelpBox("This profile defines any additional Services like systems, features, and managers to register with the Mixed Reality Toolkit.\n\n" + "Note: The order of the list determines the order these services get created.", MessageType.Info); - (target as BaseMixedRealityProfile).CheckProfileLock(); + thisProfile.CheckProfileLock(); serializedObject.Update(); EditorGUILayout.Space(); @@ -107,7 +98,8 @@ private void DrawConfigurationOptionElement(Rect rect, int index, bool isActive, { serializedObject.ApplyModifiedProperties(); - if (!string.IsNullOrEmpty(componentType.FindPropertyRelative("reference").stringValue)) + if (MixedRealityToolkit.IsInitialized && + !string.IsNullOrEmpty(componentType.FindPropertyRelative("reference").stringValue)) { MixedRealityToolkit.Instance.ResetConfiguration(MixedRealityToolkit.Instance.ActiveProfile); } @@ -142,7 +134,11 @@ private void OnConfigurationOptionRemoved(ReorderableList list) } serializedObject.ApplyModifiedProperties(); - EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetConfiguration(MixedRealityToolkit.Instance.ActiveProfile); + + if (MixedRealityToolkit.IsInitialized) + { + EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetConfiguration(MixedRealityToolkit.Instance.ActiveProfile); + } } } } \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealitySpeechCommandsProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealitySpeechCommandsProfileInspector.cs index 2405fa885..0ab925297 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealitySpeechCommandsProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealitySpeechCommandsProfileInspector.cs @@ -7,7 +7,6 @@ using XRTK.Definitions; using XRTK.Definitions.InputSystem; using XRTK.Inspectors.Utilities; -using XRTK.Services; namespace XRTK.Inspectors.Profiles { @@ -25,61 +24,50 @@ public class MixedRealitySpeechCommandsProfileInspector : BaseMixedRealityProfil private SerializedProperty speechCommands; private static GUIContent[] actionLabels; private static int[] actionIds; + private MixedRealityInputSystemProfile inputSystemProfile; protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } + inputSystemProfile = thisProfile.ParentProfile as MixedRealityInputSystemProfile; + Debug.Assert(inputSystemProfile != null); - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled || - MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile == null) { return; } + if (inputSystemProfile.InputActionsProfile == null) { return; } recognizerStartBehaviour = serializedObject.FindProperty("startBehavior"); recognitionConfidenceLevel = serializedObject.FindProperty("recognitionConfidenceLevel"); speechCommands = serializedObject.FindProperty("speechCommands"); - actionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions.Select(action => new GUIContent(action.Description)).Prepend(new GUIContent("None")).ToArray(); - actionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions.Select(action => (int)action.Id).Prepend(0).ToArray(); + actionLabels = inputSystemProfile.InputActionsProfile.InputActions.Select(action => new GUIContent(action.Description)).Prepend(new GUIContent("None")).ToArray(); + actionIds = inputSystemProfile.InputActionsProfile.InputActions.Select(action => (int)action.Id).Prepend(0).ToArray(); } public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) + if (inputSystemProfile != null && + GUILayout.Button("Back to Input Profile")) { - return; + Selection.activeObject = inputSystemProfile; } - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled) - { - EditorGUILayout.HelpBox("No input system is enabled, or you need to specify the type in the main configuration profile.", MessageType.Error); - - if (GUILayout.Button("Back to Configuration Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; - } - - return; - } - - if (GUILayout.Button("Back to Input Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile; - } - - (target as BaseMixedRealityProfile).CheckProfileLock(); + thisProfile.CheckProfileLock(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Speech Commands", EditorStyles.boldLabel); EditorGUILayout.HelpBox("Speech Commands are any/all spoken keywords your users will be able say to raise an Input Action in your application.", MessageType.Info); + EditorGUILayout.Space(); - if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile == null) + if (inputSystemProfile == null) { - EditorGUILayout.HelpBox("No input actions found, please specify a input action profile in the main configuration.", MessageType.Error); + EditorGUILayout.HelpBox("No input system profile found, please specify an input system profile in the main configuration profile.", MessageType.Error); + return; + } + + if (inputSystemProfile.InputActionsProfile == null) + { + EditorGUILayout.HelpBox("No input actions found, please specify a input action profile in the input system profile.", MessageType.Error); return; } @@ -92,7 +80,7 @@ public override void OnInspectorGUI() serializedObject.ApplyModifiedProperties(); } - private static void RenderList(SerializedProperty list) + private void RenderList(SerializedProperty list) { EditorGUILayout.Space(); GUILayout.BeginVertical(); @@ -149,7 +137,10 @@ private static void RenderList(SerializedProperty list) if (EditorGUI.EndChangeCheck()) { - MixedRealityInputAction inputAction = actionId.intValue == 0 ? MixedRealityInputAction.None : MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1]; + var inputAction = actionId.intValue == 0 + ? MixedRealityInputAction.None + : inputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1]; + actionDescription.stringValue = inputAction.Description; actionConstraint.enumValueIndex = (int)inputAction.AxisConstraint; } diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityToolkitConfigurationProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityToolkitConfigurationProfileInspector.cs index 56ef31973..54c9e79a3 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityToolkitConfigurationProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityToolkitConfigurationProfileInspector.cs @@ -58,6 +58,8 @@ protected override void OnEnable() // Create The MR Manager if none exists. if (!MixedRealityToolkit.IsInitialized && prefabStage == null) { + // TODO Check base scene for service locator existence? + // Search for all instances, in case we've just hot reloaded the assembly. var managerSearch = FindObjectsOfType(); @@ -76,17 +78,10 @@ protected override void OnEnable() else { Debug.LogWarning("No Mixed Reality Toolkit in your scene."); - return; } } } - if (!MixedRealityToolkit.ConfirmInitialized() || - !MixedRealityToolkit.HasActiveProfile) - { - return; - } - // Camera configuration enableCameraSystem = serializedObject.FindProperty("enableCameraSystem"); cameraSystemType = serializedObject.FindProperty("cameraSystemType"); @@ -124,12 +119,6 @@ public override void OnInspectorGUI() MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); serializedObject.Update(); - if (!MixedRealityToolkit.IsInitialized) - { - EditorGUILayout.HelpBox("Unable to find Mixed Reality Toolkit!", MessageType.Error); - return; - } - if (!configurationProfile.IsCustomProfile) { EditorGUILayout.HelpBox("The Mixed Reality Toolkit's core SDK profiles can be used to get up and running quickly.\n\n" + @@ -153,7 +142,7 @@ public override void OnInspectorGUI() } // We don't call the CheckLock method so won't get a duplicate message. - if (MixedRealityPreferences.LockProfiles && !((BaseMixedRealityProfile)target).IsCustomProfile) + if (MixedRealityPreferences.LockProfiles && !thisProfile.IsCustomProfile) { GUI.enabled = false; } @@ -168,21 +157,21 @@ public override void OnInspectorGUI() EditorGUILayout.LabelField("Camera System Settings", EditorStyles.boldLabel); EditorGUILayout.PropertyField(enableCameraSystem); EditorGUILayout.PropertyField(cameraSystemType); - changed |= RenderProfile(cameraProfile); + changed |= RenderProfile(thisProfile, cameraProfile); // Input System configuration GUILayout.Space(12f); EditorGUILayout.LabelField("Input System Settings", EditorStyles.boldLabel); EditorGUILayout.PropertyField(enableInputSystem); EditorGUILayout.PropertyField(inputSystemType); - changed |= RenderProfile(inputSystemProfile); + changed |= RenderProfile(thisProfile, inputSystemProfile); // Boundary System configuration GUILayout.Space(12f); EditorGUILayout.LabelField("Boundary System Settings", EditorStyles.boldLabel); EditorGUILayout.PropertyField(enableBoundarySystem); EditorGUILayout.PropertyField(boundarySystemType); - changed |= RenderProfile(boundaryVisualizationProfile); + changed |= RenderProfile(thisProfile, boundaryVisualizationProfile); // Teleport System configuration GUILayout.Space(12f); @@ -195,25 +184,25 @@ public override void OnInspectorGUI() EditorGUILayout.LabelField("Spatial Awareness System Settings", EditorStyles.boldLabel); EditorGUILayout.PropertyField(enableSpatialAwarenessSystem); EditorGUILayout.PropertyField(spatialAwarenessSystemType); - changed |= RenderProfile(spatialAwarenessProfile); + changed |= RenderProfile(thisProfile, spatialAwarenessProfile); // Networking System configuration GUILayout.Space(12f); EditorGUILayout.LabelField("Networking System Settings", EditorStyles.boldLabel); EditorGUILayout.PropertyField(enableNetworkingSystem); EditorGUILayout.PropertyField(networkingSystemType); - changed |= RenderProfile(networkingSystemProfile); + changed |= RenderProfile(thisProfile, networkingSystemProfile); // Diagnostics System configuration GUILayout.Space(12f); EditorGUILayout.LabelField("Diagnostics System Settings", EditorStyles.boldLabel); EditorGUILayout.PropertyField(enableDiagnosticsSystem); EditorGUILayout.PropertyField(diagnosticsSystemType); - changed |= RenderProfile(diagnosticsSystemProfile); + changed |= RenderProfile(thisProfile, diagnosticsSystemProfile); GUILayout.Space(12f); EditorGUILayout.LabelField("Additional Service Providers", EditorStyles.boldLabel); - changed |= RenderProfile(registeredServiceProvidersProfile); + changed |= RenderProfile(thisProfile, registeredServiceProvidersProfile); if (!changed) { @@ -223,7 +212,9 @@ public override void OnInspectorGUI() EditorGUIUtility.labelWidth = previousLabelWidth; serializedObject.ApplyModifiedProperties(); - if (changed) + if (changed && + MixedRealityToolkit.IsInitialized && + MixedRealityToolkit.Instance.ActiveProfile == configurationProfile) { EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetConfiguration(configurationProfile); } diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/BaseMixedRealitySpatialMeshObserverProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/BaseMixedRealitySpatialMeshObserverProfileInspector.cs index 7cc777395..0fe75889c 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/BaseMixedRealitySpatialMeshObserverProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/BaseMixedRealitySpatialMeshObserverProfileInspector.cs @@ -3,7 +3,6 @@ using UnityEditor; using XRTK.Providers.SpatialObservers; -using XRTK.Inspectors.Utilities; namespace XRTK.Inspectors.Profiles.SpatialAwareness { @@ -27,11 +26,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - meshPhysicsLayerOverride = serializedObject.FindProperty("meshPhysicsLayerOverride"); meshLevelOfDetail = serializedObject.FindProperty("meshLevelOfDetail"); meshTrianglesPerCubicMeter = serializedObject.FindProperty("meshTrianglesPerCubicMeter"); @@ -47,10 +41,6 @@ protected override void OnEnable() public override void OnInspectorGUI() { base.OnInspectorGUI(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } serializedObject.Update(); diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/BaseMixedRealitySpatialObserverProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/BaseMixedRealitySpatialObserverProfileInspector.cs index 5f275d2d2..64ffaa7d3 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/BaseMixedRealitySpatialObserverProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/BaseMixedRealitySpatialObserverProfileInspector.cs @@ -3,10 +3,8 @@ using UnityEditor; using UnityEngine; -using XRTK.Providers.SpatialObservers; -using XRTK.Definitions; using XRTK.Inspectors.Utilities; -using XRTK.Services; +using XRTK.Providers.SpatialObservers; namespace XRTK.Inspectors.Profiles.SpatialAwareness { @@ -25,10 +23,6 @@ public abstract class BaseMixedRealitySpatialObserverProfileInspector : BaseMixe protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } startupBehavior = serializedObject.FindProperty("startupBehavior"); observationExtents = serializedObject.FindProperty("observationExtents"); @@ -42,38 +36,18 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Spatial Awareness Profile")) { - return; + Selection.activeObject = thisProfile.ParentProfile; } - if (!MixedRealityToolkit.Instance.ActiveProfile.IsSpatialAwarenessSystemEnabled) - { - EditorGUILayout.HelpBox("The Spatial Awareness Observer Data Provider requires that the spatial awareness system be enabled.", MessageType.Error); - - if (GUILayout.Button("Back to Configuration Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; - } - - return; - } - - if (GUILayout.Button("Back to Spatial Awareness Profile")) - { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile.SpatialAwarenessProfile; - } - - EditorGUILayout.Space(); EditorGUILayout.LabelField("Spatial Observer Options", EditorStyles.boldLabel); EditorGUILayout.HelpBox("The Spatial Awareness Observer Data Provider supplies the Spatial Awareness system with all the data it needs to understand the world around you.", MessageType.Info); EditorGUILayout.Space(); - if (MixedRealityPreferences.LockProfiles && !((BaseMixedRealityProfile)target).IsCustomProfile) - { - GUI.enabled = false; - } + thisProfile.CheckProfileLock(); serializedObject.Update(); diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/BaseMixedRealitySurfaceObserverProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/BaseMixedRealitySurfaceObserverProfileInspector.cs index 2189a6fd3..b59375bfd 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/BaseMixedRealitySurfaceObserverProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/BaseMixedRealitySurfaceObserverProfileInspector.cs @@ -4,7 +4,6 @@ using UnityEditor; using UnityEngine; using XRTK.Providers.SpatialObservers; -using XRTK.Inspectors.Utilities; namespace XRTK.Inspectors.Profiles.SpatialAwareness { @@ -35,11 +34,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - surfacePhysicsLayerOverride = serializedObject.FindProperty("surfacePhysicsLayerOverride"); surfaceFindingMinimumArea = serializedObject.FindProperty("surfaceFindingMinimumArea"); displayFloorSurfaces = serializedObject.FindProperty("displayFloorSurfaces"); @@ -57,11 +51,6 @@ public override void OnInspectorGUI() { base.OnInspectorGUI(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) - { - return; - } - serializedObject.Update(); foldout = EditorGUILayout.Foldout(foldout, "Surface Finding Settings", true); diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/MixedRealitySpatialAwarenessSystemProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/MixedRealitySpatialAwarenessSystemProfileInspector.cs index 4c7084388..9ade9e89b 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/MixedRealitySpatialAwarenessSystemProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/SpatialAwareness/MixedRealitySpatialAwarenessSystemProfileInspector.cs @@ -3,10 +3,8 @@ using UnityEditor; using UnityEngine; -using XRTK.Definitions; using XRTK.Definitions.SpatialAwarenessSystem; using XRTK.Inspectors.Utilities; -using XRTK.Services; namespace XRTK.Inspectors.Profiles.SpatialAwareness { @@ -25,11 +23,6 @@ protected override void OnEnable() { base.OnEnable(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured(false)) - { - return; - } - registeredSpatialObserverDataProviders = serializedObject.FindProperty("registeredSpatialObserverDataProviders"); foldouts = new bool[registeredSpatialObserverDataProviders.arraySize]; } @@ -39,14 +32,10 @@ public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); - if (!MixedRealityInspectorUtility.CheckMixedRealityConfigured()) - { - return; - } - - if (GUILayout.Button("Back to Configuration Profile")) + if (thisProfile.ParentProfile != null && + GUILayout.Button("Back to Configuration Profile")) { - Selection.activeObject = MixedRealityToolkit.Instance.ActiveProfile; + Selection.activeObject = thisProfile.ParentProfile; } EditorGUILayout.Space(); @@ -55,10 +44,7 @@ public override void OnInspectorGUI() EditorGUILayout.Space(); serializedObject.Update(); - if (MixedRealityPreferences.LockProfiles && !((BaseMixedRealityProfile)target).IsCustomProfile) - { - GUI.enabled = false; - } + thisProfile.CheckProfileLock(); EditorGUILayout.Space(); @@ -116,7 +102,7 @@ public override void OnInspectorGUI() EditorGUILayout.PropertyField(spatialObserverName); EditorGUILayout.PropertyField(priority); EditorGUILayout.PropertyField(runtimePlatform); - RenderProfile(profile, false); + RenderProfile(thisProfile, profile, false); EditorGUI.indentLevel--; } diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/InputActionPropertyDrawer.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/InputActionPropertyDrawer.cs index 23e2c7492..7743c1443 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/InputActionPropertyDrawer.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/InputActionPropertyDrawer.cs @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using XRTK.Extensions; using System.Linq; using UnityEditor; using UnityEngine; using XRTK.Definitions.InputSystem; +using XRTK.Extensions; using XRTK.Services; namespace XRTK.Inspectors.PropertyDrawers @@ -19,39 +19,39 @@ public class InputActionPropertyDrawer : PropertyDrawer public override void OnGUI(Rect rect, SerializedProperty property, GUIContent content) { - if (!MixedRealityToolkit.IsInitialized || !MixedRealityToolkit.HasActiveProfile) - { - profile = null; - actionLabels = new[] { new GUIContent("Missing Mixed Reality Toolkit") }; - actionIds = new[] { 0 }; - } + profile = null; + actionLabels = new[] { new GUIContent("Missing Mixed Reality Toolkit") }; + actionIds = new[] { 0 }; - if (profile == null || - (MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled && - profile.InputActions != null && - profile.InputActions != MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions)) + if (MixedRealityToolkit.IsInitialized && MixedRealityToolkit.HasActiveProfile) { - profile = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile; - - if (profile != null) + if (profile == null || + (MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled && + profile.InputActions != null && + profile.InputActions != MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions)) { - actionLabels = profile.InputActions.Select(action => new GUIContent(action.Description)).Prepend(new GUIContent("None")).ToArray(); - actionIds = profile.InputActions.Select(action => (int)action.Id).Prepend(0).ToArray(); + profile = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile; + + if (profile != null) + { + actionLabels = profile.InputActions.Select(action => new GUIContent(action.Description)).Prepend(new GUIContent("None")).ToArray(); + actionIds = profile.InputActions.Select(action => (int)action.Id).Prepend(0).ToArray(); + } + else + { + actionLabels = new[] { new GUIContent("No input action profile found") }; + actionIds = new[] { 0 }; + } } - else + + if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled) { - actionLabels = new[] { new GUIContent("No input action profile found") }; + profile = null; + actionLabels = new[] { new GUIContent("Input System Disabled") }; actionIds = new[] { 0 }; } } - if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled) - { - profile = null; - actionLabels = new[] { new GUIContent("Input System Disabled") }; - actionIds = new[] { 0 }; - } - var label = EditorGUI.BeginProperty(rect, content, property); var inputActionId = property.FindPropertyRelative("id"); diff --git a/XRTK-Core/Packages/com.xrtk.core/Services/CameraSystem/MixedRealityCameraSystem.cs b/XRTK-Core/Packages/com.xrtk.core/Services/CameraSystem/MixedRealityCameraSystem.cs index d91f24a00..9d6fe3e1c 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Services/CameraSystem/MixedRealityCameraSystem.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Services/CameraSystem/MixedRealityCameraSystem.cs @@ -67,12 +67,10 @@ public override void Initialize() public override void Enable() { - if (Application.isPlaying) + if (Application.isPlaying && + profile.IsCameraPersistent) { - if (profile.IsCameraPersistent) - { - CameraCache.Main.transform.root.DontDestroyOnLoad(); - } + CameraCache.Main.transform.root.DontDestroyOnLoad(); } } diff --git a/XRTK-Core/Packages/com.xrtk.core/Services/MixedRealityToolkit.cs b/XRTK-Core/Packages/com.xrtk.core/Services/MixedRealityToolkit.cs index 7514b3ce9..b1d7b69ac 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Services/MixedRealityToolkit.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Services/MixedRealityToolkit.cs @@ -26,7 +26,7 @@ namespace XRTK.Services /// /// This class is responsible for coordinating the operation of the Mixed Reality Toolkit. It is the only Singleton in the entire project. /// It provides a service registry for all active services that are used within a project as well as providing the active configuration profile for the project. - /// The Profile can be swapped out at any time to meet the needs of your project. + /// The can be swapped out at any time to meet the needs of your project. /// [ExecuteInEditMode] [DisallowMultipleComponent] @@ -164,12 +164,8 @@ public static MixedRealityToolkit Instance return instance; } - if (isGettingInstance) - { - return null; - } - - if (Application.isPlaying && !searchForInstance) + if (isGettingInstance || + (Application.isPlaying && !searchForInstance)) { return null; } @@ -244,10 +240,7 @@ private void InitializeInstance() DontDestroyOnLoad(instance.transform.root); } - Application.quitting += () => - { - isApplicationQuitting = true; - }; + Application.quitting += () => isApplicationQuitting = true; #if UNITY_EDITOR UnityEditor.EditorApplication.hierarchyChanged += OnHierarchyChanged; @@ -264,12 +257,14 @@ void OnHierarchyChanged() void OnPlayModeStateChanged(UnityEditor.PlayModeStateChange playModeState) { - if (playModeState == UnityEditor.PlayModeStateChange.ExitingEditMode || playModeState == UnityEditor.PlayModeStateChange.EnteredEditMode) + if (playModeState == UnityEditor.PlayModeStateChange.ExitingEditMode || + playModeState == UnityEditor.PlayModeStateChange.EnteredEditMode) { isApplicationQuitting = false; } - if (playModeState == UnityEditor.PlayModeStateChange.ExitingEditMode && activeProfile == null) + if (activeProfile == null && + playModeState == UnityEditor.PlayModeStateChange.ExitingEditMode) { UnityEditor.EditorApplication.isPlaying = false; UnityEditor.Selection.activeObject = Instance; @@ -289,7 +284,6 @@ void OnPlayModeStateChanged(UnityEditor.PlayModeStateChange playModeState) /// Flag to search for instance the first time Instance property is called. /// Subsequent attempts will generally switch this flag false, unless the instance was destroyed. /// - // ReSharper disable once StaticMemberInGenericType private static bool searchForInstance = true; private static bool isInitializing = false; @@ -660,7 +654,8 @@ private static void EnsureMixedRealityRequirements() #if UNITY_EDITOR private void OnValidate() { - if (!IsInitialized && !UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode) + if (!IsInitialized && + !UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode) { ConfirmInitialized(); }