RenderCache_SpriteData.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace WXB
  7. {
  8. // 缓存渲染元素
  9. public partial class RenderCache
  10. {
  11. class SpriteData : BaseData
  12. {
  13. public Sprite sprite;
  14. public void Reset(NodeBase n, Sprite s, Rect r, Line l)
  15. {
  16. node = n;
  17. sprite = s;
  18. rect = r;
  19. line = l;
  20. }
  21. protected override void OnRelease()
  22. {
  23. sprite = null;
  24. }
  25. public override void Render(VertexHelper vh, Rect area, Vector2 offset, float pixelsPerUnit)
  26. {
  27. Color currentColor = node.d_color;
  28. if (currentColor.a <= 0.01f)
  29. return;
  30. var uv = UnityEngine.Sprites.DataUtility.GetOuterUV(sprite);
  31. Vector2 leftPos = GetStartLeftBottom(1f) + offset;
  32. Tools.LB2LT(ref leftPos, area.height);
  33. float width = rect.width;
  34. float height = rect.height;
  35. int count = vh.currentVertCount;
  36. vh.AddVert(new Vector3(leftPos.x, leftPos.y), currentColor, new Vector2(uv.x, uv.y));
  37. vh.AddVert(new Vector3(leftPos.x, leftPos.y + height), currentColor, new Vector2(uv.x, uv.w));
  38. vh.AddVert(new Vector3(leftPos.x + width, leftPos.y + height), currentColor, new Vector2(uv.z, uv.w));
  39. vh.AddVert(new Vector3(leftPos.x + width, leftPos.y), currentColor, new Vector2(uv.z, uv.y));
  40. vh.AddTriangle(count, count + 1, count + 2);
  41. vh.AddTriangle(count + 2, count + 3, count);
  42. }
  43. }
  44. }
  45. }