void OnEnable() { //Load initila variables SetColors(GetColorDefault(GamestrapHelper.ColorRGBInt(141, 39, 137))); font = (Font)AssetDatabase.LoadAssetAtPath(GamestrapHelper.gamestrapRoute + "Fonts/Lato/Lato-Regular.ttf", typeof(Font)); SetUpColors(); sceneColors = new List <Color>(); if (theme == null) { FindTheme(); } selectedColorSet = null; selectedEffectSet = null; defaultBg = GUI.backgroundColor; }
public void ActivateEffects(GameObject gameObject, EffectSet set) { if (gameObject.GetComponent <UnityEngine.UI.Image>()) { if (set.gradient) { GradientEffect gradientEffect = gameObject.GetComponent <GradientEffect>(); if (!gradientEffect) { gradientEffect = Undo.AddComponent <GradientEffect>(gameObject); } gradientEffect.top = set.gradientTop; gradientEffect.bottom = set.gradientBottom; EditorUtility.SetDirty(gradientEffect); } else if (gameObject.GetComponent <GradientEffect>()) { Undo.DestroyObjectImmediate(gameObject.GetComponent <GradientEffect>()); } } if (gameObject.GetComponent <UnityEngine.UI.Image>() || gameObject.GetComponent <UnityEngine.UI.Text>()) { if (set.shadow) { ShadowEffect shadowEffect = gameObject.GetComponent <ShadowEffect>(); if (!shadowEffect) { shadowEffect = Undo.AddComponent <ShadowEffect>(gameObject); } shadowEffect.effectDistance = set.shadowOffset; shadowEffect.effectColor = set.shadowColor; EditorUtility.SetDirty(shadowEffect); } else if (gameObject.GetComponent <ShadowEffect>()) { Undo.DestroyObjectImmediate(gameObject.GetComponent <ShadowEffect>()); } } if (gameObject.transform.childCount > 0) // Recursive search for components { for (int i = 0; i < gameObject.transform.childCount; i++) { ActivateEffects(gameObject.transform.GetChild(i).gameObject, set); } } }
void OnInspectorUpdate() { //Checks to see if an undo changed the selected Sets if (theme != null) { if (selectedColorSet != null && !theme.palette.Contains(selectedColorSet)) { selectedColorSet = null; // To update the undos right away Repaint(); } if (selectedEffectSet != null && !theme.effectSets.Contains(selectedEffectSet)) { selectedEffectSet = null; // To update the undos right away Repaint(); } } }
private void ApplyEffectSetTag(EffectSet set) { if (set.tag.Length > 0 && set.tag != "Untagged") { GameObject[] list = GameObject.FindGameObjectsWithTag(set.tag); foreach (GameObject go in list) { UIBehaviour[] effects; #if UNITY_4_6 || UNITY_5_0 || UNITY_5_1 effects = go.GetComponents <BaseVertexEffect>(); #else effects = go.GetComponents <BaseMeshEffect>(); #endif foreach (UIBehaviour behaviour in effects) { DestroyImmediate(behaviour); } ActivateEffects(go, set); go.SetActive(false); go.SetActive(true); } } }
private void ActivateEffects(GameObject gameObject, EffectSet set) { if (gameObject.GetComponent <UnityEngine.UI.Image>()) { if (set.gradient) { GradientEffect gradientEffect = gameObject.GetComponent <GradientEffect>(); if (!gradientEffect) { gradientEffect = gameObject.AddComponent <GradientEffect>(); } gradientEffect.top = set.gradientTop; gradientEffect.bottom = set.gradientBottom; } else if (gameObject.GetComponent <GradientEffect>()) { DestroyImmediate(gameObject.GetComponent <GradientEffect>()); } if (set.radialGradient) { RadialGradientEffect gradientEffect = gameObject.GetComponent <RadialGradientEffect>(); if (!gradientEffect) { gradientEffect = gameObject.AddComponent <RadialGradientEffect>(); } gradientEffect.centerColor = set.radialColor; gradientEffect.centerPosition = set.centerPosition; gradientEffect.radius = set.radius; } else if (gameObject.GetComponent <RadialGradientEffect>()) { DestroyImmediate(gameObject.GetComponent <RadialGradientEffect>()); } } if (gameObject.GetComponent <UnityEngine.UI.Image>() || gameObject.GetComponent <UnityEngine.UI.Text>()) { if (set.shadow) { ShadowEffect shadowEffect = gameObject.GetComponent <ShadowEffect>(); if (!shadowEffect) { shadowEffect = gameObject.AddComponent <ShadowEffect>(); } shadowEffect.effectDistance = set.shadowOffset; shadowEffect.effectColor = set.shadowColor; } else if (gameObject.GetComponent <ShadowEffect>()) { DestroyImmediate(gameObject.GetComponent <ShadowEffect>()); } if (set.mirrorEffect) { MirrorEffect mirrorEffect = gameObject.GetComponent <MirrorEffect>(); if (!mirrorEffect) { mirrorEffect = gameObject.AddComponent <MirrorEffect>(); } mirrorEffect.top = set.mirrorTop; mirrorEffect.bottom = set.mirrorBottom; mirrorEffect.offset = set.mirrorOffset; mirrorEffect.scale = set.mirrorScale; mirrorEffect.skew = set.mirrorSkew; } else if (gameObject.GetComponent <MirrorEffect>()) { DestroyImmediate(gameObject.GetComponent <MirrorEffect>()); } if (set.skewEffect) { SkewEffect skewEffect = gameObject.GetComponent <SkewEffect>(); if (!skewEffect) { skewEffect = gameObject.AddComponent <SkewEffect>(); } skewEffect.skew = set.skew; skewEffect.perspective = set.perspective; } else if (gameObject.GetComponent <SkewEffect>()) { DestroyImmediate(gameObject.GetComponent <SkewEffect>()); } } if (gameObject.transform.childCount > 0) // Recursive search for components { for (int i = 0; i < gameObject.transform.childCount; i++) { ActivateEffects(gameObject.transform.GetChild(i).gameObject, set); } } }
void OnGUI() { if (theme == null) { FindTheme(); } //Checks if there is any style not initialized SetStyles(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos); EditorGUI.BeginChangeCheck(); Undo.RecordObject(theme, "Content change in theme"); GUILayout.BeginHorizontal(); GamestrapTheme newTheme = (GamestrapTheme)EditorGUILayout.ObjectField(theme, typeof(GamestrapTheme), false); if (theme != newTheme) { string assetPathAndName = AssetDatabase.GetAssetPath(newTheme); EditorPrefs.SetString(prefsKey, assetPathAndName); } theme = newTheme; //Save as button UI Logic SaveAs(); GUILayout.EndHorizontal(); #region Palette GUI GUILayout.Label("Palette", titleStyle); GUILayout.Label("Right click to assign color to selection"); EditorGUILayout.BeginVertical("Box"); EditorGUILayout.BeginHorizontal(); int counter = 0; foreach (ColorSet colorSet in theme.palette) { GUI.backgroundColor = colorSet.normal; // Sets the button color if (GUILayout.Button("", (colorSet == selectedColorSet) ? btnSelectedStyle : btnStyle, GUILayout.Width((position.width - 35f) / rowCount), GUILayout.Height(40))) { // To remove focus from any input field which might lead to errors GUI.FocusControl("Null"); if (Event.current.button == 1) { AssignColorsToSelection(colorSet); } else if (Event.current.button == 0) { if (colorSet == selectedColorSet) { selectedColorSet = null; } else { selectedColorSet = colorSet; } } } counter++; if (counter % rowCount == 0) { GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } } GUI.backgroundColor = Color.white; if (GUILayout.Button("Add", btnStyle, GUILayout.Width((position.width - 20f) / rowCount), GUILayout.Height(40))) { GUI.FocusControl("Null"); Color[] baseColor = colors[UnityEngine.Random.Range(0, colors.Count - 1)]; selectedColorSet = new ColorSet(baseColor); theme.palette.Add(selectedColorSet); } GUI.backgroundColor = defaultBg; GUILayout.EndHorizontal(); if (selectedColorSet != null) { GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) }); GUILayout.BeginHorizontal(); GUILayout.Label("Color Details", subtitleStyle); GUI.backgroundColor = deleteColor; if (GUILayout.Button("Delete", btnStyleWhiteFont, GUILayout.Width(50f))) { theme.palette.Remove(selectedColorSet); selectedColorSet = null; } GUI.backgroundColor = defaultBg; if (GUILayout.Button("X", GUILayout.Width(20))) { selectedColorSet = null; } GUILayout.EndHorizontal(); if (selectedColorSet != null) { EditorGUILayout.BeginHorizontal(); GUILayout.Label("Name", GUILayout.Width(100)); selectedColorSet.name = EditorGUILayout.TextField(selectedColorSet.name); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Tag", GUILayout.Width(100)); selectedColorSet.tag = EditorGUILayout.TagField(selectedColorSet.tag); EditorGUILayout.EndHorizontal(); selectedColorSet.normal = EditorGUILayout.ColorField("Normal", selectedColorSet.normal); selectedColorSet.highlighted = EditorGUILayout.ColorField("Highlighted", selectedColorSet.highlighted); selectedColorSet.pressed = EditorGUILayout.ColorField("Pressed", selectedColorSet.pressed); selectedColorSet.disabled = EditorGUILayout.ColorField("Disabled", selectedColorSet.disabled); selectedColorSet.detail = EditorGUILayout.ColorField("Detail", selectedColorSet.detail); GUILayout.BeginHorizontal(); GUILayout.Label("Apply ColorSet to:", GUILayout.Width(125)); GUI.backgroundColor = applyColor; if (GUILayout.Button("Selected", btnStyleWhiteFont)) { AssignColorsToSelection(selectedColorSet); } GUI.backgroundColor = defaultBg; GUI.enabled = selectedColorSet.tag.Length > 0 && selectedColorSet.tag != "Untagged"; if (GUILayout.Button("Tag")) { ApplyColorSetTag(selectedColorSet); } GUI.enabled = true; GUILayout.EndHorizontal(); #region Helper color selection GUILayout.BeginHorizontal(); bool lastShowSceneColors = showSceneColors; showColors = GUILayout.Toggle(showColors, "Suggestions", "Button"); showSuggestions = GUILayout.Toggle(showSuggestions, "Schemes", "Button"); showSceneColors = GUILayout.Toggle(showSceneColors, "Scene Colors", "Button"); // If the toggle was activated, refresh and search for the new colors in scene if (showSceneColors != lastShowSceneColors && showSceneColors) { SearchSceneColors(); } GUILayout.EndHorizontal(); if (showSceneColors) { GUILayout.Label("Scene Colors", EditorStyles.boldLabel); GUI.backgroundColor = Color.black; GUILayout.BeginVertical(bgStyle); GUILayout.BeginHorizontal(); counter = 0; foreach (Color color in sceneColors) { GUI.backgroundColor = color; // Sets the button color if (GUILayout.Button("", btnStyle)) { SetColors(GetColorDefault(color)); selectedColor = color; } counter++; if (counter % 5 == 0) { // Start a new row each 5 GUILayout.EndHorizontal(); GUI.backgroundColor = Color.black; GUILayout.BeginHorizontal(); } } GUILayout.EndHorizontal(); GUI.backgroundColor = defaultBg; // Resets the color background GUILayout.EndVertical(); } if (showSuggestions) { GUILayout.Label("Color Scheme Generator", EditorStyles.boldLabel); paletteType = (SchemeType)EditorGUILayout.EnumPopup("Scheme: ", paletteType); selectedColor = EditorGUILayout.ColorField("Base:", selectedColor); GUI.backgroundColor = Color.black; GUILayout.BeginVertical(bgStyle); GUI.backgroundColor = selectedColor; // Sets the button color if (GUILayout.Button("", btnStyle)) { SetColors(GetColorDefault(selectedColor)); } Color[] paletteColors = GamestrapHelper.GetColorPalette(selectedColor, paletteType); GUILayout.BeginHorizontal(); for (int i = 0; i < paletteColors.Length; i++) { GUI.backgroundColor = paletteColors[i]; // Sets the button color if (GUILayout.Button("", btnStyle)) { SetColors(GetColorDefault(paletteColors[i])); } } GUI.backgroundColor = defaultBg; // Resets the color background GUILayout.EndHorizontal(); GUILayout.EndVertical(); } if (showColors) { GUILayout.Label("Color Suggestions", EditorStyles.boldLabel); GUI.backgroundColor = Color.black; GUILayout.BeginVertical(bgStyle); GUILayout.BeginHorizontal(); counter = 0; foreach (Color[] color in colors) { GUI.backgroundColor = color[0]; // Sets the button color if (GUILayout.Button("", btnStyle) && color.Length >= 5) { SetColors(color); selectedColor = color[0]; } counter++; if (counter % 5 == 0) { // Start a new row each 5 GUILayout.EndHorizontal(); GUI.backgroundColor = Color.black; GUILayout.BeginHorizontal(); } } GUILayout.EndHorizontal(); GUI.backgroundColor = defaultBg; // Resets the color background GUILayout.EndVertical(); } #endregion } } EditorGUILayout.EndVertical(); #endregion #region Effects GUILayout.Label("Effects", titleStyle); EditorGUILayout.BeginVertical("Box"); Color effectBackground = new Color(0.6f, 0.6f, 0.6f); for (int i = 0; i < theme.effectSets.Count; i++) { EffectSet set = theme.effectSets[i]; bool pressed = (set == selectedEffectSet); GUI.backgroundColor = effectBackground; bool newPressed = GUILayout.Toggle(pressed, set.name, "Button"); GUI.backgroundColor = defaultBg; if (pressed != newPressed) { // To remove focus from any input field which might lead to errors GUI.FocusControl("Null"); if (newPressed) { if (Event.current.button == 1) { ActivateEffects(set); } else if (Event.current.button == 0) { selectedEffectSet = set; } } else if (Event.current.button == 0) { selectedEffectSet = null; } } if (selectedEffectSet != null && set == selectedEffectSet) { GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) }); GUILayout.BeginHorizontal(); GUILayout.Label("Effect Details", subtitleStyle); GUI.backgroundColor = deleteColor; if (GUILayout.Button("Delete", btnStyleWhiteFont, GUILayout.Width(50f))) { theme.effectSets.Remove(selectedEffectSet); selectedEffectSet = null; i--; } GUI.backgroundColor = defaultBg; if (GUILayout.Button("X", GUILayout.Width(20))) { selectedEffectSet = null; } GUILayout.EndHorizontal(); if (selectedEffectSet != null) { EditorGUILayout.BeginHorizontal(); GUILayout.Label("Name", GUILayout.Width(75)); selectedEffectSet.name = EditorGUILayout.TextField(selectedEffectSet.name); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Tag", GUILayout.Width(75)); selectedEffectSet.tag = EditorGUILayout.TagField(selectedEffectSet.tag); EditorGUILayout.EndHorizontal(); selectedEffectSet.shadow = EditorGUILayout.ToggleLeft("Shadow", selectedEffectSet.shadow); if (selectedEffectSet.shadow) { selectedEffectSet.shadowColor = EditorGUILayout.ColorField("Color", selectedEffectSet.shadowColor); selectedEffectSet.shadowOffset = EditorGUILayout.Vector2Field("Effect Distance", selectedEffectSet.shadowOffset); } selectedEffectSet.gradient = EditorGUILayout.ToggleLeft("Gradient", selectedEffectSet.gradient); if (selectedEffectSet.gradient) { selectedEffectSet.gradientTop = EditorGUILayout.ColorField("Color Top", selectedEffectSet.gradientTop); selectedEffectSet.gradientBottom = EditorGUILayout.ColorField("Color Bottom", selectedEffectSet.gradientBottom); } GUILayout.BeginHorizontal(); GUILayout.Label("Apply EffectSet to:", GUILayout.Width(125)); GUI.backgroundColor = applyColor; if (GUILayout.Button("Selection", btnStyleWhiteFont)) { ActivateEffects(selectedEffectSet); } GUI.backgroundColor = defaultBg; GUI.enabled = selectedEffectSet.tag.Length > 0 && selectedEffectSet.tag != "Untagged"; if (GUILayout.Button("Tag")) { ApplyEffectSetTag(selectedEffectSet); } GUI.enabled = true; GUILayout.EndHorizontal(); } } } if (GUILayout.Button("Add Effect Set", GUILayout.Height(35))) { GUI.FocusControl("Null"); selectedEffectSet = new EffectSet(); selectedEffectSet.name = "New Effect"; theme.effectSets.Add(selectedEffectSet); } EditorGUILayout.EndVertical(); #endregion #region Font GUILayout.Label("Font", titleStyle); GUILayout.BeginHorizontal(); font = (Font)EditorGUILayout.ObjectField(font, typeof(Font), false); if (GUILayout.Button("Apply")) { AssignFontToSelection(); } GUILayout.EndHorizontal(); #endregion #region Additional Options showGlobalAction = EditorGUILayout.Foldout(showGlobalAction, "Additional Options"); if (showGlobalAction) { GUI.backgroundColor = applyColor; if (GUILayout.Button("Apply theme to Tags in scene", btnStyleWhiteFont)) { foreach (ColorSet set in theme.palette) { ApplyColorSetTag(set); } foreach (EffectSet set in theme.effectSets) { ApplyEffectSetTag(set); } } GUI.backgroundColor = defaultBg; if (GUILayout.Button("Generate Palette From Scene")) { GetSceneColors(); foreach (Color c in sceneColors) { ColorSet cs = new ColorSet(); Color[] colors = GetColorDefault(c); cs.normal = colors[0]; cs.highlighted = colors[1]; cs.pressed = colors[2]; cs.disabled = colors[3]; cs.detail = colors[4]; theme.palette.Add(cs); } } GUI.backgroundColor = deleteColor; if (GUILayout.Button("Clear palette and effects", btnStyleWhiteFont)) { theme.palette.Clear(); theme.effectSets.Clear(); } GUI.backgroundColor = defaultBg; } #endregion if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(theme); } EditorGUILayout.EndScrollView(); }