Exemplo n.º 1
0
        public static void ShowPopup(ColorGroup baseColor, List <ColorGroup> colors, System.Action <ColorGroup> selectedColorCallback)
        {
            if (instance == null)
            {
                instance = ScriptableObject.CreateInstance <ColorGroupPopupWindow>();
            }
            instance.selectedColor         = baseColor;
            instance.colors                = colors;
            instance.selectedColorCallback = selectedColorCallback;
            Vector2 realPosition = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
            Vector2 size         = new Vector2(200f, Mathf.Min(rowHeight * maxRows, instance.MaxHeight));

            instance.position = new Rect(realPosition.x, realPosition.y, size.x, size.y);
            instance.ShowPopup();
            instance.Focus();
        }
Exemplo n.º 2
0
        private void SetupColorGroupDescendantsRList(ColorGroup cg)
        {
            if (cg == null)
            {
                return;
            }

            elementDescendantsRList = new ReorderableList(cg.descendants, typeof(ColorGroupDescendant));
            elementDescendantsRList.drawHeaderCallback = (Rect rect) =>
            {
                GUI.Label(rect, "Nested Elements");
            };
            elementDescendantsRList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                Action <ColorGroup> colorGroupSelected = (selectedCG) =>
                {
                    if (selectedCG != null)
                    {
                        cg.descendants[index].target = selectedCG.instanceId;
                        Repaint();
                    }
                };
                int colorIndex = Theme.colors.FindIndex((cg2) => cg.descendants[index].target.Value == cg2.instanceId.Value);
                rect.width -= 20;
                if (colorIndex == -1)
                {
                    if (GUI.Button(rect, "Select an Element"))
                    {
                        elementDescendantsRList.index = index;
                        ColorGroupPopupWindow.ShowPopup(null, Theme.colors, colorGroupSelected);
                    }
                }
                else
                {
                    ColorGroup child = Theme.colors[colorIndex];
                    DrawColorGroupHorizontal(rect, child, () =>
                    {
                        elementDescendantsRList.index = index;
                        ColorGroupPopupWindow.ShowPopup(child, Theme.colors, colorGroupSelected);
                    });
                }
            };
            elementDescendantsRList.onAddCallback = (ReorderableList r) =>
            {
                cg.descendants.Add(new ColorGroupDescendant(new SerializableGuid()));
            };
        }