using UnityEngine; using UnityEngine.UI; namespace Fateforge { // Deterministic presentation geometry; driven by the settlement clock, never gameplay RNG. [RequireComponent(typeof(RectTransform),typeof(CanvasRenderer))] public sealed class ScoreStreaks : MaskableGraphic { const int Count=78; readonly Vector2[] origins=new Vector2[Count]; readonly Vector2[] controls=new Vector2[Count]; readonly Vector2[] destinations=new Vector2[Count]; readonly float[] delays=new float[Count],durations=new float[Count],tails=new float[Count]; float progress; bool configured; protected override void Awake(){base.Awake();raycastTarget=false;} public void Configure(Vector2[] starts,Vector2 end) { raycastTarget=false;progress=0;configured=starts!=null&&starts.Length>0; if(configured)for(int i=0;i.5f?1:-1; controls[i]=Vector2.Lerp(origins[i],destinations[i],.48f)+new Vector2(side*(22+Noise(i,6)*Mathf.Min(150,distance*.3f)),30+Noise(i,7)*Mathf.Min(100,distance*.22f)); delays[i]=Noise(i,8)*.21f;durations[i]=.55f+Noise(i,9)*.12f;tails[i]=.04f+Noise(i,10)*.04f; } SetVerticesDirty(); } public void Sample(float value) {progress=Mathf.Clamp01(value);SetVerticesDirty();} protected override void OnPopulateMesh(VertexHelper mesh) { mesh.Clear();if(!configured||progress<=0||progress>=1)return; for(int i=0;i=1)continue; float head=1-Mathf.Pow(1-age,1.45f),tail=Mathf.Max(0,head-tails[i]); Vector2 a=Arc(origins[i],controls[i],destinations[i],tail),b=Arc(origins[i],controls[i],destinations[i],head); float opacity=Mathf.Clamp01(age*14)*Mathf.Clamp01((1-age)*8)*color.a; Stroke(mesh,a,b,5.5f,new Color(1,.50f,.08f,opacity*.08f),new Color(1,.65f,.14f,opacity*.15f)); Stroke(mesh,a,b,3.8f,new Color(1,.65f,.12f,opacity*.03f),new Color(1,.79f,.32f,opacity*.24f)); Stroke(mesh,a,b,1.3f,new Color(1,.73f,.18f,opacity*.10f),new Color(1,.95f,.72f,opacity)); } } static Vector2 Arc(Vector2 start,Vector2 control,Vector2 end,float t) {float inverse=1-t;return inverse*inverse*start+2*inverse*t*control+t*t*end;} static void Stroke(VertexHelper mesh,Vector2 tail,Vector2 head,float width,Color tailColor,Color headColor) { var delta=head-tail;if(delta.sqrMagnitude<.01f)return; Vector2 normal=new Vector2(-delta.y,delta.x).normalized*width*.5f;int first=mesh.currentVertCount; mesh.AddVert(tail-normal,tailColor,Vector2.zero);mesh.AddVert(tail+normal,tailColor,Vector2.zero); mesh.AddVert(head+normal,headColor,Vector2.zero);mesh.AddVert(head-normal,headColor,Vector2.zero); mesh.AddTriangle(first,first+1,first+2);mesh.AddTriangle(first,first+2,first+3); } static float Noise(int index,int salt) { unchecked{uint value=(uint)(index*747796405+salt*2891336453L);value=((value>>((int)(value>>28)+4))^value)*277803737u;value=(value>>22)^value;return (value&0x00ffffff)/16777215f;} } } }