Skip to content

Commit 05908da

Browse files
authored
Merge pull request #28 from marc-antoine-girard/#22-Fix-DragAndDrop-ReferenceDrawer
2 parents ffff1a5 + 38f79b8 commit 05908da

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

Editor/Drawers/RawReferenceDrawer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public void OnGUI(Rect position)
7272
: new GUIContent(rawReferenceValue.GetType().Name, IconUtility.ScriptIcon);
7373

7474
CustomObjectDrawer.OnGUI(objectFieldRect, label, content);
75+
76+
HandleDragAndDrop(objectFieldRect);
77+
7578
if (rawReferenceValue == null)
7679
return;
7780

@@ -83,8 +86,6 @@ public void OnGUI(Rect position)
8386
new GUIContent(rawReferenceValue.GetType().Name),
8487
true);
8588

86-
HandleDragAndDrop(objectFieldRect);
87-
8889
previousPropertyPath = Property.propertyPath;
8990
}
9091

Editor/Drawers/ReferenceDrawer.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,17 @@ private void OnItemSelected(ReferenceMode mode, object reference)
113113

114114
protected void HandleDragAndDrop(Rect position)
115115
{
116+
if (!position.Contains(Event.current.mousePosition))
117+
return;
118+
116119
if (Event.current.type == EventType.DragPerform)
117120
{
121+
HandleDragUpdated();
118122
HandleDragPerform();
119123
}
120124
else if (Event.current.type == EventType.DragUpdated)
121125
{
122-
HandleDragUpdated(position);
126+
HandleDragUpdated();
123127
}
124128
}
125129

@@ -138,11 +142,8 @@ private void SetDragAndDropMode(bool success, DragAndDropMode? successMode = nul
138142
}
139143
}
140144

141-
private void HandleDragUpdated(Rect position)
145+
private void HandleDragUpdated()
142146
{
143-
if (!position.Contains(Event.current.mousePosition))
144-
return;
145-
146147
if (DragAndDrop.objectReferences.Length > 1)
147148
{
148149
SetDragAndDropMode(false);
@@ -191,7 +192,11 @@ private void HandleDragPerform()
191192
ReferenceModeProperty.enumValueIndex = (int)ReferenceMode.Raw;
192193
break;
193194
case DragAndDropMode.Unity:
194-
UnityReferenceProperty.objectReferenceValue = DragAndDrop.objectReferences[0];
195+
if(DragAndDrop.objectReferences[0] is GameObject go)
196+
UnityReferenceProperty.objectReferenceValue = go.GetComponent(GenericType);
197+
else
198+
UnityReferenceProperty.objectReferenceValue = DragAndDrop.objectReferences[0];
199+
195200
ReferenceModeProperty.enumValueIndex = (int)ReferenceMode.Unity;
196201
break;
197202
case DragAndDropMode.None:

0 commit comments

Comments
 (0)