From c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 19 Apr 2020 17:19:32 -0400 Subject: Inital commit --- .../Scripts/Runtime/TMP_StyleSheet.cs | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_StyleSheet.cs (limited to 'Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_StyleSheet.cs') diff --git a/Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_StyleSheet.cs b/Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_StyleSheet.cs new file mode 100644 index 0000000..8d02a18 --- /dev/null +++ b/Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_StyleSheet.cs @@ -0,0 +1,131 @@ +using UnityEngine; +using System; +using System.Collections.Generic; + + +namespace TMPro +{ + + [Serializable] + public class TMP_StyleSheet : ScriptableObject + { + private static TMP_StyleSheet s_Instance; + + [SerializeField] + private List m_StyleList = new List(1); + private Dictionary m_StyleDictionary = new Dictionary(); + + + /// + /// Get a singleton instance of the TMP_StyleSheet + /// + public static TMP_StyleSheet instance + { + get + { + if (s_Instance == null) + { + s_Instance = TMP_Settings.defaultStyleSheet; + + if (s_Instance == null) + s_Instance = Resources.Load("Style Sheets/Default Style Sheet"); + + if (s_Instance == null) return null; + + // Load the style dictionary. + s_Instance.LoadStyleDictionaryInternal(); + } + + return s_Instance; + } + } + + + /// + /// Static Function to load the Default Style Sheet. + /// + /// + public static TMP_StyleSheet LoadDefaultStyleSheet() + { + return instance; + } + + + /// + /// Function to retrieve the Style matching the HashCode. + /// + /// + /// + public static TMP_Style GetStyle(int hashCode) + { + return instance.GetStyleInternal(hashCode); + } + + + /// + /// Internal method to retrieve the Style matching the Hashcode. + /// + /// + /// + private TMP_Style GetStyleInternal(int hashCode) + { + if (m_StyleDictionary.TryGetValue(hashCode, out TMP_Style style)) + { + return style; + } + + return null; + } + + + public void UpdateStyleDictionaryKey(int old_key, int new_key) + { + if (m_StyleDictionary.ContainsKey(old_key)) + { + TMP_Style style = m_StyleDictionary[old_key]; + m_StyleDictionary.Add(new_key, style); + m_StyleDictionary.Remove(old_key); + } + } + + + /// + /// Function to update the internal reference to a newly assigned style sheet in the TMP Settings. + /// + public static void UpdateStyleSheet() + { + // Reset instance + s_Instance = null; + + RefreshStyles(); + } + + + /// + /// Function to refresh the Style Dictionary. + /// + public static void RefreshStyles() + { + instance.LoadStyleDictionaryInternal(); + } + + + /// + /// + /// + private void LoadStyleDictionaryInternal() + { + m_StyleDictionary.Clear(); + + // Read Styles from style list and store them into dictionary for faster access. + for (int i = 0; i < m_StyleList.Count; i++) + { + m_StyleList[i].RefreshStyle(); + + if (!m_StyleDictionary.ContainsKey(m_StyleList[i].hashCode)) + m_StyleDictionary.Add(m_StyleList[i].hashCode, m_StyleList[i]); + } + } + } + +} \ No newline at end of file -- cgit v1.2.3