TextPlus.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public class TextPlus : Text
  6. {
  7. #region
  8. public bool Draw;
  9. private ImagePlus _ImagePlus;
  10. public ImagePlus ImagePlus
  11. {
  12. get
  13. {
  14. if (_ImagePlus == null)
  15. {
  16. _ImagePlus = GetComponentInChildren<ImagePlus>();
  17. }
  18. return _ImagePlus;
  19. }
  20. set { _ImagePlus = value; }
  21. }
  22. #endregion
  23. public override void SetVerticesDirty()
  24. {
  25. base.SetVerticesDirty();
  26. int leftIndex = text.IndexOf("<(");
  27. int rightIndex = text.IndexOf(")>");
  28. if (leftIndex == -1)
  29. {
  30. Draw = false;
  31. }
  32. else
  33. {
  34. Draw = true;
  35. ImagePlus.SpriteName = text.Between(leftIndex + 2, rightIndex - 2);
  36. ImagePlus.StartIndex = leftIndex - 1;
  37. text = text.Replace(leftIndex, rightIndex, " ");
  38. }
  39. }
  40. protected override void OnPopulateMesh(VertexHelper toFill)
  41. {
  42. base.OnPopulateMesh(toFill);
  43. if (Draw)
  44. {
  45. Draw = false;
  46. toFill.GetUIVertexStream(ImagePlus.TextVertexList);
  47. }
  48. }
  49. }