Ejemplo n.º 1
0
        void Setup()
        {
            IMColorUtil.RGBToHSV(_color, out h, out s, out v);

            circle            = Resources.Load <Texture2D>("imCircle");
            rightArrow        = Resources.Load <Texture2D>("imRight");
            leftArrow         = Resources.Load <Texture2D>("imLeft");
            button            = Resources.Load <Texture2D>("imBorder");
            buttonHighlighted = Resources.Load <Texture2D>("imBorderHighlighted");

            previewStyle = new GUIStyle();
            previewStyle.normal.background = Texture2D.whiteTexture;

            labelStyle          = new GUIStyle();
            labelStyle.fontSize = 12;

            hueTexture = CreateHueTexture(20, kHSVPickerSize);
            hueStyle   = new GUIStyle();
            hueStyle.normal.background = hueTexture;

            svTexture = CreateSVTexture(_color, kHSVPickerSize);
            svStyle   = new GUIStyle();
            svStyle.normal.background = svTexture;

            presetStyle = new GUIStyle();
            presetStyle.normal.background = button;

            presetHighlightedStyle = new GUIStyle();
            presetHighlightedStyle.normal.background = buttonHighlighted;
        }
Ejemplo n.º 2
0
        void UpdateSVTexture(Color c, Texture2D tex)
        {
            float h, _s, _v;

            IMColorUtil.RGBToHSV(c, out h, out _s, out _v);

            var size = tex.width;

            for (int y = 0; y < size; y++)
            {
                var v = 1f * y / size;
                for (int x = 0; x < size; x++)
                {
                    var s     = 1f * x / size;
                    var color = IMColorUtil.HSVToRGB(h, s, v);
                    tex.SetPixel(x, y, color);
                }
            }

            tex.Apply();
        }
Ejemplo n.º 3
0
        void DrawPresets(ref Color c)
        {
            const int presetSize = 16;

            GUILayout.Label("Presets", labelStyle);
            GUILayout.Space(2f);

            var tmp = GUI.backgroundColor;
            int n   = preset.Colors.Count;
            var e   = Event.current;

            for (int offset = 0, m = n / 10; offset <= m; offset++)
            {
                using (new GUILayout.HorizontalScope())
                {
                    GUILayout.Space(1f);
                    var limit = Mathf.Min(n, (offset + 1) * 10);
                    for (int i = offset * 10; i < limit; i++)
                    {
                        var color = preset.Colors[i];
                        GUI.backgroundColor = color;
                        if (GUILayout.Button(" ", (i == selectedPreset) ? presetHighlightedStyle : presetStyle, GUILayout.Width(presetSize), GUILayout.Height(presetSize)))
                        {
                            switch (e.button)
                            {
                            case 0:
                                selectedPreset = i;
                                c = color;
                                IMColorUtil.RGBToHSV(c, out h, out s, out v);
                                UpdateSVTexture(c, svTexture);
                                break;

                            case 1:
                            {
                                preset.Colors.RemoveAt(i);
                                ClearPresetSelection();
                                return;
                            }
                            break;
                            }
                        }
                        GUILayout.Space(1f);
                    }
                }
            }

            GUI.backgroundColor = tmp;
            const int buttonWidth = 67, buttonHeight = 20;

            using (new GUILayout.HorizontalScope()) {
                if (GUILayout.Button("Save", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)))
                {
                    preset.Save(c);
                    selectedPreset = preset.Colors.Count - 1;
                }
                if (selectedPreset >= 0 && GUILayout.Button("Remove", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)))
                {
                    preset.Colors.RemoveAt(selectedPreset);
                    ClearPresetSelection();
                }
            }
        }