예제 #1
0
        public override void OnInspectorGUI()
        {
            Swatch swatch = (Swatch)target;

            EditorGUI.BeginChangeCheck();
            base.OnInspectorGUI();
            if (EditorGUI.EndChangeCheck())
            {
                swatch.SignalChange();
                SwatchEditorGUI.GameViewRepaint();
            }

            if (GUILayout.Button("Add .ASE"))
            {
                var path = EditorUtility.OpenFilePanel("Swatchy Import", "", "ase");
                if (path != null && path != string.Empty)
                {
                    Debug.Log("[SwatchEditorGUI] path " + path);
                    SwatchASEFile aseFile = new SwatchASEFile(path);
                    swatch.AddColorsFromASEFile(aseFile);
                }
            }

            if (GUILayout.Button("Add .ASE Folder"))
            {
                var path = EditorUtility.OpenFolderPanel("Swatchy Folder Import", "", "");
                //var path = EditorUtility.OpenFilePanel("Import", "", "ase");
                if (path != null && path != string.Empty)
                {
                    var files = Directory.GetFiles(path);
                    for (int i = 0; i < files.Length; i++)
                    {
                        string file = files[i];
                        if (file.EndsWith(".ase"))
                        {
                            SwatchASEFile aseFile = new SwatchASEFile(file);
                            swatch.AddColorsFromASEFile(aseFile);
                        }
                    }
                }
            }

            if (GUILayout.Button(replace ? "Cancel Replace" : "Replace With Another Swatch"))
            {
                replace = !replace;
                if (replace)
                {
                    LoadOtherSwatches();
                }
            }

            if (replace)
            {
                if (otherSwatchGUIDs != null && otherSwatchFilenames != null)
                {
                    var lastRect = GUILayoutUtility.GetLastRect();
                    var indent   = 50;
                    lastRect.x     += indent;
                    lastRect.width -= indent;
                    var spacing = 3;
                    GUILayout.Space((EditorGUIUtility.singleLineHeight + spacing) * otherSwatchGUIDs.Length);
                    for (int i = 0; i < otherSwatchGUIDs.Length; i++)
                    {
                        var swatchName = otherSwatchFilenames[i];

                        var buttonRect = new Rect(lastRect.x, lastRect.y + EditorGUIUtility.singleLineHeight + spacing, lastRect.width, EditorGUIUtility.singleLineHeight);
                        lastRect = buttonRect;
                        if (GUI.Button(buttonRect, swatchName))
                        {
                            var otherSwatchAssetPath = AssetDatabase.GUIDToAssetPath(otherSwatchGUIDs[i]);
                            var otherSwatch          = AssetDatabase.LoadAssetAtPath <Swatch>(otherSwatchAssetPath);
                            if (otherSwatch != null)
                            {
                                swatch.ReplaceSelfWithOtherSwatch(otherSwatch);
                                SwatchEditorGUI.GameViewRepaint();
                            }
                            else
                            {
                                Debug.LogError("[SwatchEditorGUI] couldnt load asset at path: " + otherSwatchAssetPath);
                            }
                            break;
                        }
                    }
                }
            }


            if (GUILayout.Button(merge ? "Cancel Merge" : "Merge With Another Swatch"))
            {
                mergeObject = null;
                merge       = !merge;
            }
            if (merge)
            {
                mergeObject = (Swatch)EditorGUILayout.ObjectField(mergeObject, typeof(Swatch), false);
                if (mergeObject != null)
                {
                    if (GUILayout.Button("Merge"))
                    {
                        swatch.AddColorsFromOtherSwatch(mergeObject);
                        mergeObject = null;
                        merge       = false;
                    }
                }
            }



            if (GUILayout.Button("Export To Color Picker Presets"))
            {
                SwatchPresetExporter.ExportToColorPresetLibrary(swatch);
            }
        }
예제 #2
0
 void UpdateActiveSwatch(Color color)
 {
     swatchTexture.SetPixel(0, 0, color);
     swatchTexture.Apply();
     SwatchEditorGUI.GameViewRepaint();
 }