private void restoreDefaultPalettes() { if (EditorUtility.DisplayDialog("Restore default palettes", "This will remove all your current palettes!\nAre you sure you want to do this?", "Validate", "Cancel")) { m_paletteData.restoreDefaultPalettes(); PaletteUtils.SavePalettes(m_paletteData); } }
private void clearPalettes() { if (EditorUtility.DisplayDialog("Clear palettes", "This will remove ALL palettes except the first one!\nAre you sure you want to do this?", "Validate", "Cancel")) { m_paletteData.clearPalettes(); PaletteUtils.SavePalettes(m_paletteData); } }
private void importPaletteFromFile(string filePath) { if (string.IsNullOrEmpty(filePath)) { return; } string extension = Path.GetExtension(filePath); switch (extension) { case ".colors": m_paletteData.colorPaletteList.Add(ColorPresetFileImporter.Import(filePath)); break; case ".svg": m_paletteData.colorPaletteList.Add(SVGFileImporter.Import(filePath)); break; case ".ase": #if UNITY_WEBPLAYER throw new UnityException("Sorry you can't import a .ase palette if you're using WebPlayer"); #elif UNITY_SAMSUNGTV throw new UnityException("Sorry you can't import a .ase palette if you're using Samsung TV"); #else m_paletteData.colorPaletteList.Add(ASEFileImporter.Import(filePath)); break; #endif case ".gpl": m_paletteData.colorPaletteList.Add(GPLFileImporter.Import(filePath)); break; case ".aco": m_paletteData.colorPaletteList.Add(ACOFileImporter.Import(filePath)); break; default: throw new UnityException("Sorry we do not support this file type. Please contact us at [email protected] and we'll add support for whatever you want :D"); } PaletteUtils.SavePalettes(m_paletteData); }
public void init() { if (colorPaletteList != null) { foreach (ColorPalette colorPalette in colorPaletteList) { colorPalette.restoreFromOldVersion(); } PaletteUtils.SavePalettes(this); } if (colorPaletteList == null || colorPaletteList.Count == 0) { restoreDefaultPalettes(); } m_currentPaletteIndex = PlayerPrefs.GetInt(m_prefCurrentColorPaletteIndex, 0); }
private void importPaletteFromURL(string url) { EditorUtility.DisplayProgressBar("Downloading palette", url, 0.5f); Uri uri = new Uri(url); try { if (uri.Host.EndsWith("colourlovers.com")) { m_paletteData.colorPaletteList.Add(ColourLoversWebsiteImporter.Import(uri)); } else if (uri.Host.EndsWith("dribbble.com")) { m_paletteData.colorPaletteList.Add(DribbbleWebsiteImporter.Import(uri)); } else if (uri.Host.EndsWith("colorcombos.com")) { m_paletteData.colorPaletteList.Add(ColorCombosWebsiteImporter.Import(uri)); } else if (uri.Host.EndsWith("colrd.com")) { m_paletteData.colorPaletteList.Add(ColrdWebsiteImporter.Import(uri)); } else { throw new UnityException("Sorry we do not support downloading palettes from the website " + uri.Host + " for now. Please contact us at [email protected] and we'll add support for whatever you want :D"); } } catch (Exception e) { EditorUtility.ClearProgressBar(); throw new UnityException(e.Message); } PaletteUtils.SavePalettes(m_paletteData); EditorUtility.ClearProgressBar(); }
public void drawInspector() { if (m_paletteData.colorPaletteList == null || m_paletteData.colorPaletteList.Count == 0) { m_paletteData.restoreDefaultPalettes(); } for (int i = 0; i < m_paletteData.colorPaletteList.Count; i++) { ColorPalette colorPalette = m_paletteData.colorPaletteList[i]; GUI.backgroundColor = ColorPaletteData.Singleton.currentPaletteIndex == i ? Color.green : Color.white; if (GUIUtils.DrawHeader(colorPalette.name)) { GUI.backgroundColor = Color.white; GUIUtils.BeginContents(); { if (!colorPalette.showDetails) { EditorGUILayout.BeginHorizontal(); { GUILayout.Space(4f); for (int j = 0; j < colorPalette.colorInfoList.Count; j++) { ColorPaletteObjectEditor.DrawCustomSwatch(colorPalette.colorInfoList[j], 20); } } EditorGUILayout.EndHorizontal(); } else { m_colorPaletteDetailRenderer.drawInspector(colorPalette, m_paletteData); } GUILayout.Space(5f); EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button(new GUIContent("Set current", "Apply this palette to all the ColorPaletteObject objects in the current scene"), EditorStyles.miniButton, GUILayout.Width(65f))) { ColorPaletteData.Singleton.setCurrentPalette(i); GUI.FocusControl(null); } /*if (GUILayout.Button(new GUIContent("Apply to color picker", "Use this palette for the color picker"), EditorStyles.miniButton, GUILayout.Width(115f))) * { * //TODO: Add this palette to the color picker * System.Type colorPickerType = System.Type.GetType("UnityEditor.ColorPicker,UnityEditor"); * ScriptableObject colorPickerInstance = ScriptableObject.CreateInstance(colorPickerType); * * // Call the Show method of ColorPicker * System.Reflection.MethodInfo method = colorPickerType.GetMethod("Show", new System.Type[] { System.Type.GetType("UnityEditor.GUIView,UnityEditor"), typeof(Color)}); * method.Invoke(null, new object[] { null, Color.white }); * * // Set the new palette path * System.String palettePath = "Assets/PygmyMonkey/ColorPalette/Example/Editor/Color Presets/20 - Text and Detail"; //TODO: Find a way to save that as a real preset and use this new file as the path * System.Reflection.PropertyInfo property = colorPickerType.GetProperty("currentPresetLibrary"); * //Debug.Log (property.GetValue(colorPickerInstance, null)); * property.SetValue(colorPickerInstance, System.Convert.ChangeType(palettePath, property.PropertyType), null); * * GUI.FocusControl(null); * }*/ if (GUILayout.Button(new GUIContent(colorPalette.showDetails ? "Hide details" : "Show details", "Edit the palette"), EditorStyles.miniButton, GUILayout.Width(75f))) { colorPalette.showDetails = !colorPalette.showDetails; GUI.FocusControl(null); PaletteUtils.SavePalettes(m_paletteData); } EditorGUILayout.Space(); GUI.changed = false; if (GUILayout.Button(new GUIContent("+", "duplicate"), EditorStyles.miniButtonLeft, GUILayout.Width(20f))) { m_paletteData.colorPaletteList.Insert(i + 1, colorPalette.Copy()); if (m_paletteData.currentPaletteIndex > i) { m_paletteData.currentPaletteIndex++; } GUI.FocusControl(null); PaletteUtils.SavePalettes(m_paletteData); return; } GUI.enabled = i > 0; if (GUILayout.Button(new GUIContent("\u2191", "move up"), EditorStyles.miniButtonMid, GUILayout.Width(20f))) { m_paletteData.colorPaletteList.Remove(colorPalette); m_paletteData.colorPaletteList.Insert(i - 1, colorPalette); if (m_paletteData.currentPaletteIndex == i) { m_paletteData.currentPaletteIndex--; } else if (m_paletteData.currentPaletteIndex == i - 1) { m_paletteData.currentPaletteIndex++; } GUI.FocusControl(null); } GUI.enabled = true; GUI.enabled = i < m_paletteData.colorPaletteList.Count - 1; if (GUILayout.Button(new GUIContent("\u2193", "move down"), EditorStyles.miniButtonMid, GUILayout.Width(20f))) { m_paletteData.colorPaletteList.Remove(colorPalette); m_paletteData.colorPaletteList.Insert(i + 1, colorPalette); if (m_paletteData.currentPaletteIndex == i) { m_paletteData.currentPaletteIndex++; } else if (m_paletteData.currentPaletteIndex == i + 1) { m_paletteData.currentPaletteIndex--; } GUI.FocusControl(null); } GUI.enabled = true; GUI.enabled = m_paletteData.colorPaletteList.Count > 1; if (GUILayout.Button(new GUIContent("-", "delete"), EditorStyles.miniButtonRight, GUILayout.Width(20f))) { m_paletteData.colorPaletteList.Remove(colorPalette); if (m_paletteData.currentPaletteIndex > i) { m_paletteData.currentPaletteIndex--; } else if (m_paletteData.currentPaletteIndex == i) { m_paletteData.currentPaletteIndex = 0; } GUI.FocusControl(null); PaletteUtils.SavePalettes(m_paletteData); return; } GUI.enabled = true; } EditorGUILayout.EndHorizontal(); } GUIUtils.EndContents(); if (GUI.changed) { PaletteUtils.SavePalettes(m_paletteData); } } EditorGUILayout.Space(); } }
public void drawInspector(ColorPalette colorPalette, ColorPaletteData colorPaletteData) { colorPalette.name = EditorGUILayout.TextField("Palette name", colorPalette.name); EditorGUILayout.BeginVertical(); { EditorGUILayout.Space(); for (int i = 0; i < colorPalette.colorInfoList.Count; i++) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("#" + ColorUtils.ColorToHex(colorPalette.colorInfoList[i].color), GUILayout.Width(55f)); colorPalette.colorInfoList[i].name = EditorGUILayout.TextField(colorPalette.colorInfoList[i].name); colorPalette.colorInfoList[i].color = EditorGUILayout.ColorField(colorPalette.colorInfoList[i].color); GUI.changed = false; if (GUILayout.Button(new GUIContent("+", "duplicate"), EditorStyles.miniButtonLeft, GUILayout.Width(20f))) { colorPalette.colorInfoList.Insert(i + 1, colorPalette.colorInfoList[i].Copy()); GUI.FocusControl(null); PaletteUtils.SavePalettes(colorPaletteData); return; } GUI.enabled = i > 0; if (GUILayout.Button(new GUIContent("\u2191", "move up"), EditorStyles.miniButtonMid, GUILayout.Width(20f))) { ColorInfo tmpColor = colorPalette.colorInfoList[i]; colorPalette.colorInfoList.RemoveAt(i); colorPalette.colorInfoList.Insert(i - 1, tmpColor); GUI.FocusControl(null); } GUI.enabled = true; GUI.enabled = i < colorPalette.colorInfoList.Count - 1; if (GUILayout.Button(new GUIContent("\u2193", "move down"), EditorStyles.miniButtonMid, GUILayout.Width(20f))) { ColorInfo tmpColor = colorPalette.colorInfoList[i]; colorPalette.colorInfoList.RemoveAt(i); colorPalette.colorInfoList.Insert(i + 1, tmpColor); GUI.FocusControl(null); } GUI.enabled = true; GUI.enabled = colorPalette.colorInfoList.Count > 1; if (GUILayout.Button(new GUIContent("-", "delete"), EditorStyles.miniButtonRight, GUILayout.Width(20f))) { colorPalette.colorInfoList.RemoveAt(i); GUI.FocusControl(null); PaletteUtils.SavePalettes(colorPaletteData); return; } GUI.enabled = true; if (GUI.changed) { PaletteUtils.SavePalettes(colorPaletteData); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); } EditorGUILayout.EndVertical(); }
public void drawInspector() { if (GUIUtils.DrawHeader("Create palette")) { GUIUtils.BeginContents(); { EditorGUILayout.BeginHorizontal(); { m_selectedAlgorithm = (Algorithm)EditorGUILayout.EnumPopup(m_selectedAlgorithm); if (GUILayout.Button("Generate", EditorStyles.miniButton)) { GUI.FocusControl(null); generatePalette(); } } EditorGUILayout.EndHorizontal(); m_colorCount = EditorGUILayout.IntSlider("Number of colors", m_colorCount, 1, 25); if (m_selectedAlgorithm == Algorithm.RANDOM_FROM_COLOR) { m_colorReference = EditorGUILayout.ColorField("Base color", m_colorReference); m_colorOffset = EditorGUILayout.FloatField("Color offset", m_colorOffset); } else if (m_selectedAlgorithm == Algorithm.RANDOM_GOLDEN_RATIO) { m_saturation = EditorGUILayout.Slider("Saturation", m_saturation, 0.0f, 1.0f); } else if (m_selectedAlgorithm == Algorithm.GRADIENT) { m_colorGradient1 = EditorGUILayout.ColorField("From color", m_colorGradient1); m_colorGradient2 = EditorGUILayout.ColorField("To color", m_colorGradient2); } if (m_generatedColorPalette != null) { if (GUI.changed) { generatePalette(); } GUILayout.Space(3f); EditorGUILayout.BeginHorizontal(); { for (int j = 0; j < m_generatedColorPalette.colorInfoList.Count; j++) { Rect rect = EditorGUILayout.GetControlRect(false, 20f, EditorStyles.colorField, GUILayout.Width(20f)); EditorGUIUtility.DrawColorSwatch(rect, m_generatedColorPalette.colorInfoList[j].color); } } EditorGUILayout.EndHorizontal(); GUILayout.Space(3f); if (GUILayout.Button("Add to my palettes")) { m_paletteData.colorPaletteList.Add(m_generatedColorPalette); m_generatedColorPalette = null; PaletteUtils.SavePalettes(m_paletteData); } } } GUIUtils.EndContents(); } }