ImagePlus.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public class ImagePlus : Image
  6. {
  7. #region 变量
  8. public Text Text
  9. {
  10. get
  11. {
  12. if (Text_ == null)
  13. {
  14. Text_ = GetComponentInParent<Text>();
  15. }
  16. return Text_;
  17. }
  18. set { Text_ = value; }
  19. }
  20. private Text Text_;
  21. public bool Draw;
  22. public List<UIVertex[]> VerticesList;
  23. #endregion
  24. public void UpdateStatus(bool draw, VertexHelper empty, List<UIVertex> vertexList)
  25. {
  26. Draw = draw;
  27. if (Draw)
  28. {
  29. if (Application.isPlaying)
  30. {
  31. if (sprite == null)
  32. {
  33. Auxiliary.Instance.DelayCall
  34. (
  35. () =>
  36. {
  37. sprite = ManaReso.LoadSprite("Atlas", Folder.Atlas);
  38. },
  39. 1
  40. );
  41. }
  42. }
  43. }
  44. VerticesList = new List<UIVertex[]>();
  45. if (vertexList.Valid())
  46. {
  47. for (int i = 0; i < vertexList.Count; i += 4)
  48. {
  49. UIVertex v0 = vertexList[i + 0];
  50. UIVertex v1 = vertexList[i + 1];
  51. UIVertex v2 = vertexList[i + 2];
  52. UIVertex v3 = vertexList[i + 3];
  53. v0.color *= color;
  54. v1.color *= color;
  55. v2.color *= color;
  56. v3.color *= color;
  57. VerticesList.Add
  58. (
  59. new UIVertex[]
  60. {
  61. v0,
  62. v1,
  63. v2,
  64. v3
  65. }
  66. );
  67. }
  68. }
  69. OnPopulateMesh(empty);
  70. Auxiliary.Instance.DelayCall
  71. (
  72. () =>
  73. {
  74. SetVerticesDirty();
  75. },
  76. 2
  77. );
  78. }
  79. protected override void OnPopulateMesh(VertexHelper toFill)
  80. {
  81. toFill.Clear();
  82. if (Draw)
  83. {
  84. if (VerticesList.Valid())
  85. {
  86. for (int i = 0; i < VerticesList.Count; i++)
  87. {
  88. toFill.AddUIVertexQuad(VerticesList[i]);
  89. }
  90. }
  91. }
  92. }
  93. }