ImagePlus.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. sprite = Bundle.Atlas.LoadAsset<Sprite>("Atlas");
  34. }
  35. }
  36. }
  37. VerticesList = new List<UIVertex[]>();
  38. if (vertexList.Valid())
  39. {
  40. for (int i = 0; i < vertexList.Count; i += 4)
  41. {
  42. UIVertex v0 = vertexList[i + 0];
  43. UIVertex v1 = vertexList[i + 1];
  44. UIVertex v2 = vertexList[i + 2];
  45. UIVertex v3 = vertexList[i + 3];
  46. v0.color *= color;
  47. v1.color *= color;
  48. v2.color *= color;
  49. v3.color *= color;
  50. VerticesList.Add
  51. (
  52. new UIVertex[]
  53. {
  54. v0,
  55. v1,
  56. v2,
  57. v3
  58. }
  59. );
  60. }
  61. }
  62. OnPopulateMesh(empty);
  63. StartCoroutine
  64. (
  65. Auxiliary.IDelayCall
  66. (
  67. () =>
  68. {
  69. SetVerticesDirty();
  70. },
  71. 2
  72. )
  73. );
  74. }
  75. protected override void OnPopulateMesh(VertexHelper toFill)
  76. {
  77. toFill.Clear();
  78. if (Draw)
  79. {
  80. if (VerticesList.Valid())
  81. {
  82. for (int i = 0; i < VerticesList.Count; i++)
  83. {
  84. toFill.AddUIVertexQuad(VerticesList[i]);
  85. }
  86. }
  87. }
  88. }
  89. }