From e9ea621b93fbb58d9edfca8375918791637bbd52 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 30 Dec 2020 20:59:04 +0800 Subject: +init --- Client/Assembly-CSharp/FontCache.cs | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Client/Assembly-CSharp/FontCache.cs (limited to 'Client/Assembly-CSharp/FontCache.cs') 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 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); + } +} -- cgit v1.1-26-g67d0