| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using UnityEngine;
- using UnityEngine.UI;
- namespace DevilLink2.UI
- {
- // Equal clockwise sectors; angle zero and sector ordering match LuckyWheelScreen.SectorAngle.
- [RequireComponent(typeof(CanvasRenderer))]
- public sealed class WheelGraphic : MaskableGraphic
- {
- private Material aaMaterial;
- protected override void OnEnable()
- {
- aaMaterial=Resources.Load<Material>("DevilLink2WheelAA");
- if(aaMaterial && aaMaterial.shader && aaMaterial.shader.isSupported)material=aaMaterial;
- else {aaMaterial=null;material=null;Debug.LogWarning("Wheel AA material unavailable: using original mesh fallback.");}
- base.OnEnable();
- }
- protected override void OnPopulateMesh(VertexHelper mesh)
- {
- mesh.Clear();var rect=GetPixelAdjustedRect();float r=Mathf.Min(rect.width,rect.height)*.5f;
- if(r<=.0001f)return;
- if(aaMaterial){
- // Measure actual pixel density, including the existing PortraitFrame scale.
- var camera=canvas && canvas.renderMode!=RenderMode.ScreenSpaceOverlay?canvas.worldCamera:null;
- var origin=RectTransformUtility.WorldToScreenPoint(camera,transform.TransformPoint(Vector3.zero));
- float pixels=Mathf.Min(Vector2.Distance(origin,RectTransformUtility.WorldToScreenPoint(camera,transform.TransformPoint(Vector3.right))),Vector2.Distance(origin,RectTransformUtility.WorldToScreenPoint(camera,transform.TransformPoint(Vector3.up))));
- float pad=1.5f/Mathf.Max(.01f,pixels),extent=r+pad,uv=extent/r;
- var center=rect.center;
- mesh.AddVert(center+new Vector2(-extent,-extent),color,new Vector2(-uv,-uv));
- mesh.AddVert(center+new Vector2(-extent,extent),color,new Vector2(-uv,uv));
- mesh.AddVert(center+new Vector2(extent,extent),color,new Vector2(uv,uv));
- mesh.AddVert(center+new Vector2(extent,-extent),color,new Vector2(uv,-uv));
- mesh.AddTriangle(0,1,2);mesh.AddTriangle(0,2,3);return;
- }
- for(int sector=0;sector<8;sector++){
- var shade=UIBuilder.Hex(sector%2==0?"60305D":"38244F");
- // Continuous radial tones plus a soft directional light, never brown sector fills.
- var radii=new[]{0f,.28f,.48f,.68f,.82f,.925f};
- for(int band=0;band<radii.Length-1;band++){
- float inner=radii[band],outer=radii[band+1];
- Arc(mesh,rect.center,r*inner,r*outer,90-sector*45,45,24,SectorColor(shade,inner),SectorColor(shade,outer),true);
- }
- float a=(90-sector*45)*Mathf.Deg2Rad;var direction=new Vector2(Mathf.Cos(a),Mathf.Sin(a));
- var normal=new Vector2(-direction.y,direction.x)*.45f;int n=mesh.currentVertCount;
- mesh.AddVert(rect.center+direction*r*.28f-normal,UIBuilder.Hex("796071"),Vector2.zero);
- mesh.AddVert(rect.center+direction*r*.925f-normal,UIBuilder.Hex("D5BA82"),Vector2.zero);
- mesh.AddVert(rect.center+direction*r*.925f+normal,UIBuilder.Hex("D5BA82"),Vector2.zero);
- mesh.AddVert(rect.center+direction*r*.28f+normal,UIBuilder.Hex("796071"),Vector2.zero);
- mesh.AddTriangle(n,n+1,n+2);mesh.AddTriangle(n,n+2,n+3);
- }
- // Thin inner wire, recessed violet groove, bevel and narrow champagne highlight.
- Arc(mesh,rect.center,r*.925f,r*.932f,90,360,128,UIBuilder.Hex("E8D4AA"),UIBuilder.Hex("AC9061"),true);
- Arc(mesh,rect.center,r*.932f,r*.950f,90,360,128,UIBuilder.Hex("24152F"),UIBuilder.Hex("453047"));
- Arc(mesh,rect.center,r*.950f,r*.975f,90,360,128,UIBuilder.Hex("7D6A60"),UIBuilder.Hex("C4AB80"),true);
- Arc(mesh,rect.center,r*.975f,r*.982f,90,360,128,UIBuilder.Hex("F7E8C7"),UIBuilder.Hex("D8BD8D"),true);
- Arc(mesh,rect.center,r*.982f,r*.992f,90,360,128,UIBuilder.Hex("8D7967"),UIBuilder.Hex("3B283B"));
- Arc(mesh,rect.center,r*.992f,r,90,360,128,UIBuilder.Hex("271A32"),UIBuilder.Hex("130D1C"));
- }
- private static Color SectorColor(Color shade,float radius)
- {
- float light=.40f+.43f*Mathf.Sin(radius/.925f*Mathf.PI)+.08f*radius;
- return Color.Lerp(UIBuilder.Hex("140F23"),shade,light);
- }
- private static Color Lit(Color color,float angle,bool light)
- {
- if(!light)return color;
- float strength=.84f+.16f*(.5f+.5f*Mathf.Cos(angle-135*Mathf.Deg2Rad));
- return new Color(color.r*strength,color.g*strength,color.b*strength,color.a);
- }
- private static void Arc(VertexHelper mesh,Vector2 center,float inner,float outer,float start,float span,int steps,Color inside,Color outside,bool light=false)
- {
- for(int i=0;i<steps;i++){
- float a=(start-span*i/steps)*Mathf.Deg2Rad,b=(start-span*(i+1)/steps)*Mathf.Deg2Rad;
- var x=new Vector2(Mathf.Cos(a),Mathf.Sin(a));var y=new Vector2(Mathf.Cos(b),Mathf.Sin(b));int n=mesh.currentVertCount;
- mesh.AddVert(center+x*inner,Lit(inside,a,light),Vector2.zero);mesh.AddVert(center+x*outer,Lit(outside,a,light),Vector2.zero);
- mesh.AddVert(center+y*outer,Lit(outside,b,light),Vector2.zero);mesh.AddVert(center+y*inner,Lit(inside,b,light),Vector2.zero);
- mesh.AddTriangle(n,n+1,n+2);mesh.AddTriangle(n,n+2,n+3);
- }
- }
- }
- }
|