Ejemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            if (palette == null)
            {
                return;
            }

            if (palette.material == null || palette.material.GetColorArray("_Colors") == null)
            {
                palette.UpdateMaterial();
            }

            EditorGUILayout.BeginVertical(GUI.skin.box);

            Rect  space = EditorGUILayout.BeginVertical();
            float paletteRowSize;

            paletteRowSize = 64;
            GUILayout.Space(paletteRowSize);
            EditorGUILayout.EndVertical();

            palette.material.SetVector("_CursorPos", Vector3.left);
            EditorGUI.DrawPreviewTexture(space, Texture2D.whiteTexture, palette.material);

            EditorGUILayout.EndVertical();

            if (GUILayout.Button("Open in Color Studio"))
            {
                CSWindow cs = CSWindow.ShowWindow();
                cs.LoadPalette(palette);
            }
        }
Ejemplo n.º 2
0
        void DrawTopRowButtons()
        {
            EditorGUILayout.BeginVertical();

            Rect  space = EditorGUILayout.BeginHorizontal();
            float width = EditorGUIUtility.currentViewWidth;

            const int w = 32;
            const int h = 32;

            EditorGUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Label("New");
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("4", GUILayout.Width(w), GUILayout.Height(h)))
            {
                CreateNew(4, 4);
            }
            if (GUILayout.Button("8", GUILayout.Width(w), GUILayout.Height(h)))
            {
                CreateNew(8, 8);
            }
            if (GUILayout.Button("16", GUILayout.Width(w), GUILayout.Height(h)))
            {
                CreateNew(16, 16);
            }
            if (GUILayout.Button("32", GUILayout.Width(w), GUILayout.Height(h)))
            {
                CreateNew(32, 32);
            }
            if (GUILayout.Button("64", GUILayout.Width(w), GUILayout.Height(h)))
            {
                CreateNew(64, 64);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Label("Texture");
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            texture = (Texture2D)EditorGUILayout.ObjectField(GUIContent.none, texture, typeof(Texture2D), false, GUILayout.Width(w), GUILayout.Height(h));
            if (EditorGUI.EndChangeCheck())
            {
                sprite = null;
                LoadFile();
            }
            GUI.enabled = sprite == null;
            if (GUILayout.Button(icons[ICON_SAVE_TEXTURE], GUILayout.Width(w), GUILayout.Height(h)))
            {
                SaveTexture(TextureImporterType.Default);
                EditorGUIUtility.ExitGUI();
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Label("Sprite");
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            sprite = (Sprite)EditorGUILayout.ObjectField(GUIContent.none, sprite, typeof(Sprite), false, GUILayout.Width(w), GUILayout.Height(h));
            if (EditorGUI.EndChangeCheck())
            {
                texture = null;
                LoadFile();
            }
            GUI.enabled = texture == null;
            if (GUILayout.Button(icons[ICON_SAVE_SPRITE], GUILayout.Width(w), GUILayout.Height(h)))
            {
                SaveTexture(TextureImporterType.Sprite);
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            Color prevContentColor = GUI.contentColor;

            if (!EditorGUIUtility.isProSkin)
            {
                GUI.contentColor = Color.black;
            }
            EditorGUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Label("Undo / Redo");
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(icons[ICON_UNDO], GUILayout.Width(w), GUILayout.Height(h)))
            {
                EditorApplication.delayCall += () => Undo.PerformUndo();
            }
            if (GUILayout.Button(icons[ICON_REDO], GUILayout.Width(w), GUILayout.Height(h)))
            {
                EditorApplication.delayCall += () => Undo.PerformRedo();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();


            EditorGUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Label("Brush Color");
            space         = EditorGUILayout.BeginHorizontal();
            space.xMin   += 5;
            space.yMin   += 5;
            space.height -= 5;
            space.width   = space.height;
            if (GUILayout.Button(icons[ICON_COLOR_PICKER], GUILayout.Width(w), GUILayout.Height(h)))
            {
                CSWindow.ShowWindow(1);
            }
            GUI.DrawTexture(space, brushColorTexture, ScaleMode.StretchToFill);
            if (GUILayout.Button(icons[ICON_TRANSPARENT], GUILayout.Width(w), GUILayout.Height(h)))
            {
                brushColor = new Color(0, 0, 0, 0);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GUI.skin.box);
            int mw = 32 * brushWidths.Length;

            GUILayout.Label("Brush Width", GUILayout.MaxWidth(mw));
            _brushWidth = GUILayout.SelectionGrid(_brushWidth, brushWidths, brushWidths.Length, GUILayout.MaxWidth(mw), GUILayout.Height(h));
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GUI.skin.box);
            mw = 32 * brushShapes.Length;
            GUILayout.Label("Brush Shape", GUILayout.MaxWidth(mw));
            _brushShape = GUILayout.SelectionGrid(_brushShape, brushShapes, brushShapes.Length, GUILayout.MaxWidth(mw), GUILayout.Height(h));
            EditorGUILayout.EndVertical();

            GUI.contentColor = prevContentColor;

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal(); // Row


            EditorGUILayout.EndVertical(); // top buttons
        }
Ejemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            Recolor rc = (Recolor)target;

            if (rc.GetComponent <Renderer>() == null)
            {
                EditorGUILayout.HelpBox("Recolor script requires an GameObject with a MeshRenderer or SpriteRenderer component.", MessageType.Warning);
                return;
            }

            serializedObject.Update();

            EditorGUILayout.PropertyField(this.palette);

            CSPalette palette = (CSPalette)this.palette.objectReferenceValue;

            if (palette != null)
            {
                if (palette.material == null || palette.material.GetColorArray("_Colors") == null)
                {
                    palette.UpdateMaterial();
                }

                EditorGUILayout.BeginVertical(GUI.skin.box);

                Rect space = EditorGUILayout.BeginVertical();
                GUILayout.Space(64);
                EditorGUILayout.EndVertical();

                palette.material.SetVector("_CursorPos", Vector3.left);
                EditorGUI.DrawPreviewTexture(space, Texture2D.whiteTexture, palette.material);

                if (GUILayout.Button("Open in Color Studio"))
                {
                    CSWindow cs = CSWindow.ShowWindow();
                    cs.LoadPalette(palette);
                }

                EditorGUILayout.EndVertical();

                EditorGUILayout.PropertyField(applyPalette);
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Open Color Studio"))
                {
                    CSWindow.ShowWindow();
                }
                if (GUILayout.Button("Help"))
                {
                    EditorUtility.DisplayDialog("Quick Help", "This Recolor script changes colors of the gameobject or sprite at runtime.\n\nIf you assign a palette created with Color Studio, Recolor will transform the colors of the original texture to the nearest colors of the palette.\n\nYou can also specify custom color operations, like preserving or replacing individual colors from the original texture.", "Ok");
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.PropertyField(mode, new GUIContent("Recolor Mode"));
            EditorGUILayout.PropertyField(colorMatch);
            EditorGUILayout.PropertyField(threshold, new GUIContent("Color Threshold"));
            EditorGUILayout.PropertyField(materialIndex);

            if (mode.intValue != (int)RecolorMode.MainColorOnly)
            {
                if (originalTexture == null)
                {
                    originalTexture = rc.GetOriginalTexture();
                    if (originalTexture != null)
                    {
                        originalTexture            = Instantiate <Texture2D>(originalTexture);
                        originalTexture.filterMode = FilterMode.Point;
                    }
                    originalColors = rc.GetOriginalUniqueColors();
                }

                EditorGUILayout.PropertyField(showOriginalTexture);
                if (showOriginalTexture.boolValue)
                {
                    if (originalTexture != null)
                    {
                        EditorGUILayout.BeginVertical(GUI.skin.box);

                        Rect space = EditorGUILayout.BeginVertical();
                        GUILayout.Space(128);
                        EditorGUILayout.EndVertical();

                        EditorGUI.DrawPreviewTexture(space, originalTexture);
                        EditorGUILayout.EndVertical();
                    }
                }
            }

            EditorGUILayout.Separator();
            EditorGUILayout.PropertyField(colorOperations, new GUIContent("Per Color Operations"), true);

            if (originalColors != null && originalColors.Count < 64 && GUILayout.Button("Add All Texture Colors"))
            {
                colorOperations.isExpanded = true;
                List <ColorEntry> cc = new List <ColorEntry>();
                if (rc.colorOperations != null)
                {
                    for (int k = 0; k < rc.colorOperations.Length; k++)
                    {
                        int index = originalColors.IndexOf(rc.colorOperations[k].color);
                        if (index >= 0)
                        {
                            originalColors.RemoveAt(index);
                        }
                        cc.Add(rc.colorOperations[k]);
                    }
                }
                for (int k = 0; k < originalColors.Count; k++)
                {
                    ColorEntry ce = new ColorEntry {
                        color = originalColors[k], operation = ColorOperation.Preserve, replaceColor = originalColors[k]
                    };
                    cc.Add(ce);
                }
                rc.colorOperations = cc.ToArray();
                EditorUtility.SetDirty(rc);
                serializedObject.Update();
                requireRefresh = true;
            }

            if (mode.intValue != (int)RecolorMode.MainColorOnly)
            {
                if (!rc.isSprite && originalTexture != null && GUILayout.Button("Add Main Texture Colors"))
                {
                    colorOperations.isExpanded = true;
                    List <ColorEntry> cc         = new List <ColorEntry>();
                    List <Color>      mainColors = rc.GetOriginalTextureMainColors();
                    if (mainColors != null)
                    {
                        if (rc.colorOperations != null)
                        {
                            for (int k = 0; k < rc.colorOperations.Length; k++)
                            {
                                int index = mainColors.IndexOf(rc.colorOperations[k].color);
                                if (index >= 0)
                                {
                                    mainColors.RemoveAt(index);
                                }
                                cc.Add(rc.colorOperations[k]);
                            }
                        }

                        for (int k = 0; k < mainColors.Count; k++)
                        {
                            ColorEntry ce = new ColorEntry {
                                color = mainColors[k], operation = ColorOperation.Preserve, replaceColor = mainColors[k]
                            };
                            cc.Add(ce);
                        }
                        rc.colorOperations = cc.ToArray();
                        EditorUtility.SetDirty(rc);
                        serializedObject.Update();
                        requireRefresh = true;
                    }
                }
                if (!rc.isSprite && mode.intValue == (int)RecolorMode.VertexColors && GUILayout.Button("Add Vertex Colors"))
                {
                    colorOperations.isExpanded = true;
                    List <ColorEntry> cc         = new List <ColorEntry>();
                    List <Color>      mainColors = rc.GetOriginalVertexColors();
                    if (rc.colorOperations != null)
                    {
                        for (int k = 0; k < rc.colorOperations.Length; k++)
                        {
                            int index = mainColors.IndexOf(rc.colorOperations[k].color);
                            if (index >= 0)
                            {
                                mainColors.RemoveAt(index);
                            }
                            cc.Add(rc.colorOperations[k]);
                        }
                    }

                    for (int k = 0; k < mainColors.Count; k++)
                    {
                        ColorEntry ce = new ColorEntry {
                            color = mainColors[k], operation = ColorOperation.Preserve, replaceColor = mainColors[k]
                        };
                        cc.Add(ce);
                    }
                    rc.colorOperations = cc.ToArray();
                    EditorUtility.SetDirty(rc);
                    serializedObject.Update();
                    requireRefresh = true;
                }
            }

            // Color adjustments
            EditorGUILayout.Separator();
            EditorGUILayout.PropertyField(enableColorAdjustments, new GUIContent("Color Correction"), true);
            if (enableColorAdjustments.boolValue)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(colorAdjustments, true);
                EditorGUI.indentLevel--;
            }

            CheckLUTSettings((Texture2D)lutProp.objectReferenceValue);

            if (rc.enabled)
            {
                if (GUILayout.Button("Refresh"))
                {
                    requireRefresh = false;
                    rc.Refresh();
                }
            }

            if (serializedObject.ApplyModifiedProperties() || rc.dirty || requireRefresh)
            {
                requireRefresh = true;
                rc.dirty       = false;
                if (rc.enabled)
                {
                    if (GUIUtility.hotControl == 0)
                    {
                        requireRefresh = false;
                        rc.Refresh();
                    }
                }
            }
        }
Ejemplo n.º 4
0
 static void OpenColorStudio(MenuCommand command)
 {
     CSWindow.ShowWindow();
 }