Skip to content

Commit b7c0730

Browse files
Fixes as per review
1 parent 4dcc316 commit b7c0730

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

Assets/MixedRealityToolkit/_Core/Inspectors/MixedRealityControllerMappingProfileInspector.cs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public override void OnInspectorGUI()
8787
//Inspect the SerializedProperty - Because Unity does not support a "Value" property.
8888
SystemType targetController = GetSystemTypeFromSerializedProperty(i);
8989

90-
if (targetController.Type != null && !configuredControllerTypes.Contains(targetController.Type.ToString()))
90+
if (targetController?.Type != null && !configuredControllerTypes.Contains(targetController.Type.ToString()))
9191
{
9292
configuredControllerTypes.Add(targetController.Type.ToString());
9393
}
@@ -116,7 +116,7 @@ public override void OnInspectorGUI()
116116
SystemType targetController = GetSystemTypeFromSerializedProperty(i);
117117

118118
//Add the
119-
if (targetController.Type != null && !updatedControllerTypes.Contains(targetController.Type.ToString()))
119+
if (targetController?.Type != null && !updatedControllerTypes.Contains(targetController.Type.ToString()))
120120
{
121121
updatedControllerTypes.Add(targetController.Type.ToString());
122122
if (!configuredControllerTypes.Contains(targetController.Type.ToString()))
@@ -332,47 +332,61 @@ private static int CheckValue(int value, int against)
332332

333333
#region Serialized Property Inspector
334334

335-
private static object GetValue_Imp(object source, string name)
335+
private static object GetValue_Implementation(object source, string name)
336336
{
337337
if (source == null)
338+
{
338339
return null;
340+
}
341+
339342
var type = source.GetType();
340343

341344
while (type != null)
342345
{
343-
var f = type.GetField(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
344-
if (f != null)
345-
return f.GetValue(source);
346+
var field = type.GetField(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
347+
if (field != null)
348+
{
349+
return field.GetValue(source);
350+
}
346351

347-
var p = type.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
348-
if (p != null)
349-
return p.GetValue(source, null);
352+
var property = type.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
353+
if (property != null)
354+
{
355+
return property.GetValue(source, null);
356+
}
350357

351358
type = type.BaseType;
352359
}
353360
return null;
354361
}
355362

356-
private static object GetValue_Imp(object source, string name, int index)
363+
private static object GetValue_Implementation(object source, string name, int index)
357364
{
358-
var enumerable = GetValue_Imp(source, name) as System.Collections.IEnumerable;
359-
if (enumerable == null) return null;
360-
var enm = enumerable.GetEnumerator();
365+
var enumerable = GetValue_Implementation(source, name) as System.Collections.IEnumerable;
366+
if (enumerable == null)
367+
{
368+
return null;
369+
}
370+
371+
var enumerator = enumerable.GetEnumerator();
361372

362373
for (int i = 0; i <= index; i++)
363374
{
364-
if (!enm.MoveNext()) return null;
375+
if (!enumerator.MoveNext())
376+
{
377+
return null;
378+
}
365379
}
366-
return enm.Current;
380+
return enumerator.Current;
367381
}
368382

369383
private SystemType GetSystemTypeFromSerializedProperty(int i)
370384
{
371385
var item = mixedRealityControllerMappingProfiles.GetArrayElementAtIndex(i);
372386
var controllerType = item.FindPropertyRelative("controller");
373387
var targetObject = controllerType.serializedObject.targetObject;
374-
var targetObjectClassType = GetValue_Imp(targetObject, "mixedRealityControllerMappingProfiles", i);
375-
var targetController = GetValue_Imp(targetObjectClassType, "controller") as SystemType;
388+
var targetObjectClassType = GetValue_Implementation(targetObject, "mixedRealityControllerMappingProfiles", i);
389+
var targetController = GetValue_Implementation(targetObjectClassType, "controller") as SystemType;
376390
return targetController;
377391
}
378392

0 commit comments

Comments
 (0)