#region Copyright RenGuiYou. All rights reserved. //===================================================== // NeatlyFrameWork // Author: RenGuiyou // Feedback: mailto:750539605@qq.com //===================================================== #endregion using System.Collections.Generic; using UnityEngine; namespace Neatly.UI { internal static class NFontUpdateTracker { static Dictionary> m_Tracked = new Dictionary>(); public static void TrackText(NText t) { if (t.font == null) return; List exists; m_Tracked.TryGetValue(t.font, out exists); if (exists == null) { if (m_Tracked.Count == 0) Font.textureRebuilt += RebuildForFont; exists = new List(); m_Tracked.Add(t.font, exists); } if (!exists.Contains(t)) exists.Add(t); } private static void RebuildForFont(Font f) { List texts; m_Tracked.TryGetValue(f, out texts); if (texts == null) return; for (int i = 0; i < texts.Count; i++) { texts[i].FontTextureChanged(); } } public static void UntrackText(NText t) { if (t.font == null) return; List texts; m_Tracked.TryGetValue(t.font, out texts); if (texts == null) return; texts.Remove(t); if (texts.Count == 0) { m_Tracked.Remove(t.font); if (m_Tracked.Count == 0) Font.textureRebuilt -= RebuildForFont; } } } }