void Smoothen(float f, float t, Action onDone, float delay = 0f) { // duration will be 1/2 of the ping pong duration _smoother = new InterpolationFloat( new Timing(_options.Duration.Half(), delay), f, t, true ); _smoother.OnLerp += c => Current?.Invoke(c); _smoother.OnDone += () => { _smoother = null; onDone(); }; }
public static InterpolationFloat BezierMove(BezierMoveOptions options) { var tw = new InterpolationFloat(0f, 1f, options.Duration, options.Delay); tw.OnLerp += t => { Vector2 curPos = WBezierCurve.Quadratic( options.From, options.From.LerpWithOffset(options.To, .5f, options.ControlPoint), options.To, t ); options.CurPos?.Invoke(curPos); }; tw.OnDone += () => { options.OnDone?.Invoke(); }; return(tw); }
public WTweenProjectile Launch() { if (_isLaunching) { return(this); } _isLaunching = true; _curPos = _options.From; _lerper = new InterpolationFloat(0f, 1f, _options.Duration, _options.StartDelay); _lerper.OnLerp += t => { float parabola = 1.0f - 4.0f * (t - 0.5f) * (t - 0.5f); Vector2 nextPos = Vector2.Lerp(_options.From, _options.To, t); nextPos.y += parabola * _options.ArcHeight; _options.OnLaunching?.Invoke(new LaunchEv { Pos = nextPos, LerpProgress = t }); _curPos = nextPos; }; _lerper.OnDone += () => { _isLaunching = false; _lerper = null; _options.OnDone?.Invoke(); }; _lerper.OnStart += () => { _options.OnStart?.Invoke(); }; return(this); }