Created
July 8, 2020 08:45
-
-
Save MrMMatricks/716651b46887cc0f965519b18bacf81a to your computer and use it in GitHub Desktop.
DrawerTestValue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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