TMP_Style.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using UnityEngine;
  2. using System.Collections;
  3. #pragma warning disable 0649 // Disabled warnings.
  4. namespace TMPro
  5. {
  6. [System.Serializable]
  7. public class TMP_Style
  8. {
  9. public static TMP_Style NormalStyle
  10. {
  11. get
  12. {
  13. if (k_NormalStyle == null)
  14. k_NormalStyle = new TMP_Style("Normal", string.Empty, string.Empty);
  15. return k_NormalStyle;
  16. }
  17. }
  18. internal static TMP_Style k_NormalStyle;
  19. // PUBLIC PROPERTIES
  20. /// <summary>
  21. /// The name identifying this style. ex. <style="name">.
  22. /// </summary>
  23. public string name
  24. { get { return m_Name; } set { if (value != m_Name) m_Name = value; } }
  25. /// <summary>
  26. /// The hash code corresponding to the name of this style.
  27. /// </summary>
  28. public int hashCode
  29. { get { return m_HashCode; } set { if (value != m_HashCode) m_HashCode = value; } }
  30. /// <summary>
  31. /// The initial definition of the style. ex. <b> <u>.
  32. /// </summary>
  33. public string styleOpeningDefinition
  34. { get { return m_OpeningDefinition; } }
  35. /// <summary>
  36. /// The closing definition of the style. ex. </b> </u>.
  37. /// </summary>
  38. public string styleClosingDefinition
  39. { get { return m_ClosingDefinition; } }
  40. public int[] styleOpeningTagArray
  41. { get { return m_OpeningTagArray; } }
  42. public int[] styleClosingTagArray
  43. { get { return m_ClosingTagArray; } }
  44. // PRIVATE FIELDS
  45. [SerializeField]
  46. private string m_Name;
  47. [SerializeField]
  48. private int m_HashCode;
  49. [SerializeField]
  50. private string m_OpeningDefinition;
  51. [SerializeField]
  52. private string m_ClosingDefinition;
  53. [SerializeField]
  54. private int[] m_OpeningTagArray;
  55. [SerializeField]
  56. private int[] m_ClosingTagArray;
  57. /// <summary>
  58. /// Constructor
  59. /// </summary>
  60. /// <param name="styleName">Name of the style.</param>
  61. /// <param name="styleOpeningDefinition">Style opening definition.</param>
  62. /// <param name="styleClosingDefinition">Style closing definition.</param>
  63. internal TMP_Style(string styleName, string styleOpeningDefinition, string styleClosingDefinition)
  64. {
  65. m_Name = styleName;
  66. m_HashCode = TMP_TextParsingUtilities.GetHashCode(styleName);
  67. m_OpeningDefinition = styleOpeningDefinition;
  68. m_ClosingDefinition = styleClosingDefinition;
  69. RefreshStyle();
  70. }
  71. /// <summary>
  72. /// Function to update the content of the int[] resulting from changes to OpeningDefinition & ClosingDefinition.
  73. /// </summary>
  74. public void RefreshStyle()
  75. {
  76. m_HashCode = TMP_TextParsingUtilities.GetHashCode(m_Name);
  77. m_OpeningTagArray = new int[m_OpeningDefinition.Length];
  78. for (int i = 0; i < m_OpeningDefinition.Length; i++)
  79. m_OpeningTagArray[i] = m_OpeningDefinition[i];
  80. m_ClosingTagArray = new int[m_ClosingDefinition.Length];
  81. for (int i = 0; i < m_ClosingDefinition.Length; i++)
  82. m_ClosingTagArray[i] = m_ClosingDefinition[i];
  83. }
  84. }
  85. }