/// <summary>Returns a value based on the given ease and lifetime percentage (0 to 1)</summary> /// <param name="from">The value to start from when lifetimePercentage is 0</param> /// <param name="to">The value to reach when lifetimePercentage is 1</param> /// <param name="lifetimePercentage">The time percentage (0 to 1) at which the value should be taken</param> /// <param name="easeType">The type of ease</param> /// <param name="overshoot">Eventual overshoot to use with Back ease</param> public static float EasedValue(float from, float to, float lifetimePercentage, Ease easeType, float overshoot) { return(from + (to - from) * EaseManager.Evaluate(easeType, null, lifetimePercentage, 1, overshoot, DOTween.defaultEasePeriod)); }
public override void EvaluateAndApply(FloatOptions options, Tween t, bool isRelative, DOGetter <float> getter, DOSetter <float> setter, float elapsed, float startValue, float changeValue, float duration, bool usingInversePosition, UpdateNotice updateNotice) { if (t.loopType == LoopType.Incremental) { startValue += changeValue * (float)(t.isComplete ? (t.completedLoops - 1) : t.completedLoops); } if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) { startValue += changeValue * (float)((t.loopType == LoopType.Incremental) ? t.loops : 1) * (float)(t.sequenceParent.isComplete ? (t.sequenceParent.completedLoops - 1) : t.sequenceParent.completedLoops); } setter((!options.snapping) ? (startValue + changeValue * EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod)) : ((float)Math.Round((double)(startValue + changeValue * EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod))))); }
public override void EvaluateAndApply(Vector3ArrayOptions options, Tween t, bool isRelative, DOGetter <Vector3> getter, DOSetter <Vector3> setter, float elapsed, Vector3[] startValue, Vector3[] changeValue, float duration, bool usingInversePosition, UpdateNotice updateNotice) { Vector3 incrementValue = Vector3.zero; if (t.loopType == LoopType.Incremental) { int iterations = t.isComplete ? t.completedLoops - 1 : t.completedLoops; if (iterations > 0) { int end = startValue.Length - 1; incrementValue = (startValue[end] + changeValue[end] - startValue[0]) * iterations; } } if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) { int iterations = (t.loopType == LoopType.Incremental ? t.loops : 1) * (t.sequenceParent.isComplete ? t.sequenceParent.completedLoops - 1 : t.sequenceParent.completedLoops); if (iterations > 0) { int end = startValue.Length - 1; incrementValue += (startValue[end] + changeValue[end] - startValue[0]) * iterations; } } // Find correct index and segmentElapsed int index = 0; float segmentElapsed = 0; float segmentDuration = 0; int len = options.durations.Length; float count = 0; for (int i = 0; i < len; i++) { segmentDuration = options.durations[i]; count += segmentDuration; if (elapsed > count) { segmentElapsed += segmentDuration; continue; } index = i; segmentElapsed = elapsed - segmentElapsed; break; } // Evaluate float easeVal = EaseManager.Evaluate(t.easeType, t.customEase, segmentElapsed, segmentDuration, t.easeOvershootOrAmplitude, t.easePeriod); Vector3 res; switch (options.axisConstraint) { case AxisConstraint.X: res = getter(); res.x = startValue[index].x + incrementValue.x + changeValue[index].x * easeVal; if (options.snapping) { res.x = (float)Math.Round(res.x); } setter(res); break; case AxisConstraint.Y: res = getter(); res.y = startValue[index].y + incrementValue.y + changeValue[index].y * easeVal; if (options.snapping) { res.y = (float)Math.Round(res.y); } setter(res); return; case AxisConstraint.Z: res = getter(); res.z = startValue[index].z + incrementValue.z + changeValue[index].z * easeVal; if (options.snapping) { res.z = (float)Math.Round(res.z); } setter(res); break; default: res.x = startValue[index].x + incrementValue.x + changeValue[index].x * easeVal; res.y = startValue[index].y + incrementValue.y + changeValue[index].y * easeVal; res.z = startValue[index].z + incrementValue.z + changeValue[index].z * easeVal; if (options.snapping) { res.x = (float)Math.Round(res.x); res.y = (float)Math.Round(res.y); res.z = (float)Math.Round(res.z); } setter(res); break; } }
// ChangeValue is the same as endValue in this plugin public override void EvaluateAndApply(StringOptions options, Tween t, bool isRelative, DOGetter <string> getter, DOSetter <string> setter, float elapsed, string startValue, string changeValue, float duration, bool usingInversePosition, UpdateNotice updateNotice) { _Buffer.Remove(0, _Buffer.Length); // Incremental works only with relative tweens (otherwise the tween makes no sense) // Sequence with Incremental loops have no effect here (why should they?) if (isRelative && t.loopType == LoopType.Incremental) { int iterations = t.isComplete ? t.completedLoops - 1 : t.completedLoops; if (iterations > 0) { _Buffer.Append(startValue); for (int i = 0; i < iterations; ++i) { _Buffer.Append(changeValue); } startValue = _Buffer.ToString(); _Buffer.Remove(0, _Buffer.Length); } } int startValueLen = options.richTextEnabled ? options.startValueStrippedLength : startValue.Length; int changeValueLen = options.richTextEnabled ? options.changeValueStrippedLength : changeValue.Length; int len = (int)Math.Round(changeValueLen * EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod)); if (len > changeValueLen) { len = changeValueLen; } else if (len < 0) { len = 0; } if (isRelative) { _Buffer.Append(startValue); if (options.scrambleMode != ScrambleMode.None) { setter(Append(changeValue, 0, len, options.richTextEnabled).AppendScrambledChars(changeValueLen - len, ScrambledCharsToUse(options)).ToString()); return; } setter(Append(changeValue, 0, len, options.richTextEnabled).ToString()); return; } if (options.scrambleMode != ScrambleMode.None) { setter(Append(changeValue, 0, len, options.richTextEnabled).AppendScrambledChars(changeValueLen - len, ScrambledCharsToUse(options)).ToString()); return; } int diff = startValueLen - changeValueLen; int startValueMaxLen = startValueLen; if (diff > 0) { // String to be replaced is longer than endValue: remove parts of it while tweening float perc = (float)len / changeValueLen; startValueMaxLen -= (int)(startValueMaxLen * perc); } else { startValueMaxLen -= len; } Append(changeValue, 0, len, options.richTextEnabled); if (len < changeValueLen && len < startValueLen) { Append(startValue, len, options.richTextEnabled ? len + startValueMaxLen : startValueMaxLen, options.richTextEnabled); } setter(_Buffer.ToString()); }
public override void EvaluateAndApply(VectorOptions options, Tween t, bool isRelative, DOGetter <Vector4> getter, DOSetter <Vector4> setter, float elapsed, Vector4 startValue, Vector4 changeValue, float duration, bool usingInversePosition, UpdateNotice updateNotice) { if (t.loopType == LoopType.Incremental) { startValue += changeValue * (float)(t.isComplete ? (t.completedLoops - 1) : t.completedLoops); } if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) { startValue += changeValue * (float)((t.loopType != LoopType.Incremental) ? 1 : t.loops) * (float)(t.sequenceParent.isComplete ? (t.sequenceParent.completedLoops - 1) : t.sequenceParent.completedLoops); } float num = EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod); switch (options.axisConstraint) { case AxisConstraint.X: { Vector4 vector2 = getter(); vector2.x = startValue.x + changeValue.x * num; if (options.snapping) { vector2.x = (float)Math.Round((double)vector2.x); } setter(vector2); break; } case AxisConstraint.Y: { Vector4 vector4 = getter(); vector4.y = startValue.y + changeValue.y * num; if (options.snapping) { vector4.y = (float)Math.Round((double)vector4.y); } setter(vector4); break; } case AxisConstraint.Z: { Vector4 vector = getter(); vector.z = startValue.z + changeValue.z * num; if (options.snapping) { vector.z = (float)Math.Round((double)vector.z); } setter(vector); break; } case AxisConstraint.W: { Vector4 vector3 = getter(); vector3.w = startValue.w + changeValue.w * num; if (options.snapping) { vector3.w = (float)Math.Round((double)vector3.w); } setter(vector3); break; } default: startValue.x += changeValue.x * num; startValue.y += changeValue.y * num; startValue.z += changeValue.z * num; startValue.w += changeValue.w * num; if (options.snapping) { startValue.x = (float)Math.Round((double)startValue.x); startValue.y = (float)Math.Round((double)startValue.y); startValue.z = (float)Math.Round((double)startValue.z); startValue.w = (float)Math.Round((double)startValue.w); } setter(startValue); break; } }
public override void EvaluateAndApply(PathOptions options, Tween t, bool isRelative, DOGetter <Vector3> getter, DOSetter <Vector3> setter, float elapsed, Path startValue, Path changeValue, float duration) { float pathPerc = EaseManager.Evaluate(t, elapsed, 0, 1, duration, t.easeOvershootOrAmplitude, t.easePeriod); float constantPathPerc = changeValue.ConvertToConstantPathPerc(pathPerc); Vector3 newPos = changeValue.GetPoint(constantPathPerc); changeValue.targetPosition = newPos; // Used to draw editor gizmos setter(newPos); if (options.orientType != OrientType.None) { Transform trans = (Transform)t.target; Quaternion newRot = Quaternion.identity; switch (options.orientType) { case OrientType.LookAtPosition: changeValue.lookAtPosition = options.lookAtPosition; // Used to draw editor gizmos newRot = Quaternion.LookRotation(options.lookAtPosition - trans.position, trans.up); break; case OrientType.LookAtTransform: if (options.lookAtTransform != null) { changeValue.lookAtPosition = options.lookAtTransform.position; // Used to draw editor gizmos newRot = Quaternion.LookRotation(options.lookAtTransform.position - trans.position, trans.up); } break; case OrientType.ToPath: Vector3 lookAtP; if (changeValue.type == PathType.Linear && options.lookAhead <= MinLookAhead) { // Calculate lookAhead so that it doesn't turn until it starts moving on next waypoint lookAtP = newPos + changeValue.wps[changeValue.linearWPIndex] - changeValue.wps[changeValue.linearWPIndex - 1]; } else { float lookAheadPerc = constantPathPerc + options.lookAhead; if (lookAheadPerc > 1) { lookAheadPerc = (options.isClosedPath ? lookAheadPerc - 1 : 1.00001f); } lookAtP = changeValue.GetPoint(lookAheadPerc); } Vector3 transUp = trans.up; // Apply basic modification for local position movement if (options.useLocalPosition && options.parent != null) { lookAtP = options.parent.TransformPoint(lookAtP); } // LookAt axis constraint if (options.lockRotationAxis != AxisConstraint.None) { if ((options.lockRotationAxis & AxisConstraint.X) == AxisConstraint.X) { Vector3 v0 = trans.InverseTransformPoint(lookAtP); v0.y = 0; lookAtP = trans.TransformPoint(v0); transUp = options.useLocalPosition && options.parent != null ? options.parent.up : Vector3.up; } if ((options.lockRotationAxis & AxisConstraint.Y) == AxisConstraint.Y) { Vector3 v0 = trans.InverseTransformPoint(lookAtP); if (v0.z < 0) { v0.z = -v0.z; } v0.x = 0; lookAtP = trans.TransformPoint(v0); } if ((options.lockRotationAxis & AxisConstraint.Z) == AxisConstraint.Z) { // Fix to allow racing loops to keep cars straight and not flip it if (options.useLocalPosition && options.parent != null) { transUp = options.parent.TransformDirection(Vector3.up); } else { transUp = trans.TransformDirection(Vector3.up); } transUp.z = options.startupZRot; } } if (options.mode == PathMode.Full3D) { // 3D path Vector3 diff = lookAtP - trans.position; if (diff == Vector3.zero) { diff = trans.forward; } newRot = Quaternion.LookRotation(diff, transUp); } else { // 2D path float rotY = 0; float rotZ = Utils.Angle2D(trans.position, lookAtP); if (rotZ < 0) { rotZ = 360 + rotZ; } if (options.mode == PathMode.Sidescroller2D) { // Manage Y and modified Z rotation rotY = lookAtP.x < trans.position.x ? 180 : 0; if (rotZ > 90 && rotZ < 270) { rotZ = 180 - rotZ; } } newRot = Quaternion.Euler(0, rotY, rotZ); } break; } if (options.hasCustomForwardDirection) { newRot *= options.forward; } trans.rotation = newRot; } }
public override void EvaluateAndApply(VectorOptions options, Tween t, bool isRelative, DOGetter <Vector4> getter, DOSetter <Vector4> setter, float elapsed, Vector4 startValue, Vector4 changeValue, float duration, bool usingInversePosition, UpdateNotice updateNotice) { if (t.loopType == LoopType.Incremental) { startValue += changeValue * (t.isComplete ? t.completedLoops - 1 : t.completedLoops); } if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) { startValue += changeValue * (t.loopType == LoopType.Incremental ? t.loops : 1) * (t.sequenceParent.isComplete ? t.sequenceParent.completedLoops - 1 : t.sequenceParent.completedLoops); } float easeVal = EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod); switch (options.axisConstraint) { case AxisConstraint.X: Vector4 resX = getter(); resX.x = startValue.x + changeValue.x * easeVal; if (options.snapping) { resX.x = (float)Math.Round(resX.x); } setter(resX); break; case AxisConstraint.Y: Vector4 resY = getter(); resY.y = startValue.y + changeValue.y * easeVal; if (options.snapping) { resY.y = (float)Math.Round(resY.y); } setter(resY); break; case AxisConstraint.Z: Vector4 resZ = getter(); resZ.z = startValue.z + changeValue.z * easeVal; if (options.snapping) { resZ.z = (float)Math.Round(resZ.z); } setter(resZ); break; case AxisConstraint.W: Vector4 resW = getter(); resW.w = startValue.w + changeValue.w * easeVal; if (options.snapping) { resW.w = (float)Math.Round(resW.w); } setter(resW); break; default: startValue.x += changeValue.x * easeVal; startValue.y += changeValue.y * easeVal; startValue.z += changeValue.z * easeVal; startValue.w += changeValue.w * easeVal; if (options.snapping) { startValue.x = (float)Math.Round(startValue.x); startValue.y = (float)Math.Round(startValue.y); startValue.z = (float)Math.Round(startValue.z); startValue.w = (float)Math.Round(startValue.w); } setter(startValue); break; } }
// Applies the tween set by DoGoto. // Returns TRUE if the tween needs to be killed internal static bool DoApplyTween(Sequence s, float prevPosition, int prevCompletedLoops, int newCompletedSteps, bool useInversePosition, UpdateMode updateMode) { // Adapt to eventual ease position float prevPos = prevPosition; float newPos = s.position; if (s.easeType != Ease.Linear) { prevPos = s.duration * EaseManager.Evaluate(s.easeType, s.customEase, prevPos, s.duration, s.easeOvershootOrAmplitude, s.easePeriod); newPos = s.duration * EaseManager.Evaluate(s.easeType, s.customEase, newPos, s.duration, s.easeOvershootOrAmplitude, s.easePeriod); } float from, to = 0; // Determine if prevPos was inverse. // Used to calculate correct "from" value when applying internal cycle // and also in case of multiple loops within a single update bool prevPosIsInverse = s.loopType == LoopType.Yoyo && (prevPos < s.duration ? prevCompletedLoops % 2 != 0 : prevCompletedLoops % 2 == 0); if (s.isBackwards) { prevPosIsInverse = !prevPosIsInverse; } // Update multiple loop cycles within the same update if (newCompletedSteps > 0) { // Debug.Log(Time.frameCount + " <color=#FFEC03>newCompletedSteps = " + newCompletedSteps + "</color> - completedLoops: " + s.completedLoops + " - updateMode: " + updateMode); // Store expected completedLoops and position, in order to check them after the update cycles. int expectedCompletedLoops = s.completedLoops; float expectedPosition = s.position; // int cycles = newCompletedSteps; int cyclesDone = 0; from = prevPos; if (updateMode == UpdateMode.Update) { // Run all cycles elapsed since last update while (cyclesDone < cycles) { if (cyclesDone > 0) { from = to; } else if (prevPosIsInverse && !s.isBackwards) { from = s.duration - from; } to = prevPosIsInverse ? 0 : s.duration; if (ApplyInternalCycle(s, from, to, updateMode, useInversePosition, prevPosIsInverse, true)) { return(true); } cyclesDone++; if (s.loopType == LoopType.Yoyo) { prevPosIsInverse = !prevPosIsInverse; } } // If completedLoops or position were changed by some callback, exit here // Debug.Log(" Internal Cycle Ended > expecteCompletedLoops/completedLoops: " + expectedCompletedLoops + "/" + s.completedLoops + " - expectedPosition/position: " + expectedPosition + "/" + s.position); if (expectedCompletedLoops != s.completedLoops || Math.Abs(expectedPosition - s.position) > Single.Epsilon) { return(!s.active); } } else { // Simply determine correct prevPosition after steps if (s.loopType == LoopType.Yoyo && newCompletedSteps % 2 != 0) { prevPosIsInverse = !prevPosIsInverse; prevPos = s.duration - prevPos; } newCompletedSteps = 0; } } // Run current cycle if (newCompletedSteps == 1 && s.isComplete) { return(false); // Skip update if complete because multicycle took care of it } if (newCompletedSteps > 0 && !s.isComplete) { from = useInversePosition ? s.duration : 0; // In case of Restart loop rewind all tweens (keep "to > 0" or remove it?) if (s.loopType == LoopType.Restart && to > 0) { ApplyInternalCycle(s, s.duration, 0, UpdateMode.Goto, false, false, false); } } else { from = useInversePosition ? s.duration - prevPos : prevPos; } return(ApplyInternalCycle(s, from, useInversePosition ? s.duration - newPos : newPos, updateMode, useInversePosition, prevPosIsInverse)); }
public override void EvaluateAndApply(VectorOptions options, Tween t, bool isRelative, DOGetter <Vector4> getter, DOSetter <Vector4> setter, float elapsed, Vector4 startValue, Vector4 changeValue, float duration, bool usingInversePosition, UpdateNotice updateNotice) { if (t.loopType == LoopType.Incremental) { startValue += changeValue * (float)(t.isComplete ? (t.completedLoops - 1) : t.completedLoops); } if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) { startValue += changeValue * (float)((t.loopType == LoopType.Incremental) ? t.loops : 1) * (float)(t.sequenceParent.isComplete ? (t.sequenceParent.completedLoops - 1) : t.sequenceParent.completedLoops); } float num = EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod); AxisConstraint axisConstraint = options.axisConstraint; switch (axisConstraint) { case AxisConstraint.X: { Vector4 pNewValue = getter(); pNewValue.x = startValue.x + changeValue.x * num; if (options.snapping) { pNewValue.x = (float)Math.Round((double)pNewValue.x); } setter(pNewValue); return; } case (AxisConstraint)3: break; case AxisConstraint.Y: { Vector4 pNewValue2 = getter(); pNewValue2.y = startValue.y + changeValue.y * num; if (options.snapping) { pNewValue2.y = (float)Math.Round((double)pNewValue2.y); } setter(pNewValue2); return; } default: if (axisConstraint == AxisConstraint.Z) { Vector4 pNewValue3 = getter(); pNewValue3.z = startValue.z + changeValue.z * num; if (options.snapping) { pNewValue3.z = (float)Math.Round((double)pNewValue3.z); } setter(pNewValue3); return; } if (axisConstraint == AxisConstraint.W) { Vector4 pNewValue4 = getter(); pNewValue4.w = startValue.w + changeValue.w * num; if (options.snapping) { pNewValue4.w = (float)Math.Round((double)pNewValue4.w); } setter(pNewValue4); return; } break; } startValue.x += changeValue.x * num; startValue.y += changeValue.y * num; startValue.z += changeValue.z * num; startValue.w += changeValue.w * num; if (options.snapping) { startValue.x = (float)Math.Round((double)startValue.x); startValue.y = (float)Math.Round((double)startValue.y); startValue.z = (float)Math.Round((double)startValue.z); startValue.w = (float)Math.Round((double)startValue.w); } setter(startValue); }
public override void EvaluateAndApply(Vector3ArrayOptions options, Tween t, bool isRelative, DOGetter <Vector3> getter, DOSetter <Vector3> setter, float elapsed, Vector3[] startValue, Vector3[] changeValue, float duration, bool usingInversePosition, UpdateNotice updateNotice) { Vector3 vector = Vector3.zero; if (t.loopType == LoopType.Incremental) { int num = t.isComplete ? (t.completedLoops - 1) : t.completedLoops; if (num > 0) { int num2 = startValue.Length - 1; vector = (startValue[num2] + changeValue[num2] - startValue[0]) * (float)num; } } if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) { int num3 = ((t.loopType != LoopType.Incremental) ? 1 : t.loops) * (t.sequenceParent.isComplete ? (t.sequenceParent.completedLoops - 1) : t.sequenceParent.completedLoops); if (num3 > 0) { int num4 = startValue.Length - 1; vector += (startValue[num4] + changeValue[num4] - startValue[0]) * (float)num3; } } int num5 = 0; float num6 = 0f; float num7 = 0f; int num8 = options.durations.Length; float num9 = 0f; int num10 = 0; while (num10 < num8) { num7 = options.durations[num10]; num9 += num7; if (elapsed > num9) { num6 += num7; num10++; continue; } num5 = num10; num6 = elapsed - num6; break; } float num11 = EaseManager.Evaluate(t.easeType, t.customEase, num6, num7, t.easeOvershootOrAmplitude, t.easePeriod); Vector3 vector2 = default(Vector3); switch (options.axisConstraint) { case AxisConstraint.X: vector2 = getter(); vector2.x = startValue[num5].x + vector.x + changeValue[num5].x * num11; if (options.snapping) { vector2.x = (float)Math.Round((double)vector2.x); } setter(vector2); break; case AxisConstraint.Y: vector2 = getter(); vector2.y = startValue[num5].y + vector.y + changeValue[num5].y * num11; if (options.snapping) { vector2.y = (float)Math.Round((double)vector2.y); } setter(vector2); break; case AxisConstraint.Z: vector2 = getter(); vector2.z = startValue[num5].z + vector.z + changeValue[num5].z * num11; if (options.snapping) { vector2.z = (float)Math.Round((double)vector2.z); } setter(vector2); break; default: vector2.x = startValue[num5].x + vector.x + changeValue[num5].x * num11; vector2.y = startValue[num5].y + vector.y + changeValue[num5].y * num11; vector2.z = startValue[num5].z + vector.z + changeValue[num5].z * num11; if (options.snapping) { vector2.x = (float)Math.Round((double)vector2.x); vector2.y = (float)Math.Round((double)vector2.y); vector2.z = (float)Math.Round((double)vector2.z); } setter(vector2); break; } }
/// <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="ease">Ease type</param> public static EaseFunction StopMotion(int motionFps, Ease?ease = null) { EaseFunction easeFunc = EaseManager.ToEaseFunction(ease == null ? DOTween.defaultEaseType : (Ease)ease); return(StopMotion(motionFps, easeFunc)); }
internal static bool DoApplyTween(Sequence s, float prevPosition, int prevCompletedLoops, int newCompletedSteps, bool useInversePosition, UpdateMode updateMode) { float num3; float time = prevPosition; float position = s.position; if (s.easeType != Ease.Linear) { time = s.duration * EaseManager.Evaluate(s.easeType, s.customEase, time, s.duration, s.easeOvershootOrAmplitude, s.easePeriod); position = s.duration * EaseManager.Evaluate(s.easeType, s.customEase, position, s.duration, s.easeOvershootOrAmplitude, s.easePeriod); } float toPos = 0f; bool prevPosIsInverse = (s.loopType == LoopType.Yoyo) && ((time < s.duration) ? ((prevCompletedLoops % 2) > 0) : ((prevCompletedLoops % 2) == 0)); if (s.isBackwards) { prevPosIsInverse = !prevPosIsInverse; } if (newCompletedSteps > 0) { int completedLoops = s.completedLoops; float num6 = s.position; int num7 = newCompletedSteps; int num8 = 0; num3 = time; if (updateMode == UpdateMode.Update) { while (num8 < num7) { if (num8 > 0) { num3 = toPos; } else if (prevPosIsInverse && !s.isBackwards) { num3 = s.duration - num3; } toPos = prevPosIsInverse ? 0f : s.duration; if (ApplyInternalCycle(s, num3, toPos, updateMode, useInversePosition, prevPosIsInverse, true)) { return(true); } num8++; if (s.loopType == LoopType.Yoyo) { prevPosIsInverse = !prevPosIsInverse; } } if ((completedLoops != s.completedLoops) || (Math.Abs((float)(num6 - s.position)) > float.Epsilon)) { return(!s.active); } } else { if ((s.loopType == LoopType.Yoyo) && ((newCompletedSteps % 2) != 0)) { prevPosIsInverse = !prevPosIsInverse; time = s.duration - time; } newCompletedSteps = 0; } } if ((newCompletedSteps == 1) && s.isComplete) { return(false); } if ((newCompletedSteps > 0) && !s.isComplete) { num3 = useInversePosition ? s.duration : 0f; if ((s.loopType == LoopType.Restart) && (toPos > 0f)) { ApplyInternalCycle(s, s.duration, 0f, UpdateMode.Goto, false, false, false); } } else { num3 = useInversePosition ? (s.duration - time) : time; } return(ApplyInternalCycle(s, num3, useInversePosition ? (s.duration - position) : position, updateMode, useInversePosition, prevPosIsInverse, false)); }
public override void EvaluateAndApply(StringOptions options, Tween t, bool isRelative, DOGetter <string> getter, DOSetter <string> setter, float elapsed, string startValue, string changeValue, float duration, bool usingInversePosition, UpdateNotice updateNotice) { StringPlugin._Buffer.Remove(0, StringPlugin._Buffer.Length); if (isRelative && t.loopType == LoopType.Incremental) { int num = t.isComplete ? (t.completedLoops - 1) : t.completedLoops; if (num > 0) { StringPlugin._Buffer.Append(startValue); for (int i = 0; i < num; i++) { StringPlugin._Buffer.Append(changeValue); } startValue = StringPlugin._Buffer.ToString(); StringPlugin._Buffer.Remove(0, StringPlugin._Buffer.Length); } } int num2 = options.richTextEnabled ? options.startValueStrippedLength : startValue.Length; int num3 = options.richTextEnabled ? options.changeValueStrippedLength : changeValue.Length; int num4 = (int)Math.Round((double)((float)num3 * EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod))); if (num4 > num3) { num4 = num3; } else if (num4 < 0) { num4 = 0; } if (isRelative) { StringPlugin._Buffer.Append(startValue); if (options.scrambleMode != ScrambleMode.None) { setter(this.Append(changeValue, 0, num4, options.richTextEnabled).AppendScrambledChars(num3 - num4, this.ScrambledCharsToUse(options)).ToString()); return; } setter(this.Append(changeValue, 0, num4, options.richTextEnabled).ToString()); return; } else { if (options.scrambleMode != ScrambleMode.None) { setter(this.Append(changeValue, 0, num4, options.richTextEnabled).AppendScrambledChars(num3 - num4, this.ScrambledCharsToUse(options)).ToString()); return; } int num5 = num2 - num3; int num6 = num2; if (num5 > 0) { float num7 = (float)num4 / (float)num3; num6 -= (int)((float)num6 * num7); } else { num6 -= num4; } this.Append(changeValue, 0, num4, options.richTextEnabled); if (num4 < num3 && num4 < num2) { this.Append(startValue, num4, options.richTextEnabled ? (num4 + num6) : num6, options.richTextEnabled); } setter(StringPlugin._Buffer.ToString()); return; } }
protected virtual void OnEnable() { ResetTween(); mEaseFunc = EaseManager.ToEaseFunction(easeType); }
/// <summary>Returns a value based on the given ease and lifetime percentage (0 to 1)</summary> /// <param name="from">The value to start from when lifetimePercentage is 0</param> /// <param name="to">The value to reach when lifetimePercentage is 1</param> /// <param name="lifetimePercentage">The time percentage (0 to 1) at which the value should be taken</param> /// <param name="easeType">The type of ease</param> /// <param name="amplitude">Eventual amplitude to use with Elastic easeType</param> /// <param name="period">Eventual period to use with Elastic easeType</param> public static float EasedValue(float from, float to, float lifetimePercentage, Ease easeType, float amplitude, float period) { return(from + (to - from) * EaseManager.Evaluate(easeType, null, lifetimePercentage, 1, amplitude, period)); }
// Token: 0x06000194 RID: 404 RVA: 0x00008900 File Offset: 0x00006B00 public override void EvaluateAndApply(Vector3ArrayOptions options, Tween t, bool isRelative, DOGetter <Vector3> getter, DOSetter <Vector3> setter, float elapsed, Vector3[] startValue, Vector3[] changeValue, float duration, bool usingInversePosition, UpdateNotice updateNotice) { Vector3 vector = Vector3.zero; if (t.loopType == LoopType.Incremental) { int num = t.isComplete ? (t.completedLoops - 1) : t.completedLoops; if (num > 0) { int num2 = startValue.Length - 1; vector = (startValue[num2] + changeValue[num2] - startValue[0]) * (float)num; } } if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) { int num3 = ((t.loopType == LoopType.Incremental) ? t.loops : 1) * (t.sequenceParent.isComplete ? (t.sequenceParent.completedLoops - 1) : t.sequenceParent.completedLoops); if (num3 > 0) { int num4 = startValue.Length - 1; vector += (startValue[num4] + changeValue[num4] - startValue[0]) * (float)num3; } } int num5 = 0; float num6 = 0f; float num7 = 0f; int num8 = options.durations.Length; float num9 = 0f; for (int i = 0; i < num8; i++) { num7 = options.durations[i]; num9 += num7; if (elapsed <= num9) { num5 = i; num6 = elapsed - num6; break; } num6 += num7; } float num10 = EaseManager.Evaluate(t.easeType, t.customEase, num6, num7, t.easeOvershootOrAmplitude, t.easePeriod); AxisConstraint axisConstraint = options.axisConstraint; Vector3 vector2; if (axisConstraint == AxisConstraint.X) { vector2 = getter(); vector2.x = startValue[num5].x + vector.x + changeValue[num5].x * num10; if (options.snapping) { vector2.x = (float)Math.Round((double)vector2.x); } setter(vector2); return; } if (axisConstraint == AxisConstraint.Y) { vector2 = getter(); vector2.y = startValue[num5].y + vector.y + changeValue[num5].y * num10; if (options.snapping) { vector2.y = (float)Math.Round((double)vector2.y); } setter(vector2); return; } if (axisConstraint != AxisConstraint.Z) { vector2.x = startValue[num5].x + vector.x + changeValue[num5].x * num10; vector2.y = startValue[num5].y + vector.y + changeValue[num5].y * num10; vector2.z = startValue[num5].z + vector.z + changeValue[num5].z * num10; if (options.snapping) { vector2.x = (float)Math.Round((double)vector2.x); vector2.y = (float)Math.Round((double)vector2.y); vector2.z = (float)Math.Round((double)vector2.z); } setter(vector2); return; } vector2 = getter(); vector2.z = startValue[num5].z + vector.z + changeValue[num5].z * num10; if (options.snapping) { vector2.z = (float)Math.Round((double)vector2.z); } setter(vector2); }
/// <summary>Returns a value based on the given ease and lifetime percentage (0 to 1)</summary> /// <param name="from">The value to start from when lifetimePercentage is 0</param> /// <param name="to">The value to reach when lifetimePercentage is 1</param> /// <param name="lifetimePercentage">The time percentage (0 to 1) at which the value should be taken</param> /// <param name="easeCurve">The AnimationCurve to use for ease</param> public static float EasedValue(float from, float to, float lifetimePercentage, AnimationCurve easeCurve) { return(from + (to - from) * EaseManager.Evaluate(Ease.INTERNAL_Custom, new EaseCurve(easeCurve).Evaluate, lifetimePercentage, 1, DOTween.defaultEaseOvershootOrAmplitude, DOTween.defaultEasePeriod)); }
public static EaseFunction StopMotion(int motionFps, Ease?ease) { EaseFunction customEase = EaseManager.ToEaseFunction(!ease.HasValue ? DOTween.defaultEaseType : ease.Value); return(StopMotion(motionFps, customEase)); }