FairyGUI.DynamicFont.LoadFont C# (CSharp) Method

LoadFont() private method

private LoadFont ( ) : void
return void
        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
            //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;
            }

            #if (UNITY_4_7 || UNITY_5)
            Font.textureRebuilt += textureRebuildCallback;
            #else
            _font.textureRebuildCallback += textureRebuildCallback;
            #endif

            this.mainTexture = new NTexture(_font.material.mainTexture);
        }