Skip to content

Instantly share code, notes, and snippets.

@MrMMatricks
Created July 8, 2020 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrMMatricks/716651b46887cc0f965519b18bacf81a to your computer and use it in GitHub Desktop.
Save MrMMatricks/716651b46887cc0f965519b18bacf81a to your computer and use it in GitHub Desktop.
DrawerTestValue.cs
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
#if UNITY_EDITOR
using Sirenix.OdinInspector.Editor;
using UnityEditor;
using Sirenix.Utilities;
#endif
namespace LostInTheGarden.StyleManager
{
public class DrawerTestObject : MonoBehaviour
{
public DrawerTestValue test;
}
[Serializable]
public class DrawerTestValue
{
public string testValue = "";
}
#if UNITY_EDITOR
public class DrawerTestValueDrawer : OdinValueDrawer<DrawerTestValue>
{
private int colorFieldWidth = 30;
protected override void DrawPropertyLayout(GUIContent label)
{
Rect rect = EditorGUILayout.GetControlRect();
DrawerTestValue value = this.ValueEntry.SmartValue;
if (label != null)
{
rect = EditorGUI.PrefixLabel(rect, label);
}
var dropDownRect = rect.AlignLeft(rect.width - colorFieldWidth - 10);
var returnList = GenericSelector<string>.DrawSelectorDropdown(dropDownRect, value.testValue, this.ShowSelector);
if (returnList != null)
{
value.testValue = returnList.FirstOrDefault();
}
this.ValueEntry.SmartValue = value;
UnityEditor.EditorApplication.QueuePlayerLoopUpdate();
ValueEntry.ApplyChanges();
}
private List<string> TestValues = new List<string>()
{
"A","B", "C", "D", "E",
};
private OdinSelector<string> ShowSelector(Rect rect)
{
DrawerTestValue value = this.ValueEntry.SmartValue;
GenericSelector<string> selector = new GenericSelector<string>("", false, x => x, TestValues);
selector.SetSelection(value.testValue);
selector.SelectionTree.Config.DrawSearchToolbar = false;
selector.EnableSingleClickToSelect();
selector.SelectionTree.DefaultMenuStyle.Height = 22;
var window = selector.ShowInPopup(rect);
return selector;
}
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment