using UnityEngine; using System; public enum EasingType{ Linear, Smooth, } public abstract class SomethingTo : MonoBehaviour { private float lerp = 1.0f; private float speed = 1.0f; protected Action update = ActionExtensions.EmptyActionFloat; protected Action callback = ActionExtensions.EmptyAction; protected void Begin(Actionupdate, float interval, Action callback, EasingType easingType = EasingType.Linear){ SetUpdate(update, easingType); this.callback = callback; speed = 1.0f / interval; lerp = 0.0f; } private void SetUpdate(Actionupdate, EasingType easingType){ switch(easingType){ case EasingType.Smooth: this.update = lerp => { update(AnimationCurveExtensions.Smooth01.Evaluate(lerp)); }; break; default: this.update = update; break; } } public void Stop(){ lerp = 1.0f; // update(lerp); // callback(); } void Update(){ if(lerp < 1.0f){ lerp += Time.deltaTime * speed; if(lerp >= 1.0f){ lerp = 1.0f; update(lerp); callback(); }else{ update(lerp); } } } }