public void drawInspector() { if (GUIUtils.DrawHeader("Import palette")) { GUIUtils.BeginContents(); { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Import a", GUILayout.Width(50f)); m_importFileIndex = EditorGUILayout.Popup(m_importFileIndex, m_importFileExtensionArray, GUILayout.Width(100f)); EditorGUILayout.LabelField("file", GUILayout.Width(20f)); if (GUILayout.Button("Import", EditorStyles.miniButton)) { importPalette(); GUI.FocusControl(null); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); { GUILayout.Space(6f); drawDropPaletteArea(); GUILayout.Space(6f); } EditorGUILayout.EndHorizontal(); GUILayout.Space(15f); GUIUtils.BeginContents(); { EditorGUILayout.LabelField("You can import palettes directly from websites, by just copying the URL and clicking the button below.\n\nCompatible sites are:" + "\n- colourLovers.com" + "\n- dribbble.com" + "\n- colorcombos.com" + "\n- colrd.com", EditorStyles.wordWrappedLabel); GUILayout.Space(3f); bool isValidURL = isStringValidURL(EditorGUIUtility.systemCopyBuffer); if (!isValidURL) { GUI.color = Color.yellow; EditorGUILayout.LabelField("Currently don't have a valid URL in clipboard.", EditorStyles.wordWrappedMiniLabel); GUI.color = Color.white; } EditorGUILayout.BeginHorizontal(); { GUI.enabled = isValidURL; if (GUILayout.Button(new GUIContent("Download from URL in clipboard", EditorGUIUtility.systemCopyBuffer), EditorStyles.miniButton)) { importPaletteFromURL(EditorGUIUtility.systemCopyBuffer); GUI.FocusControl(null); } GUI.enabled = true; } EditorGUILayout.EndHorizontal(); } GUIUtils.EndContents(); } GUIUtils.EndContents(); } }
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() { 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(); } }