using UnityEngine; using UnityEngine.UI; namespace DiamondArrow { [RequireComponent(typeof(CanvasRenderer))] public sealed class NeonPanel : MaskableGraphic { public Color top=new Color(.18f,.025f,.29f), bottom=new Color(.045f,0,.085f), accent=Neon.Pink; public float radius=24; public bool frame=true, stripes; // 0 flat, 1 glass panel, 3 primary button, 4 secondary button, 5 inset board, 6 backdrop. public float surface=1; protected override void OnPopulateMesh(VertexHelper vh) { vh.Clear();Rect r=GetPixelAdjustedRect(); if(material!=null&&material.shader.name=="DiamondArrow/Neon Surface") { float style=frame?surface:stripes?6:0;float pad=frame?4:0;float rad=frame?radius:Mathf.Min(radius,Mathf.Min(r.width,r.height)*.5f); Vector2[] points={new Vector2(r.xMin-pad,r.yMin-pad),new Vector2(r.xMin-pad,r.yMax+pad),new Vector2(r.xMax+pad,r.yMax+pad),new Vector2(r.xMax+pad,r.yMin-pad)}; for(int i=0;i<4;i++){var v=UIVertex.simpleVert;v.position=points[i];v.color=top;v.uv0=new Vector2((points[i].x-r.xMin)/Mathf.Max(1,r.width),(points[i].y-r.yMin)/Mathf.Max(1,r.height));v.uv1=new Vector4(r.width,r.height,rad,style);v.uv2=bottom;v.uv3=accent;vh.AddVert(v);}vh.AddTriangle(0,1,2);vh.AddTriangle(0,2,3);return; } if(frame) { Fill(vh,r,radius,new Color(accent.r,accent.g,accent.b,.18f),new Color(accent.r,accent.g,accent.b,.18f)); r=Inset(r,3);Fill(vh,r,radius,accent,accent*.65f); r=Inset(r,2);Fill(vh,r,radius-2,Color.white,new Color(.24f,.12f,.34f)); r=Inset(r,3);Fill(vh,r,radius-4,new Color(.27f,.12f,.39f),new Color(.8f,.66f,.9f)); r=Inset(r,2);Fill(vh,r,radius-6,accent,accent); r=Inset(r,2); } Fill(vh,r,Mathf.Max(0,radius-(frame?10:0)),top,bottom); if(stripes) for(float y=r.yMin+6;ynew Rect(r.x+p,r.y+p,r.width-2*p,r.height-2*p); static void Quad(VertexHelper vh,Rect r,Color c) { int i=vh.currentVertCount;vh.AddVert(new Vector3(r.xMin,r.yMin),c,Vector2.zero);vh.AddVert(new Vector3(r.xMin,r.yMax),c,Vector2.zero);vh.AddVert(new Vector3(r.xMax,r.yMax),c,Vector2.zero);vh.AddVert(new Vector3(r.xMax,r.yMin),c,Vector2.zero);vh.AddTriangle(i,i+1,i+2);vh.AddTriangle(i,i+2,i+3); } static void Fill(VertexHelper vh,Rect r,float radius,Color top,Color bottom) { radius=Mathf.Clamp(radius,0,Mathf.Min(r.width,r.height)/2);int center=vh.currentVertCount; vh.AddVert(r.center,Color.Lerp(bottom,top,.5f),Vector2.zero); var corners=new[]{new Vector2(r.xMax-radius,r.yMax-radius),new Vector2(r.xMin+radius,r.yMax-radius),new Vector2(r.xMin+radius,r.yMin+radius),new Vector2(r.xMax-radius,r.yMin+radius)}; for(int c=0;c<4;c++)for(int s=0;s<=8;s++) { float a=(c*90+s*90f/8)*Mathf.Deg2Rad;Vector2 p=corners[c]+new Vector2(Mathf.Cos(a),Mathf.Sin(a))*radius;vh.AddVert(p,Color.Lerp(bottom,top,Mathf.InverseLerp(r.yMin,r.yMax,p.y)),Vector2.zero); } for(int i=0;i<36;i++)vh.AddTriangle(center,center+1+i,center+1+(i+1)%36); } } }