Пример #1
0
 private void SetupColorRList()
 {
     elementsRList = new ReorderableList(Theme.colors, typeof(ColorGroup), true, true, true, true);
     elementsRList.elementHeight       = 40f;
     elementsRList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
     {
         if (index == -1 && Theme.colors.Count > 0 || Theme.colors.Count == 0)
         {
             return;
         }
         rect.y      += 4;
         rect.height -= 8;
         DrawColorGroup(rect, Theme.colors[index], () =>
         {
             if (EditMode)
             {
                 elementsRList.index = index;
                 elementsRList.onSelectCallback.Invoke(elementsRList);
             }
             else
             {
                 AssignColorGroup(Theme.colors[index]);
             }
         });
     };
     elementsRList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Elements"); };
     elementsRList.onAddCallback      = (ReorderableList list) =>
     {
         ColorGroup cg = new ColorGroup("New Element");
         cg.Add(new NamedColor("Normal", Color.white));
         cg.Add(new NamedColor("Highlighted", Color.white));
         cg.Add(new NamedColor("Pressed", Color.gray));
         cg.Add(new NamedColor("Disabled", Color.gray));
         Undo.RecordObject(Theme, "Element Added");
         Theme.colors.Add(cg);
         UpdateColorNames();
     };
     elementsRList.onRemoveCallback = (ReorderableList list) =>
     {
         Theme.colors.RemoveAt(list.index);
         SelectedCG = null;
         list.index = -1;
         UpdateColorNames();
     };
     elementsRList.onSelectCallback = (ReorderableList list) =>
     {
         SelectedCG = Theme.colors[list.index];
         GUI.FocusControl(null);
         UpdateColorNames();
     };
     elementsRList.onReorderCallback = (ReorderableList list) =>
     {
         UpdateColorNames();
     };
 }
Пример #2
0
        private void SetupColorGroupRList(ColorGroup cg)
        {
            if (cg == null)
            {
                return;
            }

            colorsList = new ReorderableList(cg.colorList, typeof(NamedColor), true, true, true, true);

            colorsList.drawHeaderCallback = (Rect rect) =>
            {
                GUI.Label(rect, "Colors");
            };

            colorsList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                rect.width *= 0.5f;
                NamedColor nc   = cg[index];
                string     name = EditorGUI.TextField(rect, nc.Name);
                if (name != nc.Name)
                {
                    nc.Name = name;
                }
                rect.x     += rect.width + 5;
                rect.width -= 35f;
                nc.color    = EditorGUI.ColorField(rect, nc.color);
                rect.x     += rect.width + 5;
                rect.y     -= 2;
                rect.width  = 30f;
                if (GUI.Button(rect, StylesUI.PaletteButton, StylesUI.IconPalette))
                {
                    ColorHelperPopupWindow.ShowPopup(nc.color, (c) => { nc.color = c; this.Repaint(); });
                }
            };
            colorsList.elementHeight = 16f;
            colorsList.onAddCallback = (ReorderableList r) =>
            {
                if (cg.Count > 0)
                {
                    cg.Add(new NamedColor(cg[cg.Count - 1]));
                }
                else
                {
                    cg.Add(new NamedColor("New", Color.white));
                }
            };
        }
Пример #3
0
        private void UpdateColors(ColorGroup cg)
        {
            Dictionary <string, NamedColor> old = new Dictionary <string, NamedColor>();

            for (int i = 0; i < cg.Count; i++)
            {
                NamedColor nc = cg[i];
                if (old.ContainsKey(nc.Name))
                {
                    continue;
                }
                old.Add(nc.Name, nc);
            }
            EUIType type = cg.uiMask;

            // Private checker for adding new keys to color List
            Action <string> CheckColor = (k) =>
            {
                if (old.ContainsKey(k))
                {
                    if (!cg.Contains(old[k]))
                    {
                        cg.Add(old[k]);
                    }
                }
                else
                {
                    cg.Add(new NamedColor(k, Color.white));
                }
            };

            Action <string> RemoveColor = (k) =>
            {
                if (old.ContainsKey(k) && cg.Contains(old[k]))
                {
                    cg.Remove(old[k]);
                }
            };

            if (((EUIType.Text | EUIType.RawImage | EUIType.Image) & type) == 0)
            {
                RemoveColor(UIVars.Color);
            }
            else
            {
                CheckColor(UIVars.Color);
            }

            if (((EUIType.Selectable | EUIType.Button | EUIType.Toggle) & type) == 0)
            {
                RemoveColor(UIVars.Normal);
                RemoveColor(UIVars.Highlighted);
                RemoveColor(UIVars.Pressed);
                RemoveColor(UIVars.Disabled);
            }
            else
            {
                CheckColor(UIVars.Normal);
                CheckColor(UIVars.Highlighted);
                CheckColor(UIVars.Pressed);
                CheckColor(UIVars.Disabled);
            }
        }