RoundedUiMask.cs 1.1 KB

12345678910111213141516171819202122232425262728
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace Olympus
  4. {
  5. // Geometry only: clips existing illustrations without creating replacement question art.
  6. [RequireComponent(typeof(CanvasRenderer))]
  7. public sealed class RoundedUiMask : MaskableGraphic
  8. {
  9. public float radius=28;
  10. protected override void OnPopulateMesh(VertexHelper vh)
  11. {
  12. vh.Clear();var r=GetPixelAdjustedRect();float rad=Mathf.Min(radius,Mathf.Min(r.width,r.height)/2);
  13. vh.AddVert(r.center,color,new Vector2(.5f,.5f));
  14. for(int corner=0;corner<4;corner++)
  15. {
  16. Vector2 c=new Vector2(corner==0||corner==3?r.xMax-rad:r.xMin+rad,corner<2?r.yMax-rad:r.yMin+rad);
  17. for(int j=0;j<=12;j++)
  18. {
  19. float a=(corner*90+j*90f/12)*Mathf.Deg2Rad;
  20. Vector2 p=c+new Vector2(Mathf.Cos(a),Mathf.Sin(a))*rad;
  21. vh.AddVert(p,color,new Vector2((p.x-r.xMin)/r.width,(p.y-r.yMin)/r.height));
  22. }
  23. }
  24. for(int i=0;i<52;i++)vh.AddTriangle(0,i+1,(i+1)%52+1);
  25. }
  26. }
  27. }