Example #1
0
        void OnGUI()
        {
            if (this.presetList == null)
            {
                this.ReloadPreset();
            }
            if (this.reorderableList == null)
            {
                this.RebuildList();
            }
            if (this.saveIconTexture == null)
            {
                this.saveIconTexture = DataLoader.LoadSaveIconTexrture();
            }
            if (this.resetIconTexture == null)
            {
                this.resetIconTexture = DataLoader.LoadResetIconTexrture();
            }

            if (this.buttonStyle == null)
            {
                this.buttonStyle = new GUIStyle(GUI.skin.button);
                this.buttonStyle.normal.background = Texture2D.whiteTexture;
            }

            if (this.buttonLabelStyle == null)
            {
                this.buttonLabelStyle = new GUIStyle(GUI.skin.label);
                this.buttonLabelStyle.normal.textColor = Color.white;
                this.buttonLabelStyle.fontStyle        = FontStyle.Bold;
                this.buttonLabelStyle.alignment        = TextAnchor.MiddleCenter;
            }

            GUILayout.Space(3f);

            EditorGUI.BeginDisabledGroup(!this.isChanged);
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (ButtonWithIcon("Reset", this.resetIconTexture, Red))
            {
                this.ReloadPreset();
                this.RebuildList();
                this.isChanged = false;
            }

            GUILayout.Space(2f);
            if (ButtonWithIcon("Save", this.saveIconTexture, Green))
            {
                ColorDatabase.SetList(this.presetList);
                this.isChanged = false;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            GUILayout.Space(2f);
            this.reorderableList.DoLayoutList();
        }
        /// <summary>
        /// Addボタンの表示
        /// </summary>
        void ButtonAdd()
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Add to Presets"))
            {
                // プリセットへ追加
                ColorDatabase.Add(this.dataName, this.colorArray);

                // ウィンドウを開く
                ColorWindow.Open();
            }
            EditorGUILayout.EndHorizontal();
        }
Example #3
0
        void RebuildList()
        {
            this.reorderableList = new ReorderableList(this.presetList.List, typeof(ColorPreset));

            // フッターは非表示にする
            this.reorderableList.displayAdd    = false;
            this.reorderableList.displayRemove = false;

            // ヘッダー表示
            this.reorderableList.drawHeaderCallback = (rect) =>
            {
                EditorGUI.LabelField(rect, "Presets");
            };

            this.reorderableList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                EditorGUI.BeginChangeCheck();
                var preset = this.presetList.List[index];
                rect.y      += 2f;
                rect.height -= 5f;

                // 名前表示
                var nameRect = new Rect(rect);
                nameRect.x     += MarginLeft;
                nameRect.width -= ColorFieldWidth + Space + RemoveButtonWidth + MarginLeft;
                preset.Name     = EditorGUI.TextField(nameRect, preset.Name);

                // 色の表示
                EditorGUILayout.BeginHorizontal();
                var colorRect = new Rect(rect);
                colorRect.width = ColorFieldWidth;
                colorRect.x     = rect.x + rect.width - ColorFieldWidth - RemoveButtonWidth;
                if (preset.ColorArray != null)
                {
                    colorRect.width /= preset.ColorArray.Length;
                    for (int i = 0; i < preset.ColorArray.Length; i++)
                    {
                        preset.ColorArray[i] = EditorGUI.ColorField(
                            position: colorRect,
                            label: new GUIContent(""),
                            value: preset.ColorArray[i],
                            showEyedropper: false,
                            showAlpha: false,
                            hdr: false,
                            hdrConfig: null
                            );
                        colorRect.x += colorRect.width;
                    }
                }
                EditorGUILayout.EndHorizontal();

                if (EditorGUI.EndChangeCheck())
                {
                    this.isChanged = true;
                }

                // Removeボタン表示
                var defaultColor     = GUI.backgroundColor;
                var removeButtonRect = new Rect(rect);
                removeButtonRect.x     = colorRect.x + 4f;
                removeButtonRect.width = RemoveButtonWidth - 4f;
                GUI.backgroundColor    = Orange;
                var removeButtonStyle = new GUIStyle(EditorStyles.miniButton);
                removeButtonStyle.normal.textColor = Color.white;
                removeButtonStyle.fontStyle        = FontStyle.Bold;
                if (GUI.Button(removeButtonRect, "", removeButtonStyle))
                {
                    ColorDatabase.RemoveAt(index);
                }
                GUI.backgroundColor = defaultColor;

                // ボタンラベル表示
                var removeIconTexture = DataLoader.LoadRemoveIconTexture();
                var textureRect       = new Rect();
                textureRect.x      = removeButtonRect.x + removeButtonRect.width / 2f - removeIconTexture.width / 2f;
                textureRect.y      = removeButtonRect.y + removeButtonRect.height / 2f - removeIconTexture.height / 2f;
                textureRect.width  = removeIconTexture.width;
                textureRect.height = removeIconTexture.height;
                GUI.DrawTexture(textureRect, removeIconTexture);
            };

            this.reorderableList.onRemoveCallback += (list) =>
            {
                ColorDatabase.RemoveAt(list.index);
            };
        }
Example #4
0
 void ReloadPreset()
 {
     this.presetList = ColorDatabase.GetList();
 }