using UnityEngine; using UnityEngine.Sprites; using UnityEngine.UI; namespace Olympus { // A circular mesh clips the rectangular source crop without a second mask or texture edit. public sealed class PortraitImage:Image { protected override void OnPopulateMesh(VertexHelper vh) { if(!sprite){base.OnPopulateMesh(vh);return;}vh.Clear();var r=GetPixelAdjustedRect();var uv=DataUtility.GetOuterUV(sprite);var center=r.center; vh.AddVert(center,color,new Vector2((uv.x+uv.z)*.5f,(uv.y+uv.w)*.5f)); for(int i=0;i<=64;i++){float a=i*Mathf.PI*2/64;var p=new Vector2(Mathf.Cos(a),Mathf.Sin(a));vh.AddVert(center+Vector2.Scale(p,r.size*.5f),color,new Vector2(Mathf.Lerp(uv.x,uv.z,(p.x+1)*.5f),Mathf.Lerp(uv.y,uv.w,(p.y+1)*.5f)));if(i>0)vh.AddTriangle(0,i,i+1);} } } }