public static ICompletable ScaleTo(this Transform This, float target, float duration, IEaser easer = null) => Range(() => This.localScale, new Vector3(target, target, target), duration, easer) .Do(x => This.localScale = x) .AsCompletable();
public static ICompletable RotateTo(this Transform This, Quaternion target, float duration, IEaser easer = null) => Range(() => This.localRotation, target, duration, easer) .Do(x => This.localRotation = x) .AsCompletable();
public static ICompletable WorldRotateTo(this Transform This, Vector3 target, float duration, IEaser easer = null) => Range(() => This.rotation, Quaternion.Euler(target), duration, easer) .Do(x => This.rotation = x) .AsCompletable();
public static ICompletable WorldMoveTo(this Transform This, Vector3 target, float duration, IEaser easer = null) => Range(() => This.position, target, duration, easer) .Do(x => This.position = x) .AsCompletable();
public static IObservable <float> Range(float duration, IEaser easer = null) => new TweenObservable(duration, easer);
public static ICompletable MoveAnchorYTo(this RectTransform This, float target, float duration, IEaser easer = null) => Range(() => This.anchoredPosition.y, target, duration, easer) .Do(y => This.anchoredPosition = This.anchoredPosition.WithY(y)) .AsCompletable();
public TweenVector3ToShiftingTargetCompletable(IReactiveProperty <Vector3> property, IObservable <Vector3> target, float duration, IEaser easer = null) : base(property, target, duration, easer) { }
public TweenObservable(float duration, IEaser easer = null) { _duration = duration; _easer = easer; }
protected TweenWithInitialVelocityObservableBase(Func <T> sourceSelector, Func <T> velocitySelector, T target, float duration, IEaser easer) { _sourceSelector = sourceSelector; _velocitySelector = velocitySelector; _target = target; _duration = duration; _easer = easer ?? Easer.Linear; }
/// <summary> /// Eases values of This observable using given ease function /// </summary> public static IObservable <float> Ease(this IObservable <float> This, IEaser easer) => This.Select(easer.Ease);
public TweenVector2WithInitialVelocityObservable(Func <Vector2> sourceSelector, Func <Vector2> velocitySelector, Vector2 target, float duration, IEaser easer) : base(sourceSelector, velocitySelector, target, duration, easer) { }
/// <summary> /// Eases this value using given easer /// </summary> public static float Ease(this float This, IEaser ease) => ease.Ease(This);
/// <summary> /// Makes this easer animate backwards within the same time span /// </summary> public static IEaser Reversed(this IEaser This) => new Easer(t => This.Ease(1 - t));
/// <summary> /// Makes this easer animate forwards then backwards within the same time span /// </summary> public static IEaser PingPong(this IEaser This) => new Easer(t => This.Ease( t <= 0.5f ? t * 2 : 1 - (t - 0.5f) * 2));
public static IObservable <float> Range(Func <float> selector, float target, float duration, IEaser easer = null) => Observable.Defer(() => { var source = selector(); return(source.IsAlmostEqualTo(target) ? Observable.Return(target) : Range(duration, easer).Lerp(source, target)); });
public static ICompletable FadeOut(this CanvasGroup This, float duration, IEaser easer = null) => Range(() => This.alpha, 0f, duration, easer) .Do(x => This.alpha = x) .AsCompletable();
public static ICompletable MoveAnchorTo(this RectTransform This, Vector2 target, float duration, IEaser easer = null) => Range(() => This.anchoredPosition, target, duration, easer) .Do(x => This.anchoredPosition = x) .AsCompletable();
public static ICompletable TweenColorTo(this Graphic This, Color target, float duration, IEaser easer = null) => Range(() => This.color, target, duration, easer) .Do(x => This.color = x) .AsCompletable();
protected Tween (TweenDescriptor aDescriptor) { _descriptor = aDescriptor; _tweenID = Tweens.Count; _startValue = aDescriptor.fromValue; _endValue = aDescriptor.toValue; _range = GetRange (_startValue, _endValue); if (!aDescriptor.baseOnSpeed) { _duration = aDescriptor.time; } else { _duration = GetDuration (aDescriptor.speed, _startValue, _endValue); } _easer = GetEaser (aDescriptor.easeType); _progress = 0.0f; _delayTimeStamp = Time.timeSinceLevelLoad; _delay = aDescriptor.delay; _yoyo = aDescriptor.yoyo; _loopCount = 0; _loops = aDescriptor.loops; if (_yoyo && _loops == 0) //if its a yoyo effect, the loop will be atleast 1: _loops = 1; _reversing = false; if (aDescriptor.updateMethod != null) UpdateEvent += aDescriptor.updateMethod; if (aDescriptor.completeMethod != null) CompleteEvent += aDescriptor.completeMethod; Tweens.Add (this); TweenController.Singleton.UpdateEvent += Update; Play (); }
protected override ICompletable Tween(IReactiveProperty <Vector3> property, Vector3 target, float duration, Vector3 velocity, IEaser easer) => property.TweenTo(target, duration, () => velocity, easer);