ImagePlus.cs 2.6 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 = ResourceManager.LoadSprite("Atlas", Folder.Atlas);
  38. },
  39. 1
  40. );
  41. }
  42. }
  43. VerticesList = new List<UIVertex[]>();
  44. if (vertexList.Valid())
  45. {
  46. for (int i = 0; i < vertexList.Count; i += 4)
  47. {
  48. UIVertex v0 = vertexList[i + 0];
  49. UIVertex v1 = vertexList[i + 1];
  50. UIVertex v2 = vertexList[i + 2];
  51. UIVertex v3 = vertexList[i + 3];
  52. v0.color *= color;
  53. v1.color *= color;
  54. v2.color *= color;
  55. v3.color *= color;
  56. VerticesList.Add
  57. (
  58. new UIVertex[]
  59. {
  60. v0,
  61. v1,
  62. v2,
  63. v3
  64. }
  65. );
  66. }
  67. }
  68. OnPopulateMesh(empty);
  69. }
  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. }