Skip to content

Commit

Permalink
Use the new object field handling for non-custom inspector values
Browse files Browse the repository at this point in the history
- Use the new object field handling for values on the default U# inspector. This primarily makes the object search window work as expected and only show objects with behaviours of the correct type instead of the old behavior where all objects with UdonBehaviours were shown. It also reduces the amount of reflection we're doing which is nice.
  • Loading branch information
MerlinVR committed Sep 23, 2020
1 parent 88e2aec commit 686b7bc
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions Assets/UdonSharp/Editor/Editors/UdonSharpGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ internal static bool DrawCreateScriptButton(UdonSharpProgramAsset programAsset)

return false;
}
private static MonoScript currentUserScript = null;

private static MonoScript currentUserScript;
private static UnityEngine.Object ValidateObjectReference(UnityEngine.Object[] references, System.Type objType, SerializedProperty property, Enum options = null)
{
if (property != null)
Expand Down Expand Up @@ -552,25 +552,31 @@ private static object DrawUnityObjectField(GUIContent fieldName, string symbol,
Rect originalRect = objectRect;
int id = GUIUtility.GetControlID(typeof(UnityEngine.Object).GetHashCode(), FocusType.Keyboard, originalRect);

System.Type validatorDelegateType = typeof(EditorGUI).GetNestedType("ObjectFieldValidator", BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo validateMethodInfo = typeof(UdonSharpGUI).GetMethod(nameof(ValidateObjectReference), BindingFlags.NonPublic | BindingFlags.Static);

objectRect = EditorGUI.PrefixLabel(objectRect, id, new GUIContent(fieldName));

currentUserScript = fieldDefinition.userBehaviourSource;
System.Type searchType = fieldDefinition.userBehaviourSource != null ? fieldDefinition.userBehaviourSource.GetClass() : typeof(UdonSharpBehaviour);

UnityEngine.Object objectFieldValue = (UnityEngine.Object)doObjectFieldMethod.Invoke(null, new object[] {
objectRect,
objectRect,
id,
(UnityEngine.Object)value,
typeof(UdonBehaviour),
searchType,
null,
null,
System.Delegate.CreateDelegate(validatorDelegateType, validateMethodInfo),
true
});

currentUserScript = null;
if (objectFieldValue != null &&
objectFieldValue is UdonSharpBehaviour udonSharpBehaviour &&
UdonSharpEditorUtility.IsProxyBehaviour(udonSharpBehaviour))
{
objectFieldValue = UdonSharpEditorUtility.GetBackingUdonBehaviour(udonSharpBehaviour);
}
else if (!(objectFieldValue is UdonBehaviour))
{
objectFieldValue = null;
}

string labelText;
System.Type variableType = fieldDefinition.fieldSymbol.userCsType;
Expand Down Expand Up @@ -740,6 +746,7 @@ private static object DrawFieldForType(string fieldName, string symbol, (object
Array.Copy(draggedReferences.ToArray(), 0, newArray, oldArray.Length, draggedReferences.Count);

GUI.changed = true;
Event.current.Use();
DragAndDrop.AcceptDrag();

return newArray;
Expand Down

0 comments on commit 686b7bc

Please sign in to comment.