From 5495d0078d0c6cd852a940f4ecf68694882ee6cc Mon Sep 17 00:00:00 2001 From: Marc-Antoine Girard Date: Tue, 12 Jul 2022 15:46:47 -0400 Subject: [PATCH 1/2] Fixed Drag and Drop behaviour --- Editor/Drawers/RawReferenceDrawer.cs | 5 +++-- Editor/Drawers/ReferenceDrawer.cs | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Editor/Drawers/RawReferenceDrawer.cs b/Editor/Drawers/RawReferenceDrawer.cs index 72fa6e7..2720df3 100644 --- a/Editor/Drawers/RawReferenceDrawer.cs +++ b/Editor/Drawers/RawReferenceDrawer.cs @@ -59,6 +59,9 @@ public void OnGUI(Rect position) : new GUIContent(rawReferenceValue.GetType().Name, IconUtility.ScriptIcon); CustomObjectDrawer.OnGUI(objectFieldRect, label, content); + + HandleDragAndDrop(objectFieldRect); + if (rawReferenceValue == null) return; @@ -69,8 +72,6 @@ public void OnGUI(Rect position) RawReferenceProperty, new GUIContent(rawReferenceValue.GetType().Name), true); - - HandleDragAndDrop(objectFieldRect); } /// diff --git a/Editor/Drawers/ReferenceDrawer.cs b/Editor/Drawers/ReferenceDrawer.cs index 984dc05..81f7d21 100644 --- a/Editor/Drawers/ReferenceDrawer.cs +++ b/Editor/Drawers/ReferenceDrawer.cs @@ -109,13 +109,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(); } } @@ -134,11 +138,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); From b0aa93178a55b8ec8c2969a260c914de185d4e26 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Girard Date: Tue, 12 Jul 2022 16:39:15 -0400 Subject: [PATCH 2/2] Update ReferenceDrawer.cs --- Editor/Drawers/ReferenceDrawer.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Editor/Drawers/ReferenceDrawer.cs b/Editor/Drawers/ReferenceDrawer.cs index 81f7d21..bb348cd 100644 --- a/Editor/Drawers/ReferenceDrawer.cs +++ b/Editor/Drawers/ReferenceDrawer.cs @@ -188,7 +188,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: