TMP_Style.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 PROPERTIES
  10. /// <summary>
  11. /// The name identifying this style. ex. <style="name">.
  12. /// </summary>
  13. public string name
  14. { get { return m_Name; } set { if (value != m_Name) m_Name = value; } }
  15. /// <summary>
  16. /// The hash code corresponding to the name of this style.
  17. /// </summary>
  18. public int hashCode
  19. { get { return m_HashCode; } set { if (value != m_HashCode) m_HashCode = value; } }
  20. /// <summary>
  21. /// The initial definition of the style. ex. <b> <u>.
  22. /// </summary>
  23. public string styleOpeningDefinition
  24. { get { return m_OpeningDefinition; } }
  25. /// <summary>
  26. /// The closing definition of the style. ex. </b> </u>.
  27. /// </summary>
  28. public string styleClosingDefinition
  29. { get { return m_ClosingDefinition; } }
  30. public int[] styleOpeningTagArray
  31. { get { return m_OpeningTagArray; } }
  32. public int[] styleClosingTagArray
  33. { get { return m_ClosingTagArray; } }
  34. // PRIVATE FIELDS
  35. [SerializeField]
  36. private string m_Name;
  37. [SerializeField]
  38. private int m_HashCode;
  39. [SerializeField]
  40. private string m_OpeningDefinition;
  41. [SerializeField]
  42. private string m_ClosingDefinition;
  43. [SerializeField]
  44. private int[] m_OpeningTagArray;
  45. [SerializeField]
  46. private int[] m_ClosingTagArray;
  47. //public TMP_Style()
  48. //{
  49. //Debug.Log("New Style with Name: " + m_Name + " was created. ID: ");
  50. //}
  51. /// <summary>
  52. /// Function to update the content of the int[] resulting from changes to OpeningDefinition & ClosingDefinition.
  53. /// </summary>
  54. public void RefreshStyle()
  55. {
  56. m_HashCode = TMP_TextUtilities.GetSimpleHashCode(m_Name);
  57. m_OpeningTagArray = new int[m_OpeningDefinition.Length];
  58. for (int i = 0; i < m_OpeningDefinition.Length; i++)
  59. m_OpeningTagArray[i] = m_OpeningDefinition[i];
  60. m_ClosingTagArray = new int[m_ClosingDefinition.Length];
  61. for (int i = 0; i < m_ClosingDefinition.Length; i++)
  62. m_ClosingTagArray[i] = m_ClosingDefinition[i];
  63. #if UNITY_EDITOR
  64. // Event to update objects when styles are changed in the editor.
  65. TMPro_EventManager.ON_TEXT_STYLE_PROPERTY_CHANGED(true);
  66. #endif
  67. }
  68. }
  69. }