SealIcon.cs 799 B

1234567891011121314151617181920212223242526
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace TowerDevil
  4. {
  5. [RequireComponent(typeof(CanvasRenderer))]
  6. public sealed class SealIcon : MaskableGraphic
  7. {
  8. public Color top, bottom;
  9. protected override void OnPopulateMesh(VertexHelper mesh)
  10. {
  11. mesh.Clear();
  12. Rect r = rectTransform.rect;
  13. void Vertex(float x, float y) => mesh.AddVert(
  14. new Vector3(r.xMin + x * r.width, r.yMin + y * r.height), Color.Lerp(bottom, top, y), Vector2.zero);
  15. Vertex(.5f, 1);
  16. Vertex(1, .83f);
  17. Vertex(1, .42f);
  18. Vertex(.5f, 0);
  19. Vertex(0, .42f);
  20. Vertex(0, .83f);
  21. for (int i = 1; i < 5; i++)
  22. mesh.AddTriangle(0, i, i + 1);
  23. }
  24. }
  25. }