TMP_SpriteCharacter.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }
  61. }