static void ImportASEFolderIntoOne() { var path = EditorUtility.OpenFolderPanel("Swatchy Import Folder", "", ""); if (path != null && path != string.Empty) { var files = Directory.GetFiles(path); Swatch parentSwatch = null; for (int i = 0; i < files.Length; i++) { string file = files[i]; if (file.EndsWith(".ase")) { SwatchASEFile aseFile = new SwatchASEFile(file); if (parentSwatch == null) { parentSwatch = CreateSwatchFromASEFile(aseFile, GetSelectedSavePath(aseFile.title)); } else { parentSwatch.AddColorsFromASEFile(aseFile); } } } } }
static void ImportASEFileBrowse() { var path = EditorUtility.OpenFilePanel("Swatchy Import", "", "ase"); if (path != null && path != string.Empty) { SwatchASEFile aseFile = new SwatchASEFile(path); CreateSwatchFromASEFile(aseFile, GetSelectedSavePath(aseFile.title)); } }
static void ImportSelectedASEFile() { var activeObject = Selection.activeObject; var path = AssetDatabase.GetAssetPath(activeObject.GetInstanceID()); var fullPath = path.Replace("Assets", Application.dataPath); var saveDestination = path.Replace(".ase", ".asset"); var aseFile = new SwatchASEFile(fullPath); CreateSwatchFromASEFile(aseFile, saveDestination); }
public static Swatch FromSwatchASEFile(SwatchASEFile file) { var swatchScriptableObject = ScriptableObject.CreateInstance <Swatch>(); swatchScriptableObject.colors = new Color[file.colors.Count]; for (int i = 0; i < swatchScriptableObject.colors.Length; i++) { swatchScriptableObject.colors[i] = new Color(file.colors[i].r, file.colors[i].g, file.colors[i].b); } return(swatchScriptableObject); }
public static Swatch CreateSwatchFromASEFile(SwatchASEFile aseFile, string projectSaveDestination) { Swatch swatch = Swatch.FromSwatchASEFile(aseFile); projectSaveDestination = AssetDatabase.GenerateUniqueAssetPath(projectSaveDestination); AssetDatabase.CreateAsset(swatch, projectSaveDestination); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = swatch; return(swatch); }
public void AddColorsFromASEFile(SwatchASEFile file) { int i = this.colors.Length; Array.Resize <Color>(ref this.colors, this.colors.Length + file.colors.Count); var iterator = file.colors.GetEnumerator(); while (iterator.MoveNext()) { var fileColor = iterator.Current; this.colors[i++] = new Color(fileColor.r, fileColor.g, fileColor.b); } }
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); } }