diff options
Diffstat (limited to 'Client/Assembly-CSharp/FontCache.cs')
-rw-r--r-- | Client/Assembly-CSharp/FontCache.cs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/FontCache.cs b/Client/Assembly-CSharp/FontCache.cs new file mode 100644 index 0000000..91dc7a0 --- /dev/null +++ b/Client/Assembly-CSharp/FontCache.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +public class FontCache : MonoBehaviour +{ + public static FontCache Instance; + + private Dictionary<string, FontData> cache = new Dictionary<string, FontData>(); + + public List<FontExtensionData> extraData = new List<FontExtensionData>(); + + public List<TextAsset> DefaultFonts = new List<TextAsset>(); + + public List<Material> DefaultFontMaterials = new List<Material>(); + + 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<MeshRenderer>(); + 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<string, FontData>(); + } + 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); + } +} |