/// <summary> Method used by the ThemeManager when the active variant or selected theme have changed </summary> /// <param name="theme"> Target theme </param> public override void UpdateTarget(ThemeData theme) { if (Event == null) { return; } if (theme == null) { return; } base.UpdateTarget(theme); if (ThemeId == Guid.Empty) { return; } if (PropertyId == Guid.Empty) { return; } if (theme.ActiveVariant == null) { return; } Event.Invoke(theme.ActiveVariant.GetSprite(PropertyId)); }
/// <summary> Method used by the ThemeManager when the active variant or selected theme have changed </summary> /// <param name="theme"> Target theme </param> public override void UpdateTarget(ThemeData theme) { if (SpriteRenderer == null) { return; } if (theme == null) { return; } base.UpdateTarget(theme); if (ThemeId == Guid.Empty) { return; } if (PropertyId == Guid.Empty) { return; } if (theme.ActiveVariant == null) { return; } SpriteRenderer.color = theme.ActiveVariant.GetColor(PropertyId); if (!OverrideAlpha) { return; } SetAlpha(Alpha); }
/// <summary> Get the theme variant with the given variant id. If a theme variant with the given variant id is not found in the target theme, it will return null </summary> /// <param name="themeId"> Theme Guid to search for (the theme where the variant can be found) </param> /// <param name="variantId"> Variant Guid to search for (in the theme with the given id) </param> public ThemeVariantData GetVariant(Guid themeId, Guid variantId) { if (themeId == Guid.Empty || variantId == Guid.Empty) { return(null); } ThemeData themeData = Database.GetThemeData(themeId); return(themeData == null ? null : themeData.GetVariant(variantId)); }
/// <summary> Get the theme variant with the given variant name. If a theme variant with the given variant name is not found in the target theme, it will return null </summary> /// <param name="themeName"> Theme name to search for (the theme where the variant can be found) </param> /// <param name="variantName"> Variant name to search for (in the theme with the given id) </param> public ThemeVariantData GetVariant(string themeName, string variantName) { if (string.IsNullOrEmpty(themeName) || string.IsNullOrEmpty(variantName)) { return(null); } ThemeData themeData = Database.GetThemeData(themeName); return(themeData == null ? null : themeData.GetVariant(variantName)); }
/// <summary> Get the theme variant with the given variant name. If a theme variant with the given variant name is not found in the target theme, it will return null </summary> /// <param name="themeId"> Theme Guid to search for (the theme where the variant can be found) </param> /// <param name="variantName"> Variant name to search for (in the theme with the given id) </param> public ThemeVariantData GetVariant(Guid themeId, string variantName) { if (themeId == Guid.Empty || string.IsNullOrEmpty(variantName)) { return(null); } ThemeData themeData = Database.GetThemeData(themeId); return(themeData == null ? null : themeData.GetVariant(variantName)); }
/// <summary> Get the theme variant with the given variant id. If a theme variant with the given variant id is not found in the target theme, it will return null </summary> /// <param name="themeName"> Theme name to search for (the theme where the variant can be found) </param> /// <param name="variantId"> Variant Guid to search for (in the first theme with the given name) </param> public ThemeVariantData GetVariant(string themeName, Guid variantId) { if (string.IsNullOrEmpty(themeName) || variantId == Guid.Empty) { return(null); } ThemeData themeData = Database.GetThemeData(themeName); return(themeData == null ? null : themeData.GetVariant(variantId)); }
/// <summary> Get a string array of all the variant names found in a theme </summary> /// <param name="themeData"> Target theme </param> public static string[] GetVariantNames(ThemeData themeData) { var array = new string[themeData.Variants.Count]; for (int i = 0; i < themeData.Variants.Count; i++) { array[i] = themeData.Variants[i].VariantName; } return(array); }
/// <summary> Saves the active variant of the given theme to the PlayerPrefs </summary> /// <param name="theme"> Target theme </param> public static void SaveActiveVariant(ThemeData theme) { if (theme == null) { return; } if (theme.ActiveVariant == null) { return; } DataUtils.PlayerPrefsSetString(theme.Id.ToString(), theme.ActiveVariant.Id.ToString()); }
/// <summary> Method used by the ThemeManager when the active variant or selected theme have changed </summary> /// <param name="theme"> Target theme </param> public override void UpdateTarget(ThemeData theme) { if (Selectable == null) { return; } if (theme == null) { return; } base.UpdateTarget(theme); if (ThemeId == Guid.Empty) { return; } if (theme.ActiveVariant == null) { return; } ColorBlock colors = Selectable.colors; Selectable.colors = new ColorBlock { normalColor = NormalColorPropertyId != Guid.Empty ? theme.ActiveVariant.GetColor(NormalColorPropertyId) : colors.normalColor, highlightedColor = HighlightedColorPropertyId != Guid.Empty ? theme.ActiveVariant.GetColor(HighlightedColorPropertyId) : colors.highlightedColor, pressedColor = PressedColorPropertyId != Guid.Empty ? theme.ActiveVariant.GetColor(PressedColorPropertyId) : colors.pressedColor, #if UNITY_2019_3_OR_NEWER selectedColor = SelectedColorPropertyId != Guid.Empty ? theme.ActiveVariant.GetColor(SelectedColorPropertyId) : colors.selectedColor, #endif disabledColor = DisabledColorPropertyId != Guid.Empty ? theme.ActiveVariant.GetColor(DisabledColorPropertyId) : colors.disabledColor, colorMultiplier = colors.colorMultiplier, fadeDuration = colors.fadeDuration }; }
/// <summary> Loads the active variant of the given theme from the PlayerPrefs </summary> /// <param name="theme"> Target theme </param> public static void LoadActiveVariant(ThemeData theme) { if (theme == null) { return; } if (DataUtils.PlayerPrefsHasKey(theme.Id.ToString())) { theme.ActivateVariant(new Guid(DataUtils.PlayerPrefsGetString(theme.Id.ToString()))); } else { SaveActiveVariant(theme); } }
/// <summary> Add the given ThemeData reference to this database. Returns TRUE if the operation was successful </summary> /// <param name="themeData"> ThemeData that will get added to the database </param> /// <param name="saveAssets"> Write all unsaved asset changes to disk? </param> public bool AddTheme(ThemeData themeData, bool saveAssets) { if (themeData == null) { return(false); } if (Themes == null) { Themes = new List <ThemeData>(); } Themes.Add(themeData); UpdateThemesNames(false); SetDirty(saveAssets); return(true); }
/// <summary> Update all the theme targets registered in the ThemeManager </summary> public static void UpdateTargets() { if (!s_initialized) { Init(); } foreach (Guid themeId in ThemeTargets.Keys) { ThemeData theme = Database.GetThemeData(themeId); if (theme == null) { continue; } foreach (ThemeTarget themeTarget in ThemeTargets[themeId]) { themeTarget.UpdateTarget(theme); } } }
/// <summary> Creates a new ThemeData asset, at the given relative path, with the given theme name and adds a reference to it to the database </summary> /// <param name="relativePath"> Path where to create the theme asset </param> /// <param name="themeName"> The name of the new theme </param> /// <param name="showDialog"> Should a display dialog be shown before executing the action </param> /// <param name="saveAssets"> Write all unsaved asset changes to disk? </param> public bool CreateTheme(string relativePath, string themeName, bool showDialog = false, bool saveAssets = false) { themeName = themeName.Trim(); if (string.IsNullOrEmpty(themeName)) { #if UNITY_EDITOR if (showDialog) { EditorUtility.DisplayDialog(UILabels.NewTheme, UILabels.EnterThemeName, UILabels.Ok); } #endif return(false); } if (Contains(themeName)) { #if UNITY_EDITOR if (showDialog) { EditorUtility.DisplayDialog(UILabels.NewTheme, UILabels.ThemeNameAlreadyExists, UILabels.Ok); } #endif return(false); } #if UNITY_EDITOR ThemeData themeData = AssetUtils.CreateAsset <ThemeData>(relativePath, GetThemeDataFilename(themeName.Replace(" ", string.Empty))); #else ThemeData themeData = ScriptableObject.CreateInstance <ThemeData>(); #endif if (themeData == null) { return(false); } themeData.ThemeName = themeName; themeData.name = themeName; themeData.Init(false, false); themeData.SetDirty(false); AddTheme(themeData, false); SetDirty(saveAssets); return(true); }
/// <summary> Method used by the ThemeManager when the active variant or selected theme have changed </summary> /// <param name="theme"> Target theme </param> public override void UpdateTarget(ThemeData theme) { if (Selectable == null) { return; } if (theme == null) { return; } base.UpdateTarget(theme); if (ThemeId == Guid.Empty) { return; } if (theme.ActiveVariant == null) { return; } SpriteState spriteState = Selectable.spriteState; Selectable.spriteState = new SpriteState { highlightedSprite = HighlightedSpritePropertyId != Guid.Empty ? theme.ActiveVariant.GetSprite(HighlightedSpritePropertyId) : spriteState.highlightedSprite, pressedSprite = PressedSpritePropertyId != Guid.Empty ? theme.ActiveVariant.GetSprite(PressedSpritePropertyId) : spriteState.pressedSprite, #if UNITY_2019_1_OR_NEWER selectedSprite = SelectedSpritePropertyId != Guid.Empty ? theme.ActiveVariant.GetSprite(SelectedSpritePropertyId) : spriteState.selectedSprite, #endif disabledSprite = DisabledSpritePropertyId != Guid.Empty ? theme.ActiveVariant.GetSprite(DisabledSpritePropertyId) : spriteState.disabledSprite }; }
/// <summary> [Editor Only] Perform a deep search through the project for any unregistered ThemeData asset files and adds them to the database. The search is done only in all the Resources folders. </summary> /// <param name="saveAssets"> Write all unsaved asset changes to disk? </param> public void SearchForUnregisteredThemes(bool saveAssets) { DoozyUtils.DisplayProgressBar(UILabels.SearchForThemes, UILabels.Search, 0.1f); bool foundUnregisteredThemeData = false; ThemeData[] array = Resources.LoadAll <ThemeData>(""); if (array == null || array.Length == 0) { DoozyUtils.ClearProgressBar(); return; } if (Themes == null) { Themes = new List <ThemeData>(); } for (int i = 0; i < array.Length; i++) { ThemeData foundThemeData = array[i]; DoozyUtils.DisplayProgressBar(UILabels.SearchForThemes, UILabels.Search, 0.1f + 0.1f + 0.7f * (i + 1) / array.Length); if (Themes.Contains(foundThemeData)) { continue; } AddTheme(foundThemeData, false); foundUnregisteredThemeData = true; } if (!foundUnregisteredThemeData) { DoozyUtils.ClearProgressBar(); return; } DoozyUtils.DisplayProgressBar(UILabels.SearchForThemes, UILabels.Search, 0.9f); UpdateThemesNames(); SetDirty(saveAssets); DoozyUtils.ClearProgressBar(); }
/// <summary> Activate the variant by name in the theme with the given name </summary> /// <param name="themeName"> Theme name to search for (the theme where the variant can be found) </param> /// <param name="variantName"> Variant name to search for (in the theme with the given name) </param> public static void ActivateVariant(string themeName, string variantName) { if (!s_initialized) { Init(); } ThemeData theme = Instance.GetTheme(themeName); if (theme == null) { return; } theme.ActivateVariant(variantName); UpdateTargets(theme); if (!AutoSave) { return; } SaveActiveVariant(theme); DataUtils.PlayerPrefsSave(); }
/// <summary> Update all the theme targets registered in the ThemeManager, for the given theme </summary> /// <param name="themeData"> Theme reference </param> public static void UpdateTargets(ThemeData themeData) { if (!s_initialized) { Init(); } if (themeData == null) { return; } foreach (Guid themeId in ThemeTargets.Keys) { if (themeId != themeData.Id) { continue; } foreach (ThemeTarget themeTarget in ThemeTargets[themeId]) { themeTarget.UpdateTarget(themeData); } break; } }
/// <summary> Rename a ThemeData database name (including the asset filename). Returns TRUE if the operation was successful </summary> /// <param name="themeData"> Target ThemeData </param> /// <param name="newThemeName"> The new database name for the target ThemeData </param> public bool RenameThemeData(ThemeData themeData, string newThemeName) { if (themeData == null) { return(false); } newThemeName = newThemeName.Trim(); #if UNITY_EDITOR if (string.IsNullOrEmpty(newThemeName)) { EditorUtility.DisplayDialog(UILabels.RenameTheme + " '" + themeData.ThemeName + "'", UILabels.EnterDatabaseName, UILabels.Ok); return(false); } if (Contains(newThemeName)) { EditorUtility.DisplayDialog(UILabels.RenameTheme + " '" + themeData.ThemeName + "'", UILabels.NewThemeName + ": '" + newThemeName + "" + "\n\n" + UILabels.AnotherEntryExists, UILabels.Ok); return(false); } themeData.ThemeName = newThemeName; AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(themeData), GetThemeDataFilename(newThemeName.Replace(" ", string.Empty))); UpdateThemesNames(true); #endif return(true); }
/// <summary> Method used by the ThemeManager when the active variant or selected theme have changed </summary> /// <param name="theme"> Target theme </param> public virtual void UpdateTarget(ThemeData theme) { }