using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace DiamondArrow { [RequireComponent(typeof(CanvasRenderer))] public sealed class ArrowBoard : MaskableGraphic, IPointerClickHandler { public LevelData level; public GameSession session; public Action clicked; public int highlight=-1,blocked=-1,blocker=-1; public int TutorialArrow { get; set; } = -1; public float highlightUntil,flashUntil; public bool interactive; Vector2 contentCenter,cachedSize; float enteredAt,step; ArrowMotionPath[] paths; float[] bumpedAt,hitAt,bumpDistance; int[,] occupants; readonly Dictionary exits=new Dictionary(); readonly List moving=new List(90); readonly List highlightLine=new List(90); struct Exit { public float started,duration,distance;public bool smash; } public bool HasActiveExits { get {foreach(var e in exits.Values)if(Now-e.startedPreviewTime>=0?PreviewTime:Time.unscaledTime; protected override void OnEnable(){base.OnEnable();if(level!=null&&occupants==null)Configure(level,session);} public void Configure(LevelData data,GameSession run=null) { TutorialArrow = -1; level=data;session=run;exits.Clear();paths=null;raycastTarget=run!=null;interactive=run!=null;enteredAt=Now; contentCenter=Vector2.one*((level.size-1)*.5f); if(run==null) { Vector2 min=new Vector2(float.MaxValue,float.MaxValue),max=new Vector2(float.MinValue,float.MinValue); foreach(var a in level.arrows){foreach(var c in a.cells){var p=new Vector2(c.x,c.y);min=Vector2.Min(min,p);max=Vector2.Max(max,p);}var h=a.cells[a.cells.Length-1];var prev=a.cells[a.cells.Length-2];var tip=new Vector2(h.x,h.y)+new Vector2(h.x-prev.x,h.y-prev.y)*.22f;min=Vector2.Min(min,tip);max=Vector2.Max(max,tip);}contentCenter=(min+max)*.5f; } bumpedAt=new float[data.arrows.Length];hitAt=new float[data.arrows.Length];bumpDistance=new float[data.arrows.Length];occupants=new int[data.size,data.size]; for(int y=0;y.5f?r.xMax-p.x:d.x<-.5f?p.x-r.xMin:d.y>.5f?r.yMax-p.y:p.y-r.yMin; } public void Flash(int index,int other) { EnsurePaths();blocked=index;blocker=other;flashUntil=Now+.45f;bumpedAt[index]=Now;if(other>=0)hitAt[other]=Now; // Move only up to the first occupied cell, then recoil along the same path. var a=level.arrows[index].cells;var h=a[a.Length-1];var prev=a[a.Length-2];int dx=h.x-prev.x,dy=h.y-prev.y;int gap=1; for(int x=h.x+dx,y=h.y+dy;x>=0&&y>=0&&x RoundedPath(ArrowData arrow) { var src=new List();foreach(var c in arrow.cells)src.Add(Point(c));var output=new List{src[0]}; for(int i=1;i.99f){output.Add(src[i]);continue;} float radius=step*.36f;var a=src[i]-incoming*radius;var b=src[i]+outgoing*radius;output.Add(a); for(int k=1;k<=12;k++){float t=k/12f;output.Add((1-t)*(1-t)*a+2*(1-t)*t*src[i]+t*t*b);} } output.Add(src[src.Count-1]);return output; } protected override void OnPopulateMesh(VertexHelper vh) { vh.Clear();if(level==null||occupants==null)return;EnsurePaths();float now=Now; for(int x=0;x=0&&exits.TryGetValue(owner,out var ex)) { var path=paths[owner];float cellDistance=0;float best=float.MaxValue;var point=Point(new Cell(x,y)); for(int p=0;p=0)pulse=Mathf.Exp(-age*6)*Mathf.Sin(Mathf.Min(1,age*8)*Mathf.PI*.5f); } Circle(vh,Point(new Cell(x,y)),1.2f+pulse*step*.065f,new Color(.63f,.58f,.8f,.18f+pulse*.36f)); } float pulseStrength = TutorialArrow >= 0 ? .5f - .5f * Mathf.Cos((now - enteredAt) * 4f) : 0f; for(int i=0;i=exit.duration))continue; var path=paths[i];float alpha=session==null?1:Mathf.Clamp01((now-enteredAt-i*.008f)/.25f); Color color=Neon.ArrowColors[i%8];float blockedAge=now-bumpedAt[i]; if(blockedAge<1.7f)color=Color.Lerp(color,new Color(1,.13f,.25f),1-Mathf.SmoothStep(0,1,(blockedAge-.65f)/1.05f)); if(now-hitAt[i]<.32f)color=Color.Lerp(color,Color.white,Mathf.Exp(-(now-hitAt[i])*10)); if(exiting&&exit.smash){DrawFragments(vh,path,color,age,exit.duration,i);continue;} float travel=exiting?ArrowMotionPath.Travel(age,exit.duration,exit.distance):ArrowMotionPath.Bump(blockedAge,bumpDistance[i]); path.Window(travel,moving); if(exiting) { // A faint afterimage follows the same track; the arrow itself keeps its length. path.Window(ArrowMotionPath.Travel(Mathf.Max(0,age-.035f),exit.duration,exit.distance),highlightLine); Stroke(vh,highlightLine,step*.23f,new Color(color.r,color.g,color.b,.10f),true); alpha*=1-Mathf.SmoothStep(0,1,(age/exit.duration-.91f)/.09f); } float width=step*.235f; bool guided = i == TutorialArrow; if (guided) { color = new Color(1f, .70f, .15f); width *= 1.12f; Stroke(vh, moving, width + step * (.16f + .06f * pulseStrength), new Color(1f, .58f, .08f, alpha * .32f), true); Stroke(vh, moving, width + step * .085f, new Color(1f, .92f, .60f, alpha), true); } else if (TutorialArrow >= 0) alpha *= .28f; if(i==highlight&&nowstart&&path.Distances[i]0){int v=first+1+i*2;vh.AddTriangle(first,v-2,v);vh.AddTriangle(v-2,v-1,v);vh.AddTriangle(v-1,v+1,v);}} } static void Stroke(VertexHelper vh,IList points,float width,Color color,bool antialias) { if(points.Count<2)return;int first=vh.currentVertCount;var clear=new Color(color.r,color.g,color.b,0);int stride=antialias?4:2; for(int i=0;i0)for(int j=0;j=0&&distance