GetFont() public static method

public static GetFont ( string name ) : BaseFont
name string
return BaseFont
Beispiel #1
0
        void LoadFont()
        {
            //Try to load name.ttf in Resources
            _font = (Font)Resources.Load(name, typeof(Font));

            //Try to load name.ttf in Resources/Fonts/
            if (_font == null)
            {
                _font = (Font)Resources.Load("Fonts/" + name, typeof(Font));
            }

#if (UNITY_5 || UNITY_5_3_OR_NEWER)
            //Try to use new API in Uinty5 to load
            if (_font == null)
            {
                if (name.IndexOf(",") != -1)
                {
                    string[] arr = name.Split(',');
                    int      cnt = arr.Length;
                    for (int i = 0; i < cnt; i++)
                    {
                        arr[i] = arr[i].Trim();
                    }
                    _font = Font.CreateDynamicFontFromOSFont(arr, 16);
                }
                else
                {
                    _font = Font.CreateDynamicFontFromOSFont(name, 16);
                }
            }
#endif
            if (_font == null)
            {
                if (name != UIConfig.defaultFont)
                {
                    DynamicFont bf = FontManager.GetFont(UIConfig.defaultFont) as DynamicFont;
                    if (bf != null)
                    {
                        _font = bf._font;
                    }
                }

                //Try to use Unity builtin resource
                if (_font == null)
                {
                    _font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
                }

                if (_font == null)
                {
                    throw new Exception("Cant load font '" + name + "'");
                }
            }
            else
            {
                _font.hideFlags                      = DisplayOptions.hideFlags;
                _font.material.hideFlags             = DisplayOptions.hideFlags;
                _font.material.mainTexture.hideFlags = DisplayOptions.hideFlags;
            }
        }
Beispiel #2
0
        virtual protected void LoadFont()
        {
            _font = ( Font )Resources.Load(name, typeof(Font));
            if (_font == null)
            {
                _font = ( Font )Resources.Load("Fonts/" + name, typeof(Font));
            }
            if (_font == null)
            {
                _font = ( Font )Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
            }
            if (_font == null)
            {
                if (name != UIConfig.defaultFont)
                {
                    DynamicFont bf = FontManager.GetFont(UIConfig.defaultFont) as DynamicFont;
                    if (bf != null)
                    {
                        _font = bf._font;
                    }
                }
                if (_font == null)
                {
                    throw new Exception("Cant load font '" + name + "'");
                }
            }

            Font.textureRebuilt += textureRebuildCallback;
            this.mainTexture     = new NTexture(_font.material.mainTexture);
        }
        virtual protected void LoadFont()
        {
            _font = (Font)Resources.Load(name, typeof(Font));
            if (_font == null)
            {
                _font = (Font)Resources.Load("Fonts/" + name, typeof(Font));
            }
#if UNITY_5
            if (_font == null)
            {
                if (name.IndexOf(",") != -1)
                {
                    string[] arr = name.Split(new char[] { ',' });
                    int      cnt = arr.Length;
                    for (int i = 0; i < cnt; i++)
                    {
                        arr[i] = arr[i].Trim();
                    }
                    _font = Font.CreateDynamicFontFromOSFont(arr, 16);
                }
                else
                {
                    _font = Font.CreateDynamicFontFromOSFont(name, 16);
                }
            }
#endif
            if (_font == null)
            {
                _font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
            }
            if (_font == null)
            {
                if (name != UIConfig.defaultFont)
                {
                    DynamicFont bf = FontManager.GetFont(UIConfig.defaultFont) as DynamicFont;
                    if (bf != null)
                    {
                        _font = bf._font;
                    }
                }
                if (_font == null)
                {
                    throw new Exception("Cant load font '" + name + "'");
                }
            }

#if UNITY_5
            Font.textureRebuilt += textureRebuildCallback;
#else
            _font.textureRebuildCallback += textureRebuildCallback;
#endif
            this.mainTexture = new NTexture(_font.material.mainTexture);
        }