Skip to content

Commit ffff1a5

Browse files
authored
Merge pull request #26 from marc-antoine-girard/#24-Add-None-Option-CustomDrawers
2 parents f4d6a9f + 1b5e0af commit ffff1a5

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
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/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)