/// <summary> /// Utility function that tries to open a font. /// </summary> /// <returns> /// The open font. /// </returns> /// <param name='ts'> /// Ts. /// </param> /// <param name='size'> /// Size. /// </param> static public TTF.Font TryOpenFont(TTFTextStyle ts, float size, int resolution) { #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR TTFTextFontListManager flm = TTFTextFontListManager.Instance; TTF.Font font = null; if (flm.Count == 0) { return(null); } // 1. set fontId to a sane value // do not override fontId if it's already set if (ts.FontId == "") { ts.FontId = flm.GetOneId(); } // Try Open it font = flm.OpenFont(ts.FontId, size, ref ts.orientationReversed, resolution); if (font != null) { return(font); } Debug.LogWarning("Font '" + ts.FontId + "' not found."); // Try fallback fonts #if !TTFTEXT_LITE char[] sep = new char[] { ';' }; foreach (string s in ts.runtimeFontFallback.Split(sep, System.StringSplitOptions.RemoveEmptyEntries)) { font = flm.OpenFont(s, size, ref ts.orientationReversed, resolution); if (font != null) { Debug.Log("Found fallback font " + font.Name); return(font); } } #endif // Last resort try another font font = flm.OpenFont(flm.GetOneId(), size, ref ts.orientationReversed, resolution); if (font != null) { Debug.Log("Found fallback font " + font.Name); return(font); } #endif ts.orientationReversed = false; return(null); }