/// <summary> /// Function to update the content of the int[] resulting from changes to OpeningDefinition & ClosingDefinition. /// </summary> public void RefreshStyle() { m_HashCode = TMP_TextParsingUtilities.GetHashCode(m_Name); int s1 = m_OpeningDefinition.Length; m_OpeningTagArray = new int[s1]; m_OpeningTagUnicodeArray = new uint[s1]; for (int i = 0; i < s1; i++) { m_OpeningTagArray[i] = m_OpeningDefinition[i]; m_OpeningTagUnicodeArray[i] = m_OpeningDefinition[i]; } int s2 = m_ClosingDefinition.Length; m_ClosingTagArray = new int[s2]; m_ClosingTagUnicodeArray = new uint[s2]; for (int i = 0; i < s2; i++) { m_ClosingTagArray[i] = m_ClosingDefinition[i]; m_ClosingTagUnicodeArray[i] = m_ClosingDefinition[i]; } }
/// <summary> /// Constructor /// </summary> /// <param name="styleName">Name of the style.</param> /// <param name="styleOpeningDefinition">Style opening definition.</param> /// <param name="styleClosingDefinition">Style closing definition.</param> internal TMP_Style(string styleName, string styleOpeningDefinition, string styleClosingDefinition) { m_Name = styleName; m_HashCode = TMP_TextParsingUtilities.GetHashCode(styleName); m_OpeningDefinition = styleOpeningDefinition; m_ClosingDefinition = styleClosingDefinition; RefreshStyle(); }
/// <summary> /// Function to update the content of the int[] resulting from changes to OpeningDefinition & ClosingDefinition. /// </summary> public void RefreshStyle() { m_HashCode = TMP_TextParsingUtilities.GetHashCode(m_Name); m_OpeningTagArray = new int[m_OpeningDefinition.Length]; for (int i = 0; i < m_OpeningDefinition.Length; i++) { m_OpeningTagArray[i] = m_OpeningDefinition[i]; } m_ClosingTagArray = new int[m_ClosingDefinition.Length]; for (int i = 0; i < m_ClosingDefinition.Length; i++) { m_ClosingTagArray[i] = m_ClosingDefinition[i]; } }
/// <summary> /// Get the Style for the given name. /// </summary> /// <param name="name">The name of the style.</param> /// <returns>The style if found.</returns> public TMP_Style GetStyle(string name) { if (m_StyleLookupDictionary == null) { LoadStyleDictionaryInternal(); } int hashCode = TMP_TextParsingUtilities.GetHashCode(name); TMP_Style style; if (m_StyleLookupDictionary.TryGetValue(hashCode, out style)) { return(style); } return(null); }
/// <summary> /// /// </summary> private void LoadStyleDictionaryInternal() { if (m_StyleLookupDictionary == null) { m_StyleLookupDictionary = new Dictionary <int, TMP_Style>(); } else { m_StyleLookupDictionary.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_StyleLookupDictionary.ContainsKey(m_StyleList[i].hashCode)) { m_StyleLookupDictionary.Add(m_StyleList[i].hashCode, m_StyleList[i]); } } // Add Normal Style if it does not already exists int normalStyleHashCode = TMP_TextParsingUtilities.GetHashCode("Normal"); if (!m_StyleLookupDictionary.ContainsKey(normalStyleHashCode)) { TMP_Style style = new TMP_Style("Normal", string.Empty, string.Empty); m_StyleList.Add(style); m_StyleLookupDictionary.Add(normalStyleHashCode, style); } #if UNITY_EDITOR //// Event to update objects when styles are changed in the editor. TMPro_EventManager.ON_TEXT_STYLE_PROPERTY_CHANGED(true); #endif }