Пример #1
0
        public static Enum DrawMask(this Enum current, Rect area, UnityLabel label = null, GUIStyle style = null, bool indention = true)
        {
            style = style ?? EditorStyles.popup;
            string value     = current.ToName().Replace(" ", " | ").ToTitleCase();
            Rect   valueArea = area;

            if (!label.IsNull())
            {
                Rect labelArea = area.AddWidth(-EditorGUIUtility.labelWidth);
                valueArea = labelArea.AddX(EditorGUIUtility.labelWidth);
                if (value.IsEmpty())
                {
                    value = "None";
                }
                label.DrawLabel(labelArea, null, true);
            }
            if (GUI.Button(valueArea, value.Trim("| "), style))
            {
                var items = current.ToName().Split(" ").ToTitleCase();
                GenericMenu.MenuFunction2 callback = index => {
                    EditorGUIExtensionSpecial.menuArea  = area;
                    EditorGUIExtensionSpecial.menuValue = current.GetValues().GetValue((int)index);
                };
                current.GetNames().ToTitleCase().DrawMenu(valueArea, callback, items);
            }
            if (EditorGUIExtensionSpecial.menuArea == area && !EditorGUIExtensionSpecial.menuValue.IsNull())
            {
                var menuValue = (Enum)EditorGUIExtensionSpecial.menuValue;
                var newValue  = current.ToInt() ^ menuValue.ToInt();
                current = (Enum)Enum.ToObject(current.GetType(), newValue);
                EditorGUIExtensionSpecial.menuValue = null;
                EditorGUIExtensionSpecial.menuArea  = new Rect();
                GUI.changed = true;
            }
            return(current);
        }
Пример #2
0
 public static Rect AddSize(this Rect current, float width, float height)
 {
     return(current.AddWidth(width).AddHeight(height));
 }