Beispiel #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);
            }
        }
Beispiel #2
0
        bool SaveAsNewPalette(CSPalette palette)
        {
            string basePath = GetExportsPath("Palettes");
            string path     = basePath + "/Palette.asset";
            int    counter  = 2;

            while (File.Exists(path))
            {
                path = basePath + "/Palette" + counter + ".asset";
                counter++;
            }
            otherPalette = Instantiate <CSPalette>(palette);
            AssetDatabase.DeleteAsset(path);
            AssetDatabase.CreateAsset(otherPalette, path);
            EditorGUIUtility.PingObject(otherPalette);
            UpdateCWMaterial();
            palette.UpdateMaterial();
            return(true);
        }
Beispiel #3
0
 private void OnEnable()
 {
     palette = (CSPalette)target;
     palette.UpdateMaterial();
 }
Beispiel #4
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();
                    }
                }
            }
        }