Esempio n. 1
0
        /* ONLY NEEDED BY STYLING DEVS AND DESIGNERS.
         * [MenuItem("Theme/Refresh Styles &r", priority = 420)]
         * internal static void RefreshStyles()
         * {
         *  Unsupported.ClearSkinCache();
         *  EditorUtility.RequestScriptReload();
         *  InternalEditorUtility.RepaintAllViews();
         *  Debug.Log($"Style refreshed {DateTime.Now}");
         * }
         *
         * [MenuItem("Theme/Switch Theme And Repaint", priority = 420)]
         * internal static void SwitchTheme()
         * {
         *  AssetPreview.ClearTemporaryAssetPreviews();
         *  InternalEditorUtility.SwitchSkinAndRepaintAllViews();
         * }*/

        private static void UpdateGUIStyleProperties(string name, GUIStyle style)
        {
            var sname = GUIStyleExtensions.StyleNameToBlockName(style.name, false);
            var block = styleCatalog.GetStyle(sname);

            if (!block.IsValid())
            {
                return;
            }

            try
            {
                GUIStyleExtensions.PopulateStyle(styleCatalog, style, sname);

                // The new style extension do not support state backgrounds anymore.
                // Any background images needs to be defined in the uss data files.
                ResetDeprecatedBackgroundImage(style.normal);
                ResetDeprecatedBackgroundImage(style.hover);
                ResetDeprecatedBackgroundImage(style.active);
                ResetDeprecatedBackgroundImage(style.focused);
                ResetDeprecatedBackgroundImage(style.onNormal);
                ResetDeprecatedBackgroundImage(style.onHover);
                ResetDeprecatedBackgroundImage(style.onActive);
                ResetDeprecatedBackgroundImage(style.onFocused);
            }
            catch (Exception ex)
            {
                Debug.LogWarning($"Failed to parse extended style properties for {sname}\n{ex.Message}");
            }
        }
        public static Texture2D GetBackgroundImage(GUIStyle style, StyleState state = StyleState.normal)
        {
            var blockName  = GUIStyleExtensions.StyleNameToBlockName(style.name, false);
            var styleBlock = EditorResources.GetStyle(blockName, state);

            return(styleBlock.GetTexture(StyleCatalogKeyword.backgroundImage));
        }
        /* ONLY NEEDED BY STYLING DEVS AND DESIGNERS.
         * [MenuItem("Theme/Refresh Styles &r", priority = 420)]
         * internal static void RefreshStyles()
         * {
         *  Unsupported.ClearSkinCache();
         *  InternalEditorUtility.RequestScriptReload();
         *  InternalEditorUtility.RepaintAllViews();
         *  Debug.Log($"Style refreshed {DateTime.Now}");
         * }
         *
         * [MenuItem("Theme/Switch Theme And Repaint", priority = 420)]
         * internal static void SwitchTheme()
         * {
         *  AssetPreview.ClearTemporaryAssetPreviews();
         *  InternalEditorUtility.SwitchSkinAndRepaintAllViews();
         * }*/

        private static void UpdateGUIStyleProperties(string name, GUIStyle style)
        {
            if (LocalizationDatabase.currentEditorLanguage == SystemLanguage.English)
            {
                var rootBlock        = styleCatalog.GetStyle(StyleCatalogKeyword.root, StyleState.root);
                var systemSmallFont  = EditorGUIUtility.LoadRequired("Fonts/System/System Small.ttf") as Font;
                var systemNormalFont = EditorGUIUtility.LoadRequired("Fonts/System/System Normal.ttf") as Font;
                var currentFont      = GetCurrentFont();

                if (IsSystemFont(currentFont))
                {
                    var defaultSmallFontSize = rootBlock.GetInt("--unity-font-size-small", 11);
                    var systemFont           = style.fontSize == defaultSmallFontSize ? systemSmallFont : systemNormalFont;
                    systemFont.fontNames = new[] { currentFont };
                    style.font           = systemFont;
                }
                else
                {
                    if ((currentFont == "Roboto") && (style.fontStyle == FontStyle.Bold))
                    {
                        style.font      = EditorGUIUtility.LoadRequired("Fonts/roboto/Roboto-Medium.ttf") as Font;
                        style.fontStyle = FontStyle.Normal;
                    }
                    else
                    {
                        style.font = EditorGUIUtility.LoadRequired(builtInFonts[currentFont]) as Font;
                    }
                }
            }

            var sname = GUIStyleExtensions.StyleNameToBlockName(style.name, false);
            var block = styleCatalog.GetStyle(sname);

            if (!block.IsValid())
            {
                return;
            }

            try
            {
                GUIStyleExtensions.PopulateStyle(styleCatalog, style, sname);

                // The new style extension do not support state backgrounds anymore.
                // Any background images needs to be defined in the uss data files.
                ResetDeprecatedBackgroundImage(style.normal);
                ResetDeprecatedBackgroundImage(style.hover);
                ResetDeprecatedBackgroundImage(style.active);
                ResetDeprecatedBackgroundImage(style.focused);
                ResetDeprecatedBackgroundImage(style.onNormal);
                ResetDeprecatedBackgroundImage(style.onHover);
                ResetDeprecatedBackgroundImage(style.onActive);
                ResetDeprecatedBackgroundImage(style.onFocused);
            }
            catch (Exception ex)
            {
                Debug.LogWarning($"Failed to parse extended style properties for {sname}\n{ex.Message}");
            }
        }
Esempio n. 4
0
        /* ONLY NEEDED BY STYLING DEVS AND DESIGNERS.
         * [MenuItem("Theme/Refresh Styles &r", priority = 420)]
         * internal static void RefreshStyles()
         * {
         *  Unsupported.ClearSkinCache();
         *  EditorUtility.RequestScriptReload();
         *  InternalEditorUtility.RepaintAllViews();
         *  Debug.Log($"Style refreshed {DateTime.Now}");
         * }
         *
         * [MenuItem("Theme/Switch Theme And Repaint", priority = 420)]
         * internal static void SwitchTheme()
         * {
         *  AssetPreview.ClearTemporaryAssetPreviews();
         *  InternalEditorUtility.SwitchSkinAndRepaintAllViews();
         * }*/

        private static void UpdateGUIStyleProperties(string name, GUIStyle style)
        {
            var sname = GUIStyleExtensions.StyleNameToBlockName(style.name, false);
            var block = styleCatalog.GetStyle(sname);

            if (!block.IsValid())
            {
                return;
            }

            try
            {
                GUIStyleExtensions.PopulateStyle(styleCatalog, style, sname);
                GUIStyleExtensions.ConvertToExtendedStyle(style);
            }
            catch (Exception ex)
            {
                Debug.LogWarning($"Failed to parse extended style properties for {sname}\n{ex.Message}");
            }
        }
Esempio n. 5
0
        internal static List <GUIStyle> GetExtendedStylesFromSkin(GUISkin skin)
        {
            var extendedStyles = new List <GUIStyle>();
            Action <string, GUIStyle> appendExtendedBlock = (name, style) =>
            {
                var sname = GUIStyleExtensions.StyleNameToBlockName(style.name, false);
                if (styleCatalog.GetStyle(sname).IsValid())
                {
                    extendedStyles.Add(style);
                }
            };

            skin.ForEachGUIStyleProperty(appendExtendedBlock);
            foreach (var style in skin.customStyles)
            {
                appendExtendedBlock(style.name, style);
            }

            return(extendedStyles);
        }