/* ---------------------------------------------------------------------------------------- */ /// <summary> /// Common constructor logic. /// </summary> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="seconds">Seconds.</param> /// <param name="easingX">Easing x.</param> /// <param name="easingY">Easing y.</param> void Setup(float x, float y, float seconds, EaseFunction ease = null) { _x = x; _y = y; _seconds = seconds; _ease = ease; }
internal bool delayComplete = true; // TRUE when the delay has elapsed or isn't set, also set by Delay extension method (shared by Sequences only for compatibility reasons, otherwise not used) #region Abstracts + Overrideables // Doesn't reset active state, activeId and despawned, since those are only touched by TweenManager // Doesn't reset default values since those are set when Tweener.Setup is called internal virtual void Reset() { timeScale = 1; isBackwards = false; id = null; updateType = UpdateType.Default; isIndependentUpdate = false; onStart = onPlay = onRewind = onUpdate = onComplete = onStepComplete = onKill = null; target = null; isFrom = false; isSpeedBased = false; duration = 0; loops = 1; delay = 0; isRelative = false; customEase = null; isSequenced = false; sequenceParent = null; specialStartupMode = SpecialStartupMode.None; creationLocked = startupDone = playedOnce = false; position = fullDuration = completedLoops = 0; isPlaying = isComplete = false; elapsedDelay = 0; delayComplete = true; // The following are set during a tween's Setup // isRecyclable = DOTween.defaultRecyclable; // autoKill = DOTween.defaultAutoKill; // loopType = DOTween.defaultLoopType; // easeType = DOTween.defaultEaseType; // easeOvershootOrAmplitude = DOTween.defaultEaseOvershootOrAmplitude; // easePeriod = DOTween.defaultEasePeriod }
public UITweenInstance(UITween owner, object obj, float duration, Dictionary <string, float> args, EaseFunction ease) { this.m_Owner = owner; this.m_EaseFunction = ease; this.m_Object = obj; /** Convert secs into ticks **/ this.m_Duration = new TimeSpan(0, 0, 0, 0, (int)(duration * 1000.0f)).Ticks; var clazz = obj.GetType(); m_Fields = new List <UITweenInstanceField>(); foreach (var key in args.Keys) { var prop = clazz.GetMember(key)[0]; if (prop is FieldInfo) { m_Fields.Add(new UITweenInstanceField_ForField(prop as FieldInfo, obj) { End = (float)args[key] }); } else if (prop is PropertyInfo) { m_Fields.Add(new UITweenInstanceField_ForProperty(prop as PropertyInfo, obj) { End = (float)args[key] }); } } }
/* ---------------------------------------------------------------------------------------- */ public MoveTo(Rigidbody2D body, float x, float y, float seconds, EaseFunction easingX = null, EaseFunction easingY = null) { _initPosition = () => { return(new Vector3(body.position.x, body.position.y, 0)); }; _applyPosition = (float pX, float pY, float _) => { body.MovePosition(new Vector2(pX, pY)); }; Setup(x, y, seconds, easingX, easingY); }
/* ---------------------------------------------------------------------------------------- */ public MoveTo(Transform transform, float x, float y, float seconds, EaseFunction easingX = null, EaseFunction easingY = null, bool useLocal = false) { _useLocal = useLocal; SetupTransform(transform, useLocal); Setup(x, y, seconds, easingX, easingY); }
internal virtual void Reset() { this.timeScale = 1f; this.isBackwards = false; this.id = null; this.isIndependentUpdate = false; base.onStart = this.onPlay = this.onRewind = this.onUpdate = this.onComplete = this.onStepComplete = (TweenCallback)(this.onKill = null); this.onWaypointChange = null; this.target = null; this.isFrom = false; this.isBlendable = false; this.isSpeedBased = false; this.duration = 0f; this.loops = 1; this.delay = 0f; this.isRelative = false; this.customEase = null; this.isSequenced = false; this.sequenceParent = null; this.specialStartupMode = SpecialStartupMode.None; this.creationLocked = this.startupDone = this.playedOnce = false; this.position = this.fullDuration = this.completedLoops = 0; this.isPlaying = this.isComplete = false; this.elapsedDelay = 0f; this.delayComplete = true; this.miscInt = -1; }
public AnimateTo(AnimatedFloat value, float to, float seconds, EaseFunction easing = null) { _value = value; _to = to; _seconds = seconds; _easing = easing; }
/* ---------------------------------------------------------------------------------------- */ public AlphaTo(Transform transform, float to, float seconds, EaseFunction easing = null) { _transform = transform; _to = to; _seconds = seconds; _easing = easing; }
/* ---------------------------------------------------------------------------------------- */ public AlphaTo(CanvasGroup canvasGroup, float to, float seconds, EaseFunction easing = null) { _canvasGroup = canvasGroup; _to = to; _seconds = seconds; _easing = easing; }
private void NextEase() { for (int i = 0; i < (nextEaseStepLarge ? 3 : 1); i++) { EaseFunction = EaseFunction.GetNext(); } }
void Awake() { mPointerAnimMoveEaseFunc = EaseManager.ToEaseFunction(Ease.InOutSine); mPointerImageColorDefault = pointerImage.color; mPointerImageColorFadeOut = new Color(mPointerImageColorDefault.r, mPointerImageColorDefault.g, mPointerImageColorDefault.b, 0f); }
private void PrevEase() { for (int i = 0; i < (nextEaseStepLarge ? 3 : 1); i++) { EaseFunction = EaseFunction.GetPrevious(); } }
private AnimationCurve CreateNewEasingCurve(Ease ease, int timesteps) { if (timesteps <= 0) { return(null); } EaseFunction easeFunction = EaseManager.ToEaseFunction(ease); var curve = new AnimationCurve(); // Adds all the required keys for (int i = 0; i < timesteps; i++) { float time = MathfExtensions.Remap(i, 0, timesteps, 0, Duration); var result = EaseManager.Evaluate(ease, easeFunction, time, Duration, EaseOvershoot, EasePeriod); curve.AddKey(time, result); } #if UNITY_EDITOR // Set the tangent mode to Clamped Auto for all keys for (int i = 0; i < curve.length; i++) { var tangentMode = AnimationUtility.TangentMode.Linear; AnimationUtility.SetKeyLeftTangentMode(curve, i, tangentMode); AnimationUtility.SetKeyRightTangentMode(curve, i, tangentMode); } #endif return(curve); }
/* ---------------------------------------------------------------------------------------- */ public RotateTo(Rigidbody2D body, float angle, float seconds, EaseFunction easing = null) { _InitialRotation = () => { return(body.rotation); }; _ApplyRotation = (float d) => body.rotation = d; Setup(angle, seconds, easing); }
/** * Vector3 interpolation using given easing method. Easing is done independently * on all three vector axis. */ public static Vector3 Ease(EaseFunction ease, Vector3 start, Vector3 distance, float elapsedTime, float duration) { start.x = ease(start.x, distance.x, elapsedTime, duration); start.y = ease(start.y, distance.y, elapsedTime, duration); start.z = ease(start.z, distance.z, elapsedTime, duration); return start; }
internal ActionState(float duration, EaseFunction ease) { _duration = duration; this.elapsedTime = 0; _ease = ease; this.status = TweenStatus.NotPrepared; }
/// <summary> /// Animates between the two given values. /// </summary> /// <param name="from">The initial value.</param> /// <param name="to">The target value.</param> /// <param name="seconds">The animation duration, in seconds.</param> /// <param name="easing">The easing function to use, defaults to `Ease.linear`.</param> public void Animate(int from, int to, float seconds, EaseFunction easing = null) { easing = easing == null ? Ease.Linear : easing; _ = from; // set__(from); AnimateTo(to, seconds, easing); }
public virtual void Fire(GameObject objStart, Vector3 endPosition, float duration, string easeName = null) { this.BindGameLoop(); _transStart = objStart.transform; _startUnit = null; _startUnitId = 0; _startPosition = _transStart.position; _startAngle = -1.0f; _transEnd = null; _endUnit = null; _endUnitId = 0; _endPosition = endPosition; _endTeleportFlag = -1; _duration = duration <= 0 ? _duration : duration; _startTime = GetMSTime(); _easeName = string.IsNullOrEmpty(easeName) ? _easeName : easeName; _easeFunc = EaseFunc.GetFunction(easeName); _transform = this.transform; _transform.position = _startPosition; _isEnded = false; _delayTimeCounter = _delayTime; this.OnEffectStart(); }
public AnimateBy(AnimatedFloat value, float by, float seconds, EaseFunction easing = null) { _value = value; _by = by; _seconds = seconds; _easing = easing; }
/** * Vector3 interpolation using given easing method. Easing is done independently * on all three vector axis. */ public static Vector3 Ease(EaseFunction ease, Vector3 start, Vector3 distance, float elapsedTime, float duration) { start.x = ease(start.x, distance.x, elapsedTime, duration); start.y = ease(start.y, distance.y, elapsedTime, duration); start.z = ease(start.z, distance.z, elapsedTime, duration); return(start); }
public virtual void Fire(UBattleUnit startUnit, Vector3 endPosition, float duration, string easeName = null) { this.BindGameLoop(); _transStart = startUnit.GetBoneTransform("missile"); _startUnit = startUnit; _startUnitId = startUnit.unitId; _startPosition = _transStart.position; _startAngle = _startUnit.curDirectionAngle; _transEnd = null; _endUnit = null; _endUnitId = 0; _endPosition = endPosition; _endTeleportFlag = -1; _duration = duration <= 0 ? _duration : duration; _startTime = GetMSTime(); _easeName = string.IsNullOrEmpty(easeName) ? _easeName : easeName; _easeFunc = EaseFunc.GetFunction(easeName); _transform = this.transform; _transform.position = _startPosition; _isEnded = false; _delayTimeCounter = _delayTime; this.OnEffectStart(); }
public TweenValue() { Time = 0; Duration = 0; Function = EaseFunction.Linear; Used = ReadyToRemove = false; }
public Tween(float t, Vector2 b, Vector2 c, float d) { time = t; begin = b; change = c; duration = d; function = EaseFunction.Linear; }
public UITweenInstanceMembers(UITween owner, object obj, float duration, Dictionary <string, float> args, EaseFunction ease) { Owner = owner; TargetObject = obj; Duration = duration; Arguments = args; Ease = ease; }
public void Move(Vector2 change, float duration, EaseFunction function = EaseFunction.Linear) { Begin = Owner.Position; Change = new Vector2(change.X - Owner.Position.X, change.Y - Owner.Position.Y); Duration = duration; Function = function; Time = 0; }
/* ---------------------------------------------------------------------------------------- */ /// <summary> /// Common constructor logic. /// </summary> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="seconds">Seconds.</param> /// <param name="easingX">Easing x.</param> /// <param name="easingY">Easing y.</param> void Setup(float x, float y, float seconds, EaseFunction easingX = null, EaseFunction easingY = null) { _scaleX = x; _scaleY = y; _seconds = seconds; _easingX = easingX; _easingY = easingY; }
/// <summary>Sets the ease of the tween. /// <para>If applied to Sequences eases the whole sequence animation</para></summary> /// <param name="overshootOrAmplitude">Eventual overshoot or amplitude to use with Back or Elastic easeType (default is 1.70158)</param> /// <param name="period">Eventual period to use with Elastic easeType (default is 0)</param> public TweenParams SetEase(Ease ease, float?overshootOrAmplitude = null, float?period = null) { this.easeType = ease; this.easeOvershootOrAmplitude = overshootOrAmplitude != null ? (float)overshootOrAmplitude : DOTween.defaultEaseOvershootOrAmplitude; this.easePeriod = period != null ? (float)period : DOTween.defaultEasePeriod; this.customEase = null; return(this); }
public void Move(Vector2 _change, float _duration, EaseFunction _function = EaseFunction.Linear) { Begin = Owner.Position; Change = new Vector2(_change.X - Owner.Position.X, _change.Y - Owner.Position.Y); Duration = _duration; Function = _function; Time = 0; }
public TweenParams SetEase(Ease ease, float?overshootOrAmplitude, float?period) { this.easeType = ease; this.easeOvershootOrAmplitude = overshootOrAmplitude.HasValue ? overshootOrAmplitude.Value : DOTween.defaultEaseOvershootOrAmplitude; this.easePeriod = period.HasValue ? period.Value : DOTween.defaultEasePeriod; this.customEase = null; return(this); }
public virtual void Dispose() { mActive = false; mKill = true; mOnBeginPlay = mOnComplete = mOnKill = mOnLoopComplete = null; mEaseFunction = null; mEaseCurve = null; }
/* ---------------------------------------------------------------------------------------- */ public ColorTo(Color start, Color to, float seconds, Action <Color> updateDelegate, EaseFunction easing = null) { _from = start; _to = to; _seconds = seconds; _easing = easing; _updateDelegate = updateDelegate; }
/** * Generic easing sequence generator used to implement the time and * slice variants. Normally you would not use this function directly. */ public static IEnumerator NewEase(EaseFunction ease, Vector3 start, Vector3 end, float total, IEnumerator driver) { Vector3 distance = end - start; while(driver.MoveNext()) { yield return Ease(ease, start, distance, (float)driver.Current, total); } }
/// <summary> /// Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS /// </summary> /// <param name="motionFps">FPS at which the tween should be played</param> /// <param name="customEase">Custom ease function to use</param> public static EaseFunction StopMotion(int motionFps, EaseFunction customEase) { // Compute the time interval in which we must re-evaluate the value float motionDelay = 1.0f / motionFps; return delegate(float time, float duration, float overshootOrAmplitude, float period) { // Adjust the time so it's in steps float steptime = time < duration ? time - (time % motionDelay) : time; // Evaluate the ease value based on the new step time return customEase(steptime, duration, overshootOrAmplitude, period); }; }
/// <summary> /// Initializes a new instance of the <see cref="RotateTo2DGameAction"/> class. /// </summary> /// <param name="entity">The target entity</param> /// <param name="to">The target angle</param> /// <param name="time">Animation duration</param> /// <param name="ease">The ease function</param> /// <param name="local">If the rotation is local</param> public RotateTo2DGameAction(Entity entity, float to, TimeSpan time, EaseFunction ease = EaseFunction.None, bool local = false) : base(entity, 0, to, time, ease) { this.local = local; if (local) { this.updateAction = this.LocalRotateAction; } else { this.updateAction = this.RotateAction; } this.transform = entity.FindComponent<Transform2D>(); }
/// <summary> /// Initializes a new instance of the <see cref="MoveTo2DGameAction"/> class. /// </summary> /// <param name="entity">The target entity</param> /// <param name="to">The target position</param> /// <param name="time">Animation duration</param> /// <param name="ease">The ease function</param> /// <param name="local">If the position is in local coordinates.</param> public MoveTo2DGameAction(Entity entity, Vector2 to, TimeSpan time, EaseFunction ease = EaseFunction.None, bool local = false) : base(entity, Vector2.Zero, to, time, ease) { this.local = local; if (local) { this.updateAction = this.LocalMoveAction; } else { this.updateAction = this.MoveAction; } this.transform = entity.FindComponent<Transform2D>(); }
/// <summary> /// Initializes a new instance of the <see cref="ScaleTo3DGameAction"/> class. /// </summary> /// <param name="entity">The target entity</param> /// <param name="to">The target scale</param> /// <param name="time">Animation duration</param> /// <param name="ease">The ease function</param> /// /// <param name="local">If the scale is in local coordinate</param> public ScaleTo3DGameAction(Entity entity, Vector3 to, TimeSpan time, EaseFunction ease = EaseFunction.None, bool local = false) : base(entity, Vector3.Zero, to, time, ease) { this.local = local; if (local) { this.updateAction = this.LocalScaleAction; } else { this.updateAction = this.ScaleAction; } this.transform = entity.FindComponent<Transform3D>(); }
/// <summary>Clears and resets this TweenParams instance using default values, /// so it can be reused without instantiating another one</summary> public TweenParams Clear() { id = target = null; updateType = DOTween.defaultUpdateType; isIndependentUpdate = DOTween.defaultTimeScaleIndependent; onStart = onPlay = onRewind = onUpdate = onStepComplete = onComplete = onKill = null; onWaypointChange = null; isRecyclable = DOTween.defaultRecyclable; isSpeedBased = false; autoKill = DOTween.defaultAutoKill; loops = 1; loopType = DOTween.defaultLoopType; delay = 0; isRelative = false; easeType = Ease.Unset; customEase = null; easeOvershootOrAmplitude = DOTween.defaultEaseOvershootOrAmplitude; easePeriod = DOTween.defaultEasePeriod; return this; }
public GOTween(GameObject target, float duration, EaseFunction easeFunction = null, TweenCallback completeCallback = null, TweenCallback updateCallback = null) { if (easeFunction == null) { m_ease = EaseFunctions.LinearNone; } else { m_ease = easeFunction; } m_target = target; m_duration = duration; m_elapsed = 0.0f; m_completeCallback = completeCallback; m_updateCallback = updateCallback; }
/** * Generic bezier spline sequence generator used to implement the time and * slice variants. Normally you would not use this function directly. */ public static IEnumerator NewBezier(EaseFunction ease, Vector3[] nodes, PositionToPositionFunction toVector3 , float maxStep, IEnumerator steps) { // need at least two nodes to spline between if (nodes.Length >= 2) { // copy nodes array since Bezier is destructive Vector3[] points = new Vector3[nodes.Length]; while(steps.MoveNext()) { // re-initialize copy before each destructive call to Bezier for(int i = 0; i < nodes.Length; i++) { points[i] = toVector3(nodes[i]); } yield return Bezier(ease, points, (float)steps.Current, maxStep); // make sure last value is always generated } } }
/** * A Vector3[] variation of the Transform[] NewBezier() function. * Same functionality but using Vector3s to define bezier curve. */ public static IEnumerator NewBezier(EaseFunction ease, Vector3[] points, int slices) { IEnumerator counter = NewCounter(0, slices + 1, 1); return NewBezier(ease, points, Identity, slices + 1, counter); }
/** * A Vector3[] variation of the Transform[] NewBezier() function. * Same functionality but using Vector3s to define bezier curve. */ public static IEnumerator NewBezier(EaseFunction ease, Vector3[] points, float duration) { IEnumerator timer = NewTimer(duration); return NewBezier(ease, points, Identity, duration, timer); }
/** * Instead of interpolating based on time, generate n interpolated points * (slices) between the first and last node. */ public static IEnumerator NewBezier(EaseFunction ease, Transform[] nodes, int slices) { IEnumerator counter = NewCounter(0, slices + 1, 1); return NewBezier(ease, nodes, TransformDotPosition, slices + 1, counter); }
/// <summary>Sets the ease of the tween using an AnimationCurve. /// <para>If applied to Sequences eases the whole sequence animation</para></summary> public TweenParams SetEase(AnimationCurve animCurve) { this.easeType = Ease.INTERNAL_Custom; this.customEase = new EaseCurve(animCurve).Evaluate; return this; }
public UITweenInstance(UITween owner, object obj, float duration, Dictionary<string, float> args, EaseFunction ease) { this.m_Owner = owner; this.m_EaseFunction = ease; this.m_Object = obj; /** Convert secs into ticks **/ this.m_Duration = new TimeSpan(0, 0, 0, 0, (int)(duration * 1000.0f)).Ticks; var clazz = obj.GetType(); m_Fields = new List<UITweenInstanceField>(); foreach (var key in args.Keys) { var prop = clazz.GetMember(key)[0]; if(prop is FieldInfo){ m_Fields.Add(new UITweenInstanceField_ForField(prop as FieldInfo, obj) { End = (float)args[key] }); } else if (prop is PropertyInfo) { m_Fields.Add(new UITweenInstanceField_ForProperty(prop as PropertyInfo, obj) { End = (float)args[key] }); } } }
/** * Instead of easing based on time, generate n interpolated points (slices) * between the start and end positions. */ public static IEnumerator NewEase(EaseFunction ease, Vector3 start, Vector3 end, int slices) { IEnumerator counter = NewCounter(0, slices + 1, 1); return NewEase(ease, start, end, slices + 1, counter); }
/// <summary> /// Delta Function method /// </summary> /// <param name="function"></param> /// <param name="from">Start value</param> /// <param name="to">End value</param> /// <param name="time">Current time</param> /// <param name="totalTime">Animation duration</param> /// <returns>Delta value</returns> public Quaternion DeltaFunction(EaseFunction function, Quaternion from, Quaternion to, float time, float totalTime) { Quaternion delta = Quaternion.Identity; switch (this.easeFunction) { case EaseFunction.BackInEase: delta = this.BackInEase(time, from, to, totalTime); break; case EaseFunction.BackInOutEase: delta = this.BackInOutEase(time, from, to, totalTime); break; case EaseFunction.BackOutEase: delta = this.BackOutEase(time, from, to, totalTime); break; case EaseFunction.BounceInEase: delta = this.BounceInEase(time, from, to, totalTime); break; case EaseFunction.BounceOutEase: delta = this.BounceOutEase(time, from, to, totalTime); break; case EaseFunction.BounceInOutEase: delta = this.BounceInOutEase(time, from, to, totalTime); break; case EaseFunction.CircleInEase: delta = this.CircleInEase(time, from, to, totalTime); break; case EaseFunction.CircleOutEase: delta = this.CircleOutEase(time, from, to, totalTime); break; case EaseFunction.CircleInOutEase: delta = this.CircleInOutEase(time, from, to, totalTime); break; case EaseFunction.CubicInEase: delta = this.CubicInEase(time, from, to, totalTime); break; case EaseFunction.CubicOutEase: delta = this.CubitOutEase(time, from, to, totalTime); break; case EaseFunction.CubicInOutEase: delta = this.CubicInOutEase(time, from, to, totalTime); break; case EaseFunction.ElasticInEase: delta = this.ElasticInEase(time, from, to, totalTime); break; case EaseFunction.ElasticOutEase: delta = this.ElasticOutEase(time, from, to, totalTime); break; case EaseFunction.ElasticInOutEase: delta = this.ElasticInOutEase(time, from, to, totalTime); break; case EaseFunction.ExponentialInEase: delta = this.ExponentialInEase(time, from, to, totalTime); break; case EaseFunction.ExponentialOutEase: delta = this.ExponentialOutEase(time, from, to, totalTime); break; case EaseFunction.ExponentialInOutEase: delta = this.ExponentialInOutEase(time, from, to, totalTime); break; case EaseFunction.QuadraticInEase: delta = this.QuadraticInEase(time, from, to, totalTime); break; case EaseFunction.QuadraticOutEase: delta = this.QuadraticOutEase(time, from, to, totalTime); break; case EaseFunction.QuadraticInOutEase: delta = this.QuadraticInOutEase(time, from, to, totalTime); break; case EaseFunction.QuarticInEase: delta = this.QuarticInEase(time, from, to, totalTime); break; case EaseFunction.QuarticOutEase: delta = this.QuarticOutEase(time, from, to, totalTime); break; case EaseFunction.QuarticInOutEase: delta = this.QuarticInOutEase(time, from, to, totalTime); break; case EaseFunction.QuinticInEase: delta = this.QuinticInEase(time, from, to, totalTime); break; case EaseFunction.QuinticOutEase: delta = this.QuinticOutEase(time, from, to, totalTime); break; case EaseFunction.QuinticInOutEase: delta = this.QuinticInOutEase(time, from, to, totalTime); break; case EaseFunction.SineInEase: delta = this.SineInEase(time, from, to, totalTime); break; case EaseFunction.SineOutEase: delta = this.SineOutEase(time, from, to, totalTime); break; case EaseFunction.SineInOutEase: delta = this.SineInOutEase(time, from, to, totalTime); break; case EaseFunction.None: delta = this.LinearStep(time, from, to, totalTime); break; } return delta; }
/// <summary> /// Delta Function method /// </summary> /// <param name="function"></param> /// <param name="from">Start value</param> /// <param name="to">End value</param> /// <param name="time">Current time</param> /// <param name="totalTime">Animation duration</param> /// <returns>Delta value</returns> public Vector3 DeltaFunction(EaseFunction function, Vector3 from, Vector3 to, float time, float totalTime) { Vector3 delta = Vector3.Zero; switch (this.easeFunction) { case EaseFunction.BackInEase: delta = this.BackInEase(time, from, to, totalTime); break; case EaseFunction.BackInOutEase: delta = this.BackInOutEase(time, from, to, totalTime); break; case EaseFunction.BackOutEase: delta = this.BackOutEase(time, from, to, totalTime); break; case EaseFunction.BounceInEase: delta = this.BounceInEase(time, from, to, totalTime); break; case EaseFunction.BounceOutEase: delta = this.BounceOutEase(time, from, to, totalTime); break; case EaseFunction.BounceInOutEase: delta = this.BounceInOutEase(time, from, to, totalTime); break; case EaseFunction.CircleInEase: delta = this.CircleInEase(time, from, to, totalTime); break; case EaseFunction.CircleOutEase: delta = this.CircleOutEase(time, from, to, totalTime); break; case EaseFunction.CircleInOutEase: delta = this.CircleInOutEase(time, from, to, totalTime); break; case EaseFunction.CubicInEase: delta = this.CubicInEase(time, from, to, totalTime); break; case EaseFunction.CubicOutEase: delta = this.CubitOutEase(time, from, to, totalTime); break; case EaseFunction.CubicInOutEase: delta = this.CubicInOutEase(time, from, to, totalTime); break; case EaseFunction.ElasticInEase: delta = this.ElasticInEase(time, from, to, totalTime); break; case EaseFunction.ElasticOutEase: delta = this.ElasticOutEase(time, from, to, totalTime); break; case EaseFunction.ElasticInOutEase: delta = this.ElasticInOutEase(time, from, to, totalTime); break; case EaseFunction.ExponentialInEase: delta = this.ExponentialInEase(time, from, to, totalTime); break; case EaseFunction.ExponentialOutEase: delta = this.ExponentialOutEase(time, from, to, totalTime); break; case EaseFunction.ExponentialInOutEase: delta = this.ExponentialInOutEase(time, from, to, totalTime); break; case EaseFunction.QuadraticInEase: delta = this.QuadraticInEase(time, from, to, totalTime); break; case EaseFunction.QuadraticOutEase: delta = this.QuadraticOutEase(time, from, to, totalTime); break; case EaseFunction.QuadraticInOutEase: delta = this.QuadraticInOutEase(time, from, to, totalTime); break; case EaseFunction.QuarticInEase: delta = this.QuarticInEase(time, from, to, totalTime); break; case EaseFunction.QuarticOutEase: delta = this.QuarticOutEase(time, from, to, totalTime); break; case EaseFunction.QuarticInOutEase: delta = this.QuarticInOutEase(time, from, to, totalTime); break; case EaseFunction.QuinticInEase: delta = this.QuinticInEase(time, from, to, totalTime); break; case EaseFunction.QuinticOutEase: delta = this.QuinticOutEase(time, from, to, totalTime); break; case EaseFunction.QuinticInOutEase: delta = this.QuinticInOutEase(time, from, to, totalTime); break; case EaseFunction.SineInEase: delta = this.SineInEase(time, from, to, totalTime); break; case EaseFunction.SineOutEase: delta = this.SineOutEase(time, from, to, totalTime); break; case EaseFunction.SineInOutEase: delta = this.SineInOutEase(time, from, to, totalTime); break; case EaseFunction.None: delta = this.LinearStep(time, from, to, totalTime); break; } return delta; }
public BaseTween Easing(EaseFunction f) { easing = Mathfl.GetEaseFunction(f); return (this); }
/// <summary>Sets the ease of the tween. /// <para>If applied to Sequences eases the whole sequence animation</para></summary> /// <param name="overshootOrAmplitude">Eventual overshoot or amplitude to use with Back or Elastic easeType (default is 1.70158)</param> /// <param name="period">Eventual period to use with Elastic easeType (default is 0)</param> public TweenParams SetEase(Ease ease, float? overshootOrAmplitude = null, float? period = null) { this.easeType = ease; this.easeOvershootOrAmplitude = overshootOrAmplitude != null ? (float)overshootOrAmplitude : DOTween.defaultEaseOvershootOrAmplitude; this.easePeriod = period != null ? (float)period : DOTween.defaultEasePeriod; this.customEase = null; return this; }
/// <summary> /// Initializes a new instance of the <see cref="QuaternionAnimationGameAction"/> class. /// </summary> /// <param name="entity">The entity</param> /// <param name="from">Initial value</param> /// <param name="to">End value</param> /// <param name="time">The time of the animation</param> /// <param name="ease">Easing function</param> protected QuaternionAnimationGameAction(Entity entity, Quaternion from, Quaternion to, TimeSpan time, EaseFunction ease) : this(entity, from, to, time, ease, null) { }
/** * A Vector3 n-degree bezier spline. * * WARNING: The points array is modified by Bezier. See NewBezier() for a * safe and user friendly alternative. * * You can pass zero control points, just the start and end points, for just * plain easing. In other words a zero-degree bezier spline curve is just the * easing method. * * @param points start point, n control points, end point */ public static Vector3 Bezier(EaseFunction ease, Vector3[] points, float elapsedTime, float duration) { // Reference: http://ibiblio.org/e-notes/Splines/Bezier.htm // Interpolate the n starting points to generate the next j = (n - 1) points, // then interpolate those n - 1 points to generate the next n - 2 points, // continue this until we have generated the last point (n - (n - 1)), j = 1. // We store the next set of output points in the same array as the // input points used to generate them. This works because we store the // result in the slot of the input point that is no longer used for this // iteration. for(int j = points.Length - 1; j > 0; j--) { for(int i = 0; i < j; i++) { points[i].x = ease(points[i].x, points[i + 1].x - points[i].x, elapsedTime, duration); points[i].y = ease(points[i].y, points[i + 1].y - points[i].y, elapsedTime, duration); points[i].z = ease(points[i].z, points[i + 1].z - points[i].z, elapsedTime, duration); } } return points[0]; }
/// <summary> /// Initializes a new instance of the <see cref="QuaternionAnimationGameAction"/> class. /// </summary> /// <param name="updateAction">The action when needs to be updated</param> /// <param name="entity">The entity</param> /// <param name="from">Initial value</param> /// <param name="to">End value</param> /// <param name="ease">Easing function</param> /// <param name="time">The time of the animation</param> public QuaternionAnimationGameAction(Entity entity, Quaternion from, Quaternion to, TimeSpan time, EaseFunction ease, Action<Quaternion> updateAction) : base("QuaternionAnimation" + instances++, entity.Scene) { if (entity == null) { throw new ArgumentNullException("entity"); } this.entity = entity; this.totalTime = time; this.from = from; this.to = to; this.easeFunction = ease; this.updateAction = updateAction; }
/** * Returns sequence generator from start to end over duration using the * given easing function. The sequence is generated as it is accessed * using the Time.deltaTime to calculate the portion of duration that has * elapsed. */ public static IEnumerator NewEase(EaseFunction ease, Vector3 start, Vector3 end, float duration) { IEnumerator timer = NewTimer(duration); return NewEase(ease, start, end, duration, timer); }
static public BaseTween.EasingFunction GetEaseFunction(EaseFunction func) { switch (func) { case EaseFunction.InQuad: return easeInQuad; case EaseFunction.InCubic: return easeInCirc; case EaseFunction.InQuartic: return easeInQuart; case EaseFunction.InQuintic: return easeInQuint; case EaseFunction.InSine: return easeInSine; case EaseFunction.InExpo: return easeInExpo; case EaseFunction.InCircular: return easeInCirc; case EaseFunction.InBounce: return easeInBounce; case EaseFunction.InBack: return easeInBack; case EaseFunction.InElastic: return easeInElastic; case EaseFunction.OutQuad: return easeOutQuad; case EaseFunction.OutCubic: return easeOutCubic; case EaseFunction.OutQuartic: return easeOutQuart; case EaseFunction.OutQuintic: return easeOutQuint; case EaseFunction.OutSine: return easeOutSine; case EaseFunction.OutExpo: return easeOutExpo; case EaseFunction.OutCircular: return easeOutCirc; case EaseFunction.OutBounce: return easeOutBounce; case EaseFunction.OutBack: return easeOutBack; case EaseFunction.OutElastic: return easeOutElastic; case EaseFunction.InOutQuad: return easeInOutQuad; case EaseFunction.InOutCubic: return easeInOutCubic; case EaseFunction.InOutQuartic: return easeInOutQuart; case EaseFunction.InOutQuintic: return easeInOutQuint; case EaseFunction.InOutSine: return easeInOutSine; case EaseFunction.InOutExpo: return easeInOutExpo; case EaseFunction.InOutCircular: return easeInOutCirc; case EaseFunction.InOutBounce: return easeInOutBounce; case EaseFunction.InOutBack: return easeInOutBack; case EaseFunction.InOutElastic: return easeInOutElastic; case EaseFunction.None: return null; default: throw new ArgumentOutOfRangeException("func"); } }
/// <summary> /// Initializes a new instance of the <see cref="Vector3AnimationGameAction"/> class. /// </summary> /// <param name="entity">The entity</param> /// <param name="from">Initial value</param> /// <param name="to">End value</param> /// <param name="time">The time of the animation</param> /// <param name="ease">Easing function</param> protected Vector3AnimationGameAction(Entity entity, Vector3 from, Vector3 to, TimeSpan time, EaseFunction ease) : this(entity, from, to, time, ease, null) { }
/** * Returns sequence generator from the first node to the last node over * duration time using the points in-between the first and last node * as control points of a bezier curve used to generate the interpolated points * in the sequence. If there are no control points (ie. only two nodes, first * and last) then this behaves exactly the same as NewEase(). In other words * a zero-degree bezier spline curve is just the easing method. The sequence * is generated as it is accessed using the Time.deltaTime to calculate the * portion of duration that has elapsed. */ public static IEnumerator NewBezier(EaseFunction ease, Transform[] nodes, float duration) { IEnumerator timer = NewTimer(duration); return NewBezier(ease, nodes, TransformDotPosition, duration, timer); }
/// <summary> /// Returns a value between 0 and 1 (inclusive) based on the elapsed time and ease selected /// </summary> public static float Evaluate(Ease easeType, EaseFunction customEase, float time, float duration, float overshootOrAmplitude, float period) { switch (easeType) { case Ease.Linear: return time / duration; case Ease.InSine: return -(float)Math.Cos(time / duration * _PiOver2) + 1; case Ease.OutSine: return (float)Math.Sin(time / duration * _PiOver2); case Ease.InOutSine: return -0.5f * ((float)Math.Cos(Mathf.PI * time / duration) - 1); case Ease.InQuad: return (time /= duration) * time; case Ease.OutQuad: return -(time /= duration) * (time - 2); case Ease.InOutQuad: if ((time /= duration * 0.5f) < 1) return 0.5f * time * time; return -0.5f * ((--time) * (time - 2) - 1); case Ease.InCubic: return (time /= duration) * time * time; case Ease.OutCubic: return ((time = time / duration - 1) * time * time + 1); case Ease.InOutCubic: if ((time /= duration * 0.5f) < 1) return 0.5f * time * time * time; return 0.5f * ((time -= 2) * time * time + 2); case Ease.InQuart: return (time /= duration) * time * time * time; case Ease.OutQuart: return -((time = time / duration - 1) * time * time * time - 1); case Ease.InOutQuart: if ((time /= duration * 0.5f) < 1) return 0.5f * time * time * time * time; return -0.5f * ((time -= 2) * time * time * time - 2); case Ease.InQuint: return (time /= duration) * time * time * time * time; case Ease.OutQuint: return ((time = time / duration - 1) * time * time * time * time + 1); case Ease.InOutQuint: if ((time /= duration * 0.5f) < 1) return 0.5f * time * time * time * time * time; return 0.5f * ((time -= 2) * time * time * time * time + 2); case Ease.InExpo: return (time == 0) ? 0 : (float)Math.Pow(2, 10 * (time / duration - 1)); case Ease.OutExpo: if (time == duration) return 1; return (-(float)Math.Pow(2, -10 * time / duration) + 1); case Ease.InOutExpo: if (time == 0) return 0; if (time == duration) return 1; if ((time /= duration * 0.5f) < 1) return 0.5f * (float)Math.Pow(2, 10 * (time - 1)); return 0.5f * (-(float)Math.Pow(2, -10 * --time) + 2); case Ease.InCirc: return -((float)Math.Sqrt(1 - (time /= duration) * time) - 1); case Ease.OutCirc: return (float)Math.Sqrt(1 - (time = time / duration - 1) * time); case Ease.InOutCirc: if ((time /= duration * 0.5f) < 1) return -0.5f * ((float)Math.Sqrt(1 - time * time) - 1); return 0.5f * ((float)Math.Sqrt(1 - (time -= 2) * time) + 1); case Ease.InElastic: float s0; if (time == 0) return 0; if ((time /= duration) == 1) return 1; if (period == 0) period = duration * 0.3f; if (overshootOrAmplitude < 1) { overshootOrAmplitude = 1; s0 = period / 4; } else s0 = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude); return -(overshootOrAmplitude * (float)Math.Pow(2, 10 * (time -= 1)) * (float)Math.Sin((time * duration - s0) * _TwoPi / period)); case Ease.OutElastic: float s1; if (time == 0) return 0; if ((time /= duration) == 1) return 1; if (period == 0) period = duration * 0.3f; if (overshootOrAmplitude < 1) { overshootOrAmplitude = 1; s1 = period / 4; } else s1 = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude); return (overshootOrAmplitude * (float)Math.Pow(2, -10 * time) * (float)Math.Sin((time * duration - s1) * _TwoPi / period) + 1); case Ease.InOutElastic: float s; if (time == 0) return 0; if ((time /= duration * 0.5f) == 2) return 1; if (period == 0) period = duration * (0.3f * 1.5f); if (overshootOrAmplitude < 1) { overshootOrAmplitude = 1; s = period / 4; } else s = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude); if (time < 1) return -0.5f * (overshootOrAmplitude * (float)Math.Pow(2, 10 * (time -= 1)) * (float)Math.Sin((time * duration - s) * _TwoPi / period)); return overshootOrAmplitude * (float)Math.Pow(2, -10 * (time -= 1)) * (float)Math.Sin((time * duration - s) * _TwoPi / period) * 0.5f + 1; case Ease.InBack: return (time /= duration) * time * ((overshootOrAmplitude + 1) * time - overshootOrAmplitude); case Ease.OutBack: return ((time = time / duration - 1) * time * ((overshootOrAmplitude + 1) * time + overshootOrAmplitude) + 1); case Ease.InOutBack: if ((time /= duration * 0.5f) < 1) return 0.5f * (time * time * (((overshootOrAmplitude *= (1.525f)) + 1) * time - overshootOrAmplitude)); return 0.5f * ((time -= 2) * time * (((overshootOrAmplitude *= (1.525f)) + 1) * time + overshootOrAmplitude) + 2); case Ease.InBounce: return Bounce.EaseIn(time, duration, overshootOrAmplitude, period); case Ease.OutBounce: return Bounce.EaseOut(time, duration, overshootOrAmplitude, period); case Ease.InOutBounce: return Bounce.EaseInOut(time, duration, overshootOrAmplitude, period); case Ease.INTERNAL_Custom: return customEase(time, duration, overshootOrAmplitude, period); case Ease.INTERNAL_Zero: // 0 duration tween return 1; default: // OutQuad return -(time /= duration) * (time - 2); } }
/// <summary>Sets the ease of the tween using a custom ease function. /// <para>If applied to Sequences eases the whole sequence animation</para></summary> public TweenParams SetEase(EaseFunction customEase) { this.easeType = Ease.INTERNAL_Custom; this.customEase = customEase; return this; }
/// <summary> /// Initializes a new instance of the <see cref="FloatAnimationGameAction"/> class. /// </summary> /// <param name="entity">The entity</param> /// <param name="from">Initial value</param> /// <param name="to">End value</param> /// <param name="ease">Easing function</param> /// <param name="time">The time of the animation</param> protected FloatAnimationGameAction(Entity entity, float from, float to, TimeSpan time, EaseFunction ease) : this(entity, from, to, time, ease, null) { }
public UITweenInstance To(object obj, float duration, Dictionary<string, float> args, EaseFunction ease) { var inst = new UITweenInstance(this, obj, duration, args, ease); lock (m_ActiveTweens) { m_ActiveTweens.Add(inst); } inst.Start(); return inst; }