@@ -18,6 +18,7 @@ public class MixedRealityPointerProfileInspector : BaseMixedRealityToolkitConfig
18
18
private static readonly GUIContent GazeCursorPrefabContent = new GUIContent ( "Gaze Cursor Prefab" ) ;
19
19
private static readonly GUIContent UseEyeTrackingDataContent = new GUIContent ( "Use Eye Tracking Data" ) ;
20
20
private static readonly GUIContent RaycastLayerMaskContent = new GUIContent ( "Default Raycast LayerMasks" ) ;
21
+ private static readonly GUIContent PointerRaycastLayerMaskContent = new GUIContent ( "Pointer Raycast LayerMasks" ) ;
21
22
22
23
#if UNITY_2019_3_OR_NEWER
23
24
private const string EnableGazeCapabilityContent = "To use eye tracking with UWP, the GazeInput capability needs to be set in the manifest." +
@@ -28,7 +29,7 @@ public class MixedRealityPointerProfileInspector : BaseMixedRealityToolkitConfig
28
29
private const string ProfileDescription = "Pointers attach themselves onto controllers as they are initialized." ;
29
30
30
31
private SerializedProperty pointingExtent ;
31
- private SerializedProperty pointingRaycastLayerMasks ;
32
+ private SerializedProperty defaultRaycastLayerMasks ;
32
33
private static bool showPointerOptionProperties = true ;
33
34
private SerializedProperty pointerOptions ;
34
35
@@ -50,7 +51,7 @@ protected override void OnEnable()
50
51
base . OnEnable ( ) ;
51
52
52
53
pointingExtent = serializedObject . FindProperty ( "pointingExtent" ) ;
53
- pointingRaycastLayerMasks = serializedObject . FindProperty ( "pointingRaycastLayerMasks" ) ;
54
+ defaultRaycastLayerMasks = serializedObject . FindProperty ( "pointingRaycastLayerMasks" ) ;
54
55
pointerOptions = serializedObject . FindProperty ( "pointerOptions" ) ;
55
56
debugDrawPointingRays = serializedObject . FindProperty ( "debugDrawPointingRays" ) ;
56
57
debugDrawPointingRayColors = serializedObject . FindProperty ( "debugDrawPointingRayColors" ) ;
@@ -75,7 +76,7 @@ public override void OnInspectorGUI()
75
76
76
77
EditorGUILayout . Space ( ) ;
77
78
EditorGUILayout . PropertyField ( pointingExtent ) ;
78
- EditorGUILayout . PropertyField ( pointingRaycastLayerMasks , RaycastLayerMaskContent , true ) ;
79
+ EditorGUILayout . PropertyField ( defaultRaycastLayerMasks , RaycastLayerMaskContent , true ) ;
79
80
EditorGUILayout . PropertyField ( pointerMediator ) ;
80
81
EditorGUILayout . PropertyField ( primaryPointerSelector ) ;
81
82
@@ -117,8 +118,11 @@ public override void OnInspectorGUI()
117
118
// Provide a convenient way to toggle the gaze provider as enabled/disabled via editor
118
119
gazeProvider . Enabled = EditorGUILayout . Toggle ( "Enable Gaze Provider" , gazeProvider . Enabled ) ;
119
120
120
- // Draw out the rest of the Gaze Provider's settings
121
- gazeProviderEditor . OnInspectorGUI ( ) ;
121
+ using ( new EditorGUI . IndentLevelScope ( ) )
122
+ {
123
+ // Draw out the rest of the Gaze Provider's settings
124
+ gazeProviderEditor . OnInspectorGUI ( ) ;
125
+ }
122
126
}
123
127
}
124
128
@@ -133,7 +137,6 @@ public override void OnInspectorGUI()
133
137
}
134
138
}
135
139
136
-
137
140
EditorGUILayout . Space ( ) ;
138
141
EditorGUILayout . LabelField ( "Debug Settings" , EditorStyles . boldLabel ) ;
139
142
{
@@ -156,8 +159,6 @@ protected override bool IsProfileInActiveInstance()
156
159
157
160
private void RenderPointerList ( SerializedProperty list )
158
161
{
159
- var profile = target as MixedRealityPointerProfile ;
160
-
161
162
if ( InspectorUIUtility . RenderIndentedButton ( AddButtonContent , EditorStyles . miniButton ) )
162
163
{
163
164
pointerOptions . arraySize += 1 ;
@@ -181,11 +182,10 @@ private void RenderPointerList(SerializedProperty list)
181
182
return ;
182
183
}
183
184
185
+ bool anyPrefabChanged = false ;
186
+
184
187
for ( int i = 0 ; i < list . arraySize ; i ++ )
185
188
{
186
- IMixedRealityPointer pointer = null ;
187
- Object pointerPrefab = null ;
188
-
189
189
using ( new EditorGUILayout . VerticalScope ( EditorStyles . helpBox ) )
190
190
{
191
191
Color prevColor = GUI . color ;
@@ -196,47 +196,15 @@ private void RenderPointerList(SerializedProperty list)
196
196
var prefab = pointerOption . FindPropertyRelative ( "pointerPrefab" ) ;
197
197
var prioritizedLayerMasks = pointerOption . FindPropertyRelative ( "prioritizedLayerMasks" ) ;
198
198
199
- pointerPrefab = prefab . objectReferenceValue ;
200
- pointer = pointerPrefab . IsNull ( ) ? null : ( ( GameObject ) pointerPrefab ) . GetComponent < IMixedRealityPointer > ( ) ;
199
+ GameObject pointerPrefab = prefab . objectReferenceValue as GameObject ;
200
+ IMixedRealityPointer pointer = pointerPrefab != null ? pointerPrefab . GetComponent < IMixedRealityPointer > ( ) : null ;
201
201
202
202
// Display an error if the prefab doesn't have a IMixedRealityPointer Component
203
- if ( pointer == null )
203
+ if ( pointer . IsNull ( ) )
204
204
{
205
205
InspectorUIUtility . DrawError ( $ "The prefab associated with this pointer option needs an { typeof ( IMixedRealityPointer ) . Name } component") ;
206
-
207
206
GUI . color = MixedRealityInspectorUtility . ErrorColor ;
208
207
}
209
- // if the prefab does have the component, provide a field to display and edit it's PrioritzedLayerMaskOverrides if it specifies a way to get it
210
- else
211
- {
212
- // sync the pointer option with the prefab
213
- if ( pointer . PrioritizedLayerMasksOverride != null )
214
- {
215
- if ( prioritizedLayerMasks . arraySize != pointer . PrioritizedLayerMasksOverride . Length )
216
- {
217
- prioritizedLayerMasks . arraySize = pointer . PrioritizedLayerMasksOverride . Length ;
218
- }
219
- foreach ( LayerMask mask in pointer . PrioritizedLayerMasksOverride )
220
- {
221
- SerializedProperty item = prioritizedLayerMasks . GetArrayElementAtIndex ( prioritizedLayerMasks . arraySize - 1 ) ;
222
- item . intValue = mask ;
223
- }
224
- }
225
-
226
- // if after syncing the the pointer option list is still empty, initialize with the global default
227
- // sync the pointer option with the prefab
228
- if ( prioritizedLayerMasks . arraySize == 0 )
229
- {
230
- for ( int j = 0 ; j < pointingRaycastLayerMasks . arraySize ; j ++ )
231
- {
232
- var mask = pointingRaycastLayerMasks . GetArrayElementAtIndex ( j ) . intValue ;
233
-
234
- prioritizedLayerMasks . InsertArrayElementAtIndex ( prioritizedLayerMasks . arraySize ) ;
235
- SerializedProperty item = prioritizedLayerMasks . GetArrayElementAtIndex ( prioritizedLayerMasks . arraySize - 1 ) ;
236
- item . intValue = mask ;
237
- }
238
- }
239
- }
240
208
241
209
using ( new EditorGUILayout . HorizontalScope ( ) )
242
210
{
@@ -253,23 +221,36 @@ private void RenderPointerList(SerializedProperty list)
253
221
254
222
// Ultimately sync the pointer prefab's value with the pointer option's
255
223
EditorGUI . BeginChangeCheck ( ) ;
256
- EditorGUILayout . PropertyField ( prioritizedLayerMasks , new GUIContent ( "Pointer Raycast LayerMasks" ) , true ) ;
257
- if ( EditorGUI . EndChangeCheck ( ) && pointer . PrioritizedLayerMasksOverride != null )
224
+ EditorGUILayout . PropertyField ( prioritizedLayerMasks , PointerRaycastLayerMaskContent , true ) ;
225
+ if ( EditorGUI . EndChangeCheck ( ) && pointer . IsNotNull ( ) )
258
226
{
259
227
Undo . RecordObject ( pointerPrefab , "Sync Pointer Prefab" ) ;
260
- pointer . PrioritizedLayerMasksOverride = new LayerMask [ prioritizedLayerMasks . arraySize ] ;
261
- for ( int j = 0 ; j < prioritizedLayerMasks . arraySize ; j ++ )
228
+
229
+ int prioritizedLayerMasksCount = prioritizedLayerMasks . arraySize ;
230
+ if ( pointer . PrioritizedLayerMasksOverride ? . Length != prioritizedLayerMasksCount )
231
+ {
232
+ pointer . PrioritizedLayerMasksOverride = new LayerMask [ prioritizedLayerMasksCount ] ;
233
+ }
234
+
235
+ for ( int j = 0 ; j < prioritizedLayerMasksCount ; j ++ )
262
236
{
263
237
pointer . PrioritizedLayerMasksOverride [ j ] = prioritizedLayerMasks . GetArrayElementAtIndex ( j ) . intValue ;
264
238
}
265
-
239
+
266
240
PrefabUtility . RecordPrefabInstancePropertyModifications ( pointerPrefab ) ;
241
+ EditorUtility . SetDirty ( pointerPrefab ) ;
242
+ anyPrefabChanged = true ;
267
243
}
268
244
269
245
GUI . color = prevColor ;
270
246
}
271
247
EditorGUILayout . Space ( ) ;
272
248
}
249
+
250
+ if ( anyPrefabChanged )
251
+ {
252
+ AssetDatabase . SaveAssets ( ) ;
253
+ }
273
254
}
274
255
}
275
256
}
0 commit comments