Skip to content

Commit 2da0bb7

Browse files
author
David Kline
authored
Merge pull request #3586 from Railboy/mrtk_inspector_upgrade_pt3
Mrtk Inspector Upgrade (Part 3)
2 parents b2d229d + d8506ed commit 2da0bb7

12 files changed

+94
-29
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using Microsoft.MixedReality.Toolkit.Core.Interfaces;
5+
using System;
6+
7+
namespace Microsoft.MixedReality.Toolkit.Core.Attributes
8+
{
9+
/// <summary>
10+
/// Attribute that defines which service a profile is meant to be consumed by.
11+
/// Only applies to profiles that are consumed by types implementing IMixedRealityService.
12+
/// </summary>
13+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
14+
public class MixedRealityServiceProfileAttribute : Attribute
15+
{
16+
public MixedRealityServiceProfileAttribute(Type serviceType) { ServiceType = serviceType; }
17+
18+
public Type ServiceType { get; private set; }
19+
}
20+
}

Assets/MixedRealityToolkit/Attributes/MixedRealityServiceProfileAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/MixedRealityToolkit/Definitions/BoundarySystem/MixedRealityBoundaryVisualizationProfile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.MixedReality.Toolkit.Core.Attributes;
55
using Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities;
6+
using Microsoft.MixedReality.Toolkit.Core.Interfaces.BoundarySystem;
67
using UnityEngine;
78

89
namespace Microsoft.MixedReality.Toolkit.Core.Definitions.BoundarySystem
@@ -11,6 +12,7 @@ namespace Microsoft.MixedReality.Toolkit.Core.Definitions.BoundarySystem
1112
/// Configuration profile settings for setting up boundary visualizations.
1213
/// </summary>
1314
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Mixed Reality Boundary Visualization Profile", fileName = "MixedRealityBoundaryVisualizationProfile", order = (int)CreateProfileMenuItemIndices.BoundaryVisualization)]
15+
[MixedRealityServiceProfile(typeof(IMixedRealityBoundarySystem))]
1416
public class MixedRealityBoundaryVisualizationProfile : BaseMixedRealityProfile
1517
{
1618
[SerializeField]

Assets/MixedRealityToolkit/Definitions/Devices/MixedRealityControllerVisualizationProfile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Microsoft.MixedReality.Toolkit.Core.Definitions.Devices
1111
{
1212
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Mixed Reality Controller Visualization Profile", fileName = "MixedRealityControllerVisualizationProfile", order = (int)CreateProfileMenuItemIndices.ControllerVisualization)]
13+
[MixedRealityServiceProfile(typeof(IMixedRealityControllerVisualizer))]
1314
public class MixedRealityControllerVisualizationProfile : BaseMixedRealityProfile
1415
{
1516
[SerializeField]

Assets/MixedRealityToolkit/Definitions/Diagnostics/MixedRealityDiagnosticsProfile.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using Microsoft.MixedReality.Toolkit.Core.Attributes;
45
using Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities;
6+
using Microsoft.MixedReality.Toolkit.Core.Interfaces.Diagnostics;
57
using UnityEngine;
68
using UnityEngine.Serialization;
79

@@ -11,6 +13,7 @@ namespace Microsoft.MixedReality.Toolkit.Core.Definitions.Diagnostics
1113
/// Configuration profile settings for setting up diagnostics.
1214
/// </summary>
1315
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Mixed Reality Diagnostics Profile", fileName = "MixedRealityDiagnosticsProfile", order = (int)CreateProfileMenuItemIndices.Diagnostics)]
16+
[MixedRealityServiceProfile(typeof(IMixedRealityDiagnosticsSystem))]
1417
public class MixedRealityDiagnosticsProfile : BaseMixedRealityProfile
1518
{
1619
[SerializeField]

Assets/MixedRealityToolkit/Definitions/InputSystem/MixedRealityInputSystemProfile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.MixedReality.Toolkit.Core.Definitions.InputSystem
1717
/// Configuration profile settings for setting up controller pointers.
1818
/// </summary>
1919
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Mixed Reality Input System Profile", fileName = "MixedRealityInputSystemProfile", order = (int)CreateProfileMenuItemIndices.Input)]
20+
[MixedRealityServiceProfile(typeof(IMixedRealityInputSystem))]
2021
public class MixedRealityInputSystemProfile : BaseMixedRealityProfile
2122
{
2223
[SerializeField]

Assets/MixedRealityToolkit/Definitions/MixedRealityRegisteredServiceProvidersProfile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using Microsoft.MixedReality.Toolkit.Core.Attributes;
45
using Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities;
56
using UnityEngine;
67

Assets/MixedRealityToolkit/Definitions/SpatialAwareness/MixedRealitySpatialAwarenessMeshObserverProfile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.MixedReality.Toolkit.Core.Attributes;
55
using Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities;
6+
using Microsoft.MixedReality.Toolkit.Core.Interfaces.SpatialAwarenessSystem.Observers;
67
using UnityEngine;
78

89
namespace Microsoft.MixedReality.Toolkit.Core.Definitions.SpatialAwarenessSystem
@@ -11,6 +12,7 @@ namespace Microsoft.MixedReality.Toolkit.Core.Definitions.SpatialAwarenessSystem
1112
/// Configuration profile settings for spatial awareness mesh observers.
1213
/// </summary>
1314
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Mixed Reality Spatial Awareness Mesh Observer Profile", fileName = "MixedRealitySpatialAwarenessMeshObserverProfile", order = (int)CreateProfileMenuItemIndices.SpatialAwarenessMeshObserver)]
15+
[MixedRealityServiceProfile(typeof(IMixedRealitySpatialAwarenessMeshObserver))]
1416
public class MixedRealitySpatialAwarenessMeshObserverProfile : BaseMixedRealityProfile
1517
{
1618
#region IMixedRealitySpatialAwarenessObserver settings

Assets/MixedRealityToolkit/Inspectors/Profiles/BaseMixedRealityProfileInspector.cs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using Microsoft.MixedReality.Toolkit.Core.Attributes;
45
using Microsoft.MixedReality.Toolkit.Core.Definitions;
56
using Microsoft.MixedReality.Toolkit.Core.Extensions.EditorClassExtensions;
67
using Microsoft.MixedReality.Toolkit.Core.Services;
@@ -44,9 +45,9 @@ public static bool CheckMixedRealityConfigured(bool flag = true)
4445
/// <param name="guiContent">The GUIContent for the field.</param>
4546
/// <param name="showAddButton">Optional flag to hide the create button.</param>
4647
/// <returns>True, if the profile changed.</returns>
47-
protected static bool RenderProfile(SerializedProperty property, GUIContent guiContent, bool showAddButton = true)
48+
protected static bool RenderProfile(SerializedProperty property, GUIContent guiContent, bool showAddButton = true, Type serviceType = null)
4849
{
49-
return RenderProfileInternal(property, guiContent, showAddButton);
50+
return RenderProfileInternal(property, guiContent, showAddButton, serviceType);
5051
}
5152

5253
/// <summary>
@@ -55,18 +56,40 @@ protected static bool RenderProfile(SerializedProperty property, GUIContent guiC
5556
/// <param name="property">the <see cref="Microsoft.MixedReality.Toolkit.Core.Definitions.BaseMixedRealityProfile"/> property.</param>
5657
/// <param name="showAddButton">Optional flag to hide the create button.</param>
5758
/// <returns>True, if the profile changed.</returns>
58-
protected static bool RenderProfile(SerializedProperty property, bool showAddButton = true)
59+
protected static bool RenderProfile(SerializedProperty property, bool showAddButton = true, Type serviceType = null)
5960
{
60-
return RenderProfileInternal(property, null, showAddButton);
61+
return RenderProfileInternal(property, null, showAddButton, serviceType);
6162
}
6263

63-
private static bool RenderProfileInternal(SerializedProperty property, GUIContent guiContent, bool showAddButton)
64+
private static bool RenderProfileInternal(SerializedProperty property, GUIContent guiContent, bool showAddButton, Type serviceType = null)
6465
{
6566
bool changed = false;
66-
EditorGUILayout.BeginHorizontal();
6767

6868
var oldObject = property.objectReferenceValue;
6969

70+
// If we're constraining this to a service type, check whether the profile is valid
71+
// If it isn't, issue a warning.
72+
if (serviceType != null && oldObject != null)
73+
{
74+
bool profileTypeIsValid = false;
75+
76+
foreach (MixedRealityServiceProfileAttribute serviceProfileAttribute in oldObject.GetType().GetCustomAttributes(typeof(MixedRealityServiceProfileAttribute), true))
77+
{
78+
if (serviceProfileAttribute.ServiceType.IsAssignableFrom(serviceType))
79+
{
80+
profileTypeIsValid = true;
81+
break;
82+
}
83+
}
84+
85+
if (!profileTypeIsValid)
86+
{
87+
EditorGUILayout.HelpBox("This profile is not supported for " + serviceType.Name + ". Using an unsupported service may result in unexpected behavior.", MessageType.Warning);
88+
}
89+
}
90+
91+
EditorGUILayout.BeginHorizontal();
92+
7093
if (guiContent == null)
7194
{
7295
EditorGUILayout.PropertyField(property);
@@ -101,7 +124,7 @@ private static bool RenderProfileInternal(SerializedProperty property, GUIConten
101124

102125
if (!renderedProfile.IsCustomProfile && profile.IsCustomProfile)
103126
{
104-
if (GUILayout.Button(new GUIContent("</>", "Replace with a copy of the default profile."), EditorStyles.miniButton, GUILayout.Width(32f)))
127+
if (GUILayout.Button(new GUIContent("Clone", "Replace with a copy of the default profile."), EditorStyles.miniButton, GUILayout.Width(42f)))
105128
{
106129
profileToCopy = renderedProfile;
107130
var profileTypeName = property.objectReferenceValue.GetType().Name;
@@ -116,12 +139,7 @@ private static bool RenderProfileInternal(SerializedProperty property, GUIConten
116139
}
117140
}
118141
}
119-
120-
if (oldObject != property.objectReferenceValue)
121-
{
122-
changed = true;
123-
}
124-
142+
125143
EditorGUILayout.EndHorizontal();
126144

127145
// Check fields within profile for other nested profiles
@@ -133,7 +151,7 @@ private static bool RenderProfileInternal(SerializedProperty property, GUIConten
133151
{
134152
string showFoldoutKey = GetSubProfileDropdownKey(property);
135153
bool showFoldout = SessionState.GetBool(showFoldoutKey, false);
136-
showFoldout = EditorGUILayout.Foldout(showFoldout, showFoldout ? "Hide " + property.displayName + " contents" : "Show " + property.displayName + " contents");
154+
showFoldout = EditorGUILayout.Foldout(showFoldout, showFoldout ? "Hide " + property.displayName + " contents" : "Show " + property.displayName + " contents", true);
137155

138156
if (showFoldout)
139157
{
@@ -146,11 +164,15 @@ private static bool RenderProfileInternal(SerializedProperty property, GUIConten
146164
configProfile.RenderAsSubProfile = true;
147165
}
148166

149-
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
150167
EditorGUI.indentLevel++;
168+
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
151169
subProfileEditor.OnInspectorGUI();
152-
EditorGUI.indentLevel--;
170+
171+
EditorGUILayout.Space();
172+
EditorGUILayout.Space();
173+
153174
EditorGUILayout.EndVertical();
175+
EditorGUI.indentLevel--;
154176
}
155177

156178
SessionState.SetBool(showFoldoutKey, showFoldout);

Assets/MixedRealityToolkit/Inspectors/Profiles/BaseMixedRealityToolkitConfigurationProfileInspector.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,14 @@ public abstract class MixedRealityBaseConfigurationProfileInspector { }
1919
/// </summary>
2020
public abstract class BaseMixedRealityToolkitConfigurationProfileInspector : BaseMixedRealityProfileInspector
2121
{
22-
public bool RenderAsSubProfile
23-
{
24-
set { renderAsSubProfile = value; }
25-
}
22+
public bool RenderAsSubProfile { get; set; }
2623

2724
[SerializeField]
2825
private Texture2D logoLightTheme = null;
2926

3027
[SerializeField]
3128
private Texture2D logoDarkTheme = null;
32-
33-
private bool renderAsSubProfile = false;
34-
29+
3530
protected virtual void Awake()
3631
{
3732
string assetPath = $"{MixedRealityEditorSettings.MixedRealityToolkit_RelativeFolderPath}/StandardAssets/Textures";
@@ -53,7 +48,7 @@ protected virtual void Awake()
5348
protected void RenderMixedRealityToolkitLogo()
5449
{
5550
// If we're being rendered as a sub profile, don't show the logo
56-
if (renderAsSubProfile)
51+
if (RenderAsSubProfile)
5752
return;
5853

5954
GUILayout.BeginHorizontal();
@@ -73,7 +68,7 @@ protected void RenderMixedRealityToolkitLogo()
7368
protected bool DrawBacktrackProfileButton(string message, UnityEngine.Object activeObject)
7469
{
7570
// If we're being rendered as a sub profile, don't show the button
76-
if (renderAsSubProfile)
71+
if (RenderAsSubProfile)
7772
return false;
7873

7974
if (GUILayout.Button(message))

0 commit comments

Comments
 (0)