using UnityEngine; using UnityEngine.UI; using TMPro; namespace HexaCrazy { public static class HexEase { public static float Bezier(float x,float x1,float y1,float x2,float y2) { if(x<=0)return 0;if(x>=1)return 1;float lo=0,hi=1,t=0; for(int i=0;i<12;i++){t=(lo+hi)*.5f;float u=1-t;if(3*u*u*t*x1+3*u*t*t*x2+t*t*t();graphic.raycastTarget=false;graphic.Ring=ring;graphic.color=HexUI.Gold;return graphic;} } public sealed class HexFloatingFeedback : MonoBehaviour { public HexGameApp owner;public float duration=.8f;public bool ring,reduced; RectTransform rect;CanvasGroup group;Vector2 origin;float time; void Awake(){rect=(RectTransform)transform;origin=rect.anchoredPosition;group=gameObject.AddComponent();group.blocksRaycasts=false;group.alpha=0;} void Update() { if(owner==null||owner.Paused)return;time+=Time.unscaledDeltaTime;float p=Mathf.Clamp01(time/duration); if(ring){rect.localScale=Vector3.one*Mathf.Lerp(.4f,6.4f,1-Mathf.Pow(1-p,2));group.alpha=(1-p)*.95f;} else { group.alpha=p<.22f?p/.22f:1-(p-.22f)/.78f; if(!reduced){rect.anchoredPosition=origin+Vector2.up*(55*p);rect.localScale=Vector3.one*(p<.22f?Mathf.Lerp(.7f,1.12f,p/.22f):Mathf.Lerp(1.12f,1,(p-.22f)/.78f));} } if(p>=1)Destroy(gameObject); } } public sealed class HexScoreBar : MonoBehaviour { HexGameApp owner;HexProgress fill;TextMeshProUGUI label;RectTransform head;float shown,start,elapsed=1,clock,hit;int target,limit; public float DisplayedScore=>shown;public int TargetScore=>target;public bool IsAnimating=>elapsed<.5f; public void Initialize(HexGameApp app,HexProgress progress,TextMeshProUGUI score,int max) { owner=app;fill=progress;label=score;limit=max;fill.FeedbackStyle=true; for(int i=1;i<=3;i++)HexUI.Image(transform,"QuarterMark"+i,null,8+330*i/4f,14,1.4f,15,new Color(.18f,.05f,.01f,.4f)); head=HexUI.Node(transform,"ProgressHead",8,14,30,30);HexRadial.Create(head,"Glow",15,15,30);var core=HexRadial.Create(head,"Core",15,15,16);core.color=HexUI.Cream; SetScore(0,true);Refresh(); } public void SetScore(int score,bool immediate=false,bool pulse=false) { if(score!=target){target=score;start=shown;elapsed=0;} if(immediate){shown=target;elapsed=.5f;} if(pulse)hit=.62f;Refresh(); } public Vector2 HeadDesignPosition => owner.ScreenToDesign(RectTransformUtility.WorldToScreenPoint(null,head.position)); void Update() { if(owner==null||owner.Paused)return;float dt=Time.unscaledDeltaTime;elapsed=Mathf.Min(.5f,elapsed+dt);clock+=dt;hit=Mathf.Max(0,hit-dt); shown=Mathf.Lerp(start,target,HexEase.Bezier(elapsed/.5f,.25f,.9f,.25f,1));Refresh(); } void Refresh() { float fraction=Mathf.Clamp01(shown/Mathf.Max(1,limit));fill.Value=fraction; fill.Shine=owner.Profile.Data.reduceMotion?-1:((clock%2.1f)/2.1f/.55f)*1.5f-.45f; float flash=owner.Profile.Data.reduceMotion?0:Mathf.Sin((1-hit/.62f)*Mathf.PI)*Mathf.Clamp01(hit/.25f); fill.Flash=flash;transform.localScale=Vector3.one*(1+.035f*flash); head.gameObject.SetActive(fraction>.002f);head.anchoredPosition=new Vector2(8+330*fraction,-14); head.localScale=Vector3.one*(owner.Profile.Data.reduceMotion?1:1+.15f*Mathf.Sin(clock*Mathf.PI*2/1.3f)+flash*.35f); label.text=Mathf.RoundToInt(shown)+" / "+limit; } } }