diff --git a/Editor/Drawers/RawReferenceDrawer.cs b/Editor/Drawers/RawReferenceDrawer.cs index 5390f06..e5e404f 100644 --- a/Editor/Drawers/RawReferenceDrawer.cs +++ b/Editor/Drawers/RawReferenceDrawer.cs @@ -72,6 +72,9 @@ public void OnGUI(Rect position) : new GUIContent(rawReferenceValue.GetType().Name, IconUtility.ScriptIcon); CustomObjectDrawer.OnGUI(objectFieldRect, label, content); + + HandleDragAndDrop(objectFieldRect); + if (rawReferenceValue == null) return; @@ -83,8 +86,6 @@ public void OnGUI(Rect position) new GUIContent(rawReferenceValue.GetType().Name), true); - HandleDragAndDrop(objectFieldRect); - previousPropertyPath = Property.propertyPath; } diff --git a/Editor/Drawers/ReferenceDrawer.cs b/Editor/Drawers/ReferenceDrawer.cs index 0193f43..599c6ad 100644 --- a/Editor/Drawers/ReferenceDrawer.cs +++ b/Editor/Drawers/ReferenceDrawer.cs @@ -113,13 +113,17 @@ private void OnItemSelected(ReferenceMode mode, object reference) protected void HandleDragAndDrop(Rect position) { + if (!position.Contains(Event.current.mousePosition)) + return; + if (Event.current.type == EventType.DragPerform) { + HandleDragUpdated(); HandleDragPerform(); } else if (Event.current.type == EventType.DragUpdated) { - HandleDragUpdated(position); + HandleDragUpdated(); } } @@ -138,11 +142,8 @@ private void SetDragAndDropMode(bool success, DragAndDropMode? successMode = nul } } - private void HandleDragUpdated(Rect position) + private void HandleDragUpdated() { - if (!position.Contains(Event.current.mousePosition)) - return; - if (DragAndDrop.objectReferences.Length > 1) { SetDragAndDropMode(false); @@ -191,7 +192,11 @@ private void HandleDragPerform() ReferenceModeProperty.enumValueIndex = (int)ReferenceMode.Raw; break; case DragAndDropMode.Unity: - UnityReferenceProperty.objectReferenceValue = DragAndDrop.objectReferences[0]; + if(DragAndDrop.objectReferences[0] is GameObject go) + UnityReferenceProperty.objectReferenceValue = go.GetComponent(GenericType); + else + UnityReferenceProperty.objectReferenceValue = DragAndDrop.objectReferences[0]; + ReferenceModeProperty.enumValueIndex = (int)ReferenceMode.Unity; break; case DragAndDropMode.None: