コード例 #1
0
        private void DrawPalette(ptPalette palette)
        {
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Label("Palette:");
            rows = EditorGUILayout.IntSlider(rows, 1, 50);

            scrollPos = GUILayout.BeginScrollView(scrollPos, true, false);

            int end_count = 0;
            int r_counter = rows + 1;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical(GUILayout.Width(50 * rows));
            for (int i = 0; i < palette.colors.Count; i++)
            {
                r_counter++;
                if (r_counter > rows)
                {
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical();
                    r_counter = 0;
                    end_count++;
                }

                GUI.color = palette.colors[i];
                GUILayout.Box(paletteElement);
                if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown)
                {
                    palette.colors.RemoveAt(i);
                    i--;
                    Repaint();
                }
            }
            GUI.color = Color.white;

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
            GUILayout.EndScrollView();
            if (GUILayout.Button("Remove duplicates"))
            {
                palette.colors = palette.colors.Distinct().ToList();
            }
            if (GUILayout.Button("Sort by brightness"))
            {
                ptColorUtils.SortByBrightness(palette.colors);
            }
            if (GUILayout.Button("Sort by saturation"))
            {
                ptColorUtils.SortBySaturation(palette.colors);
            }
            if (GUILayout.Button("Sort by hue"))
            {
                ptColorUtils.SortByHue(palette.colors);
            }

            GUILayout.EndVertical();
        }
コード例 #2
0
        private void DrawColorPicker(ptPalette palette)
        {
            GUILayout.BeginVertical(EditorStyles.helpBox);
            color = EditorGUILayout.ColorField("Color:", color);
            GUILayout.BeginHorizontal();
            GUILayout.Box(colorBox, GUILayout.Width(100), GUILayout.Height(100));

            if (Event.current.type == EventType.MouseDrag || Event.current.type == EventType.MouseDown)
            {
                if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
                {
                    var pickerRect = GUILayoutUtility.GetLastRect();
                    var gui        = Event.current.mousePosition;

                    Xpicker = Mathf.Abs((pickerRect.x - gui.x) / pickerRect.width);
                    Ypicker = Mathf.Abs((pickerRect.y - gui.y) / pickerRect.height);

                    UpdateColor();

                    Repaint();
                }
            }

            GUILayout.BeginVertical();

            if (GUILayout.Button(isRGB ? "RGB" : "HSV"))
            {
                isRGB = !isRGB;
            }

            if (isRGB)
            {
                color.r = EditorGUILayout.Slider(color.r, 0f, 1f);
                color.g = EditorGUILayout.Slider(color.g, 0f, 1f);
                color.b = EditorGUILayout.Slider(color.b, 0f, 1f);
                color.a = EditorGUILayout.Slider(color.a, 0f, 1f);
            }
            else
            {
                var hsv = color.toHSV();
                hsv.h = EditorGUILayout.Slider(hsv.h, 0f, 1f);
                hsv.s = EditorGUILayout.Slider(hsv.s, 0f, 1f);
                hsv.v = EditorGUILayout.Slider(hsv.v, 0f, 1f);
                color = hsv.toRGB();
            }

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            if (GUILayout.Button("Add"))
            {
                palette.colors.Add(color);
            }
            GUILayout.EndVertical();
        }
コード例 #3
0
        private void OnInspectorGUI_Paint(ptTilemap tmp)
        {
            if (paletteElement == null)
            {
                paletteElement = new Texture2D(50, 20);
                var colors = new Color[paletteElement.width * paletteElement.height];
                for (int i = 0; i < colors.Length; i++)
                {
                    colors[i] = Color.white;
                }
                paletteElement.SetPixels(colors);
                paletteElement.Apply();
            }
            GUILayout.Label("Paint:");
            EditorGUILayout.Space();

            UpdateColorBox();

            showHelp = EditorGUILayout.Foldout(showHelp, "Help");
            if (showHelp)
            {
                GUILayout.Label("RMB - place pixel \nRMB+Shift - erase pixel \nRMB+Control - pick color");
            }
            EditorGUILayout.Space();

            DrawColorPicker(tmp);

            EditorGUILayout.Space();
            showHistoryPalette = EditorGUILayout.Foldout(showHistoryPalette, "History of colors");
            if (showHistoryPalette)
            {
                historyScrollPos = GUILayout.BeginScrollView(historyScrollPos, true, false, GUILayout.Height(50));
                GUILayout.BeginHorizontal();

                for (int i = history.Count - 1; i >= 0; i--)
                {
                    GUI.color = history[i];
                    GUILayout.Box(paletteElement);
                    if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown)
                    {
                        color = history[i];
                        Repaint();
                    }
                }
                GUI.color = Color.white;
                GUILayout.EndHorizontal();
                GUILayout.EndScrollView();
                if (GUILayout.Button("Clear"))
                {
                    history.Clear();
                }
            }

            EditorGUILayout.Space();
            showCustomPalette = EditorGUILayout.Foldout(showCustomPalette, "Custom palette");
            if (showCustomPalette)
            {
                palette = (ptPalette)EditorGUILayout.ObjectField("palette:", palette, typeof(ptPalette), false);

                if (palette != null)
                {
                    DrawCustomPalette();
                }
            }

            EditorGUILayout.Space();
            showTilemapPalette = EditorGUILayout.Foldout(showTilemapPalette, "Tilemap pallete");
            if (showTilemapPalette)
            {
                tmpPaletteRows      = EditorGUILayout.IntSlider(tmpPaletteRows, 1, 50);
                tmpPalleteScrollPos = GUILayout.BeginScrollView(tmpPalleteScrollPos, true, false);
                int end_count = 0;
                int r_counter = tmpPaletteRows + 1;
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.BeginVertical(GUILayout.Width(50 * tmpPaletteRows));
                for (int i = 0; i < tmp.Palette.Length; i++)
                {
                    r_counter++;
                    if (r_counter > tmpPaletteRows)
                    {
                        EditorGUILayout.EndVertical();
                        EditorGUILayout.BeginVertical();
                        r_counter = 0;
                        end_count++;
                    }

                    GUI.color = tmp.Palette[i];
                    GUILayout.Box(paletteElement);
                    if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown)
                    {
                        color = tmp.Palette[i];
                        Repaint();
                    }
                }
                GUI.color = Color.white;



                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
                GUILayout.EndScrollView();
            }
        }