Exemplo n.º 1
0
        public static void EnumPopup <T>(GUIContent label, T selected, Action <T> callback) where T : System.Enum
        {
            label.text += ": " + selected.ToString();
            Rect buttonRect = GUILayoutUtility.GetRect(label, new GUIStyle(GUI.skin.button));

            if (GUI.Button(buttonRect, label))
            {
                PopupMenu menu   = new PopupMenu();
                T[]       values = (T[])Enum.GetValues(selected.GetType());
                Array.ForEach(values, e => { menu.AddItem(new GUIContent(Enum.GetName(selected.GetType(), e)), true, () => callback(e)); });

                Vector2 buttonPos = Event.current.mousePosition;           //new Vector2(buttonRect.x, buttonRect.y + buttonRect.height);
                buttonPos -= NodeEditor.curEditorState.zoomPanAdjust;
                buttonPos /= NodeEditor.curEditorState.zoom;
                buttonPos += NodeEditor.curEditorState.zoomPanAdjust;

                //buttonPos = GUIScaleUtility.ScaledToGUISpace(buttonPos);
                buttonPos = GUIUtility.GUIToScreenPoint(buttonPos);
                Debug.Log(buttonPos);
                menu.Show(new Vector2(buttonPos.x + 1, buttonPos.y + 1), buttonRect.width);
            }
        }
Exemplo n.º 2
0
        public static T EnumPopup <T> (GUIContent label, T selected) where T : System.Enum
        {
            T oldSelected = selected;

                        #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return((T)UnityEditor.EditorGUILayout.EnumPopup(label, selected));
            }
                        #endif
            label.text += ": " + selected.ToString();
            GUILayout.Label(label);

            Rect buttonRect = GUILayoutUtility.GetRect(label, new GUIStyle(GUI.skin.button));
            if (GUI.Button(buttonRect, label))
            {
                PopupMenu menu   = new PopupMenu();
                T[]       values = (T[])Enum.GetValues(selected.GetType());
                Array.ForEach(values, e => { menu.AddItem(new GUIContent(Enum.GetName(selected.GetType(), e)), true, () => { Debug.Log("executing handler"); selected = e; }); });

                Vector2 mousePos = GUIUtility.GUIToScreenPoint(new Vector2(buttonRect.x, buttonRect.y + buttonRect.height));
                Debug.Log(mousePos);
                Debug.Log("showing Menu");
                menu.Show(new Vector2(mousePos.x + 1, mousePos.y + 1), buttonRect.width);
            }
            if (Event.current.type == EventType.MouseDown)
            {
                Debug.Log("MouseDown");
            }
            //buttonRect = GUILayoutUtility.GetLastRect();
            if (!Object.Equals(oldSelected, selected))
            {
                Debug.Log("changing selected");
                Debug.Log(oldSelected);
                Debug.Log(selected);
            }
            return(selected);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Opens the specified popupMenu in the current editor users and closes all other popups
 /// </summary>
 public static void OpenPopup(PopupMenu popup)
 {
     openedPopup     = popup;
     openedPopupUser = currentEditorUser;
 }
Exemplo n.º 4
0
 public GenericMenu()
 {
     popup = new PopupMenu();
 }
Exemplo n.º 5
0
		public void AddItem (GUIContent content, bool on, PopupMenu.MenuFunction func)
		{
			popup.AddItem (content, on, func);
		}
Exemplo n.º 6
0
		public void AddItem (GUIContent content, bool on, PopupMenu.MenuFunctionData func, object userData)
		{
			popup.AddItem (content, on, func, userData);
		}
Exemplo n.º 7
0
		public GenericMenu () 
		{
			popup = new PopupMenu ();
		}