TMP_SpriteCharacter.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using UnityEngine;
  3. namespace TMPro
  4. {
  5. /// <summary>
  6. /// A basic element of text representing a pictograph, image, sprite or emoji.
  7. /// </summary>
  8. [Serializable]
  9. public class TMP_SpriteCharacter : TMP_TextElement
  10. {
  11. /// <summary>
  12. /// The name of the sprite element.
  13. /// </summary>
  14. public string name
  15. {
  16. get { return m_Name; }
  17. set
  18. {
  19. if (value == m_Name)
  20. return;
  21. m_Name = value;
  22. m_HashCode = TMP_TextParsingUtilities.GetHashCodeCaseSensitive(m_Name);
  23. }
  24. }
  25. /// <summary>
  26. /// The hashcode value which is computed from the name of the sprite element.
  27. /// This value is read-only and updated when the name of the text sprite is changed.
  28. /// </summary>
  29. public int hashCode { get { return m_HashCode; } }
  30. // =============================================
  31. // Private backing fields for public properties.
  32. // =============================================
  33. [SerializeField]
  34. private string m_Name;
  35. [SerializeField]
  36. private int m_HashCode;
  37. // ********************
  38. // CONSTRUCTORS
  39. // ********************
  40. /// <summary>
  41. /// Default constructor.
  42. /// </summary>
  43. public TMP_SpriteCharacter()
  44. {
  45. m_ElementType = TextElementType.Sprite;
  46. }
  47. /// <summary>
  48. /// Constructor for new sprite character.
  49. /// </summary>
  50. /// <param name="unicode">Unicode value of the sprite character.</param>
  51. /// <param name="glyph">Glyph used by the sprite character.</param>
  52. public TMP_SpriteCharacter(uint unicode, TMP_SpriteGlyph glyph)
  53. {
  54. m_ElementType = TextElementType.Sprite;
  55. this.unicode = unicode;
  56. this.glyphIndex = glyph.index;
  57. this.glyph = glyph;
  58. this.scale = 1.0f;
  59. }
  60. /// <summary>
  61. /// Constructor for new sprite character.
  62. /// </summary>
  63. /// <param name="unicode">Unicode value of the sprite character.</param>
  64. /// <param name="spriteAsset">Sprite Asset used by this sprite character.</param>
  65. /// <param name="glyph">Glyph used by the sprite character.</param>
  66. public TMP_SpriteCharacter(uint unicode, TMP_SpriteAsset spriteAsset, TMP_SpriteGlyph glyph)
  67. {
  68. m_ElementType = TextElementType.Sprite;
  69. this.unicode = unicode;
  70. this.textAsset = spriteAsset;
  71. this.glyph = glyph;
  72. this.glyphIndex = glyph.index;
  73. this.scale = 1.0f;
  74. }
  75. /// <summary>
  76. ///
  77. /// </summary>
  78. /// <param name="unicode"></param>
  79. /// <param name="glyphIndex"></param>
  80. internal TMP_SpriteCharacter(uint unicode, uint glyphIndex)
  81. {
  82. m_ElementType = TextElementType.Sprite;
  83. this.unicode = unicode;
  84. this.textAsset = null;
  85. this.glyph = null;
  86. this.glyphIndex = glyphIndex;
  87. this.scale = 1.0f;
  88. }
  89. }
  90. }