Skip to content

Commit

Permalink
🐛 fix(core): Fix inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
esnya committed Jul 26, 2022
1 parent fef79c6 commit 44109ab
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static void Apply(SerializedObject serializedCarObject, IEnumerable<Wheel
}
}

private void OnWheelsGUI(SerializedProperty property)
private void OnWheelsGUI()
{
var descriptors = WheelDescriptor.GetDescriptors(serializedObject).ToArray();
using (var change = new EditorGUI.ChangeCheckScope())
Expand All @@ -124,8 +124,6 @@ private void OnWheelsGUI(SerializedProperty property)
}
if (change.changed) WheelDescriptor.Apply(serializedObject, descriptors);
}

while (property.name.ToLower().Contains("wheel")) property.NextVisible(false);
}

private static readonly Dictionary<string, string> gameObjectNameTable = new Dictionary<string, string>() {
Expand All @@ -150,33 +148,31 @@ public override void OnInspectorGUI()

while (property.NextVisible(false))
{
if (property.name == nameof(USC_Car.wheels)) OnWheelsGUI(property);
else
using (new EditorGUILayout.HorizontalScope())
{
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.PropertyField(property, true);
EditorGUILayout.PropertyField(property, true);

if (gameObjectNameTable.ContainsKey(property.name))
if (gameObjectNameTable.ContainsKey(property.name))
{
var name = gameObjectNameTable[property.name];
if (GUILayout.Button("Find", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
{
var name = gameObjectNameTable[property.name];
if (GUILayout.Button("Find", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
var gameObject = EditorUtility.CollectDeepHierarchy(serializedObject.targetObjects)
.Select(o => o as GameObject)
.FirstOrDefault(o => o && o.name == name);

if (gameObject)
{
var gameObject = EditorUtility.CollectDeepHierarchy(serializedObject.targetObjects)
.Select(o => o as GameObject)
.FirstOrDefault(o => o && o.name == name);

if (gameObject)
{
var fieldType = typeof(USC_Car).GetField(property.name, BindingFlags.Instance | BindingFlags.DeclaredOnly)?.FieldType;
property.objectReferenceValue = fieldType?.IsSubclassOf(typeof(Component)) == true ? (UnityEngine.Object)gameObject.GetComponent(fieldType) : gameObject;
}
var fieldType = typeof(USC_Car).GetField(property.name, BindingFlags.Instance | BindingFlags.DeclaredOnly)?.FieldType;
property.objectReferenceValue = fieldType?.IsSubclassOf(typeof(Component)) == true ? (UnityEngine.Object)gameObject.GetComponent(fieldType) : gameObject;
}
}
}
}
}

OnWheelsGUI();

serializedObject.ApplyModifiedProperties();
}
}
Expand Down
Loading

0 comments on commit 44109ab

Please sign in to comment.