using System; using System.Collections.Generic; using UnityEngine; public class FontCache : MonoBehaviour { public static FontCache Instance; private Dictionary cache = new Dictionary(); public List extraData = new List(); public List DefaultFonts = new List(); public List DefaultFontMaterials = new List(); public void OnEnable() { if (!FontCache.Instance) { FontCache.Instance = this; UnityEngine.Object.DontDestroyOnLoad(base.gameObject); return; } if (FontCache.Instance != null) { UnityEngine.Object.Destroy(base.gameObject); } } public void SetFont(TextRenderer self, string name) { if (self.FontData.name == name) { return; } for (int i = 0; i < this.DefaultFonts.Count; i++) { if (this.DefaultFonts[i].name == name) { MeshRenderer component = self.GetComponent(); Material material = component.material; self.FontData = this.DefaultFonts[i]; component.sharedMaterial = this.DefaultFontMaterials[i]; component.material.SetColor("_OutlineColor", material.GetColor("_OutlineColor")); component.material.SetInt("_Mask", material.GetInt("_Mask")); return; } } } public FontData LoadFont(TextAsset dataSrc) { if (this.cache == null) { this.cache = new Dictionary(); } FontData fontData; if (this.cache.TryGetValue(dataSrc.name, out fontData)) { return fontData; } int num = this.extraData.FindIndex((FontExtensionData ed) => ed.FontName.Equals(dataSrc.name, StringComparison.OrdinalIgnoreCase)); FontExtensionData eData = null; if (num >= 0) { eData = this.extraData[num]; } fontData = FontCache.LoadFontUncached(dataSrc, eData); this.cache[dataSrc.name] = fontData; return fontData; } public static FontData LoadFontUncached(TextAsset dataSrc, FontExtensionData eData = null) { return FontLoader.FromBinary(dataSrc, eData); } }