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 ;
45using Microsoft . MixedReality . Toolkit . Core . Definitions ;
56using Microsoft . MixedReality . Toolkit . Core . Extensions . EditorClassExtensions ;
67using 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 ) ;
0 commit comments