ImagePlus.cs 1.8 KB

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