Showing posts with label Drop down. Show all posts
Showing posts with label Drop down. Show all posts

Thursday, November 13, 2014

Custom Object Popup list drop down menu combo box - Unity3D

EditorGUILayout.Popup EditorGUILayout.IntPopup,FloatPopup...
No selection event, no generic objects, no way to format button appearance, no way to set separator or disable items...

public class EditorGUILayoutEx
  {

    private static object _CustomPopup_SelectedObject;
    private static int _CustomPopup_ControlID = -1;
    private static int _CustomPopup_SelectedIndex = -1;

    public delegate void MenuCallaback <T> (int selectedIndex,T SelectedObject,int controlID);

    public delegate void EventCallback (int ownerControlID,Event e);

Use like this (returning Index or Generic Object with Arrays or Lists as values):


int selectedIndex;
selectedIndex=ws.winx.editor.extensions.EditorGUILayoutEx.CustomPopup(new GUIContent("State1"),selectedIndex,new GUIContent[]{new GUIContent("mile1*"),new GUIContent("mile1/kitic")},new int[]{22,33},onMenuSelectionIndex);

String selectedObject2;
selectedObject2=ws.winx.editor.extensions.EditorGUILayoutEx.CustomObjectPopup(new GUIContent("State1"),selectedObject2,new GUIContent[]{new GUIContent("mile"),new GUIContent("mile/kitic")},new List(){ "One", "Two" },onMenuSelectionObject);

String selectedObject3;
selectedObject3=ws.winx.editor.extensions.EditorGUILayoutEx.CustomObjectPopup(new GUIContent("State1"),selectedObject3,new GUIContent[]{new GUIContent("mile"),new GUIContent("mile/kitic")},new string[]{"mile","kitic"},onMenuSelectionObject);

MyClass selectedObject3;
selectedObject3=ws.winx.editor.extensions.EditorGUILayoutEx.CustomObjectPopup(new GUIContent("State1"),selectedObject3,new GUIContent[]{new GUIContent("mile"),new GUIContent("mile/kitic")},new MyClass[]{new MyClass,new MyClass},onMenuSelectionMyClass);
     
Handle events:
 void onMenuSelectionObject (int si,string obj,int cid) {
   Debug.Log ("Selected at inx: " + si+" selection="+obj+" cid:"+cid);
  }


  void onMenuSelectionIndex (int si,int obj,int cid) {
   Debug.Log ("Selected at inx: " + si+" selection="+obj+" cid:"+cid);
  }

void onMenuSelectionMyClass (int si,MyClass obj,int cid) {
   Debug.Log ("Selected at inx: " + si+" selection="+obj+" cid:"+cid);
  }