diff --git a/Assets/kode80/UnityTools/GUIWrapper/Editor/GUIPopup.cs b/Assets/kode80/UnityTools/GUIWrapper/Editor/GUIPopup.cs index cb01448..6c40786 100644 --- a/Assets/kode80/UnityTools/GUIWrapper/Editor/GUIPopup.cs +++ b/Assets/kode80/UnityTools/GUIWrapper/Editor/GUIPopup.cs @@ -69,4 +69,44 @@ protected override void CustomOnGUI () } } } + + public class GUIPopup : GUIBase + { + public T value; + int indexValue = -1; + T[] displayedOptions; + string[] optionsNames; + + private GUIContent _content; + public GUIContent content { get { return _content; } } + + public GUIPopup( GUIContent content, T[] options, int indexVal, OnGUIAction action = null ) + { + _content = content; + this.value = options[indexVal]; + indexValue = indexVal; + displayedOptions = options; + optionsNames = new string[displayedOptions.Length]; + for( int i = 0; i < displayedOptions.Length; ++i ) + { + optionsNames[i] = displayedOptions[i].ToString(); + } + + if( action != null ) + { + onGUIAction += action; + } + } + + protected override void CustomOnGUI() + { + int newValue = EditorGUILayout.Popup( content.text, indexValue, optionsNames ); + if( newValue != indexValue ) + { + indexValue = newValue; + value = displayedOptions[indexValue]; + CallGUIAction(); + } + } + } }