Skip to content

Commit 5a14905

Browse files
Merge remote-tracking branch 'upstream/main' into #25-Fix-Setter-ReferenceDrawer
2 parents 6ddab6e + 05908da commit 5a14905

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

Editor/Drawers/CustomObjectDrawer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ private void HandleMouseDown(Rect position, Rect positionWithoutThumb)
9494
else if (Event.button == 1 && positionWithoutThumb.Contains(Event.mousePosition))
9595
{
9696
GenericMenu menu = new GenericMenu();
97+
menu.AddItem(new GUIContent("Clear"), false, () => { DeletePressed?.Invoke(); });
9798
menu.AddItem(new GUIContent("Properties..."), false, () => { PropertiesClicked?.Invoke(); });
9899
menu.DropDown(position);
99100
Event.Use();

Editor/Drawers/RawReferenceDrawer.cs

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

5050
CustomObjectDrawer.OnGUI(objectFieldRect, label, content);
51+
52+
HandleDragAndDrop(objectFieldRect);
53+
5154
if (rawReferenceValue == null)
5255
return;
5356

@@ -59,8 +62,6 @@ public void OnGUI(Rect position)
5962
new GUIContent(rawReferenceValue.GetType().Name),
6063
true);
6164

62-
HandleDragAndDrop(objectFieldRect);
63-
6465
previousPropertyPath = Property.propertyPath;
6566
}
6667

@@ -72,6 +73,9 @@ protected override void PingObject()
7273
/// <inheritdoc />
7374
protected override void OnPropertiesClicked()
7475
{
76+
if (RawReferenceValue == null)
77+
return;
78+
7579
Type type = RawReferenceValue.GetType();
7680
string typeName = type.Name;
7781

Editor/Drawers/ReferenceDrawer.cs

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

152152
protected void HandleDragAndDrop(Rect position)
153153
{
154+
if (!position.Contains(Event.current.mousePosition))
155+
return;
156+
154157
if (Event.current.type == EventType.DragPerform)
155158
{
159+
HandleDragUpdated();
156160
HandleDragPerform();
157161
}
158162
else if (Event.current.type == EventType.DragUpdated)
159163
{
160-
HandleDragUpdated(position);
164+
HandleDragUpdated();
161165
}
162166
}
163167

@@ -176,11 +180,8 @@ private void SetDragAndDropMode(bool success, DragAndDropMode? successMode = nul
176180
}
177181
}
178182

179-
private void HandleDragUpdated(Rect position)
183+
private void HandleDragUpdated()
180184
{
181-
if (!position.Contains(Event.current.mousePosition))
182-
return;
183-
184185
if (DragAndDrop.objectReferences.Length > 1)
185186
{
186187
SetDragAndDropMode(false);

Editor/Items/NoneDropdownItem.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using UnityEditor.IMGUI.Controls;
2+
3+
namespace TNRD.Items
4+
{
5+
public class NoneDropdownItem : AdvancedDropdownItem, IDropdownItem
6+
{
7+
public NoneDropdownItem() : base("None") { }
8+
9+
ReferenceMode IDropdownItem.Mode => ReferenceMode.Raw;
10+
11+
public object GetValue()
12+
{
13+
return null;
14+
}
15+
}
16+
}

Editor/Items/NoneDropdownItem.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Utilities/SerializableInterfaceAdvancedDropdown.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ protected override AdvancedDropdownItem BuildRoot()
4848
.AddChild(new ClassesItemBuilder(interfaceType).Build())
4949
.AddChild(new SceneItemBuilder(interfaceType, relevantScene).Build());
5050

51+
foreach (AdvancedDropdownItem dropdownItem in item.children)
52+
{
53+
dropdownItem.AddChild(new NoneDropdownItem());
54+
}
55+
5156
if (canSort)
5257
{
5358
sortChildrenMethod.Invoke(item,
@@ -62,6 +67,12 @@ protected override AdvancedDropdownItem BuildRoot()
6267

6368
private int Sort(AdvancedDropdownItem a, AdvancedDropdownItem b)
6469
{
70+
// For aesthetic reasons. Always puts the None first
71+
if (a is NoneDropdownItem)
72+
return -1;
73+
if (b is NoneDropdownItem)
74+
return 1;
75+
6576
int childrenA = a.children.Count();
6677
int childrenB = b.children.Count();
6778

0 commit comments

Comments
 (0)