/// <summary> /// Computes and applies the rotation to the object /// </summary> /// <param name="targetTransform"></param> /// <param name="multiplier"></param> /// <param name="curveX"></param> /// <param name="curveY"></param> /// <param name="curveZ"></param> /// <param name="percent"></param> protected virtual void ApplyRotation(Transform targetTransform, float remapZero, float remapOne, AnimationCurve curveX, AnimationCurve curveY, AnimationCurve curveZ, float percent) { if (RotationSpace == Space.World) { targetTransform.transform.rotation = _initialRotation; } else { targetTransform.transform.localRotation = _initialRotation; } if (AnimateX) { float x = curveX.Evaluate(percent); x = MMFeedbacksHelpers.Remap(x, 0f, 1f, remapZero, remapOne); targetTransform.Rotate(Vector3.right, x, RotationSpace); } if (AnimateY) { float y = curveY.Evaluate(percent); y = MMFeedbacksHelpers.Remap(y, 0f, 1f, remapZero, remapOne); targetTransform.Rotate(Vector3.up, y, RotationSpace); } if (AnimateZ) { float z = curveZ.Evaluate(percent); z = MMFeedbacksHelpers.Remap(z, 0f, 1f, remapZero, remapOne); targetTransform.Rotate(Vector3.forward, z, RotationSpace); } }
protected virtual void ComputeNewCurvePosition(GameObject movingObject, Vector3 initialPosition, float percent) { float newValueX = AnimatePositionCurveX.Evaluate(percent); float newValueY = AnimatePositionCurveY.Evaluate(percent); float newValueZ = AnimatePositionCurveZ.Evaluate(percent); newValueX = MMFeedbacksHelpers.Remap(newValueX, 0f, 1f, RemapCurveZero, RemapCurveOne); newValueY = MMFeedbacksHelpers.Remap(newValueY, 0f, 1f, RemapCurveZero, RemapCurveOne); newValueZ = MMFeedbacksHelpers.Remap(newValueZ, 0f, 1f, RemapCurveZero, RemapCurveOne); _newPosition = initialPosition; if (RelativePosition) { _newPosition.x = AnimateX ? initialPosition.x + newValueX : initialPosition.x; _newPosition.y = AnimateY ? initialPosition.y + newValueY : initialPosition.y; _newPosition.z = AnimateZ ? initialPosition.z + newValueZ : initialPosition.z; } else { _newPosition.x = AnimateX ? newValueX : initialPosition.x; _newPosition.y = AnimateY ? newValueY : initialPosition.y; _newPosition.z = AnimateZ ? newValueZ : initialPosition.z; } SetPosition(movingObject.transform, _newPosition); }
/// <summary> /// Shakes values over time /// </summary> protected override void Shake() { if (ModifyColor) { _remappedTimeSinceStart = MMFeedbacksHelpers.Remap(Time.time - _shakeStartedTimestamp, 0f, ShakeDuration, 0f, 1f); BoundSpriteRenderer.color = ColorOverTime.Evaluate(_remappedTimeSinceStart); } }
/// <summary> /// An internal coroutine used to animate the scale over time /// </summary> /// <param name="targetTransform"></param> /// <param name="duration"></param> /// <param name="curveX"></param> /// <param name="curveY"></param> /// <param name="curveZ"></param> /// <param name="multiplier"></param> /// <returns></returns> protected virtual IEnumerator AnimateScale(Transform targetTransform, float duration, AnimationCurve curve, PossibleAxis axis, float remapCurveZero = 0f, float remapCurveOne = 1f) { if (targetTransform == null) { yield break; } if (duration == 0f) { yield break; } float journey = NormalPlayDirection ? 0f : duration; _initialScale = targetTransform.localScale; IsPlaying = true; while ((journey >= 0) && (journey <= duration) && (duration > 0)) { float percent = Mathf.Clamp01(journey / duration); float newScale = curve.Evaluate(percent) + Offset; newScale = MMFeedbacksHelpers.Remap(newScale, 0f, 1f, remapCurveZero, remapCurveOne); if (Mode == Modes.Additive) { newScale += _initialAxisScale; } ApplyScale(newScale); targetTransform.localScale = _newScale; if (TimeScale == TimeScales.Scaled) { journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; } else { journey += NormalPlayDirection ? Time.unscaledDeltaTime : -Time.unscaledDeltaTime; } yield return(null); } float finalScale; finalScale = curve.Evaluate(FinalNormalizedTime) + Offset; finalScale = MMFeedbacksHelpers.Remap(finalScale, 0f, 1f, remapCurveZero, remapCurveOne); if (Mode == Modes.Additive) { finalScale += _initialAxisScale; } ApplyScale(finalScale); targetTransform.localScale = _newScale; _coroutine = null; IsPlaying = false; yield return(null); }
/// <summary> /// An internal coroutine used to animate the scale over time /// </summary> /// <param name="targetTransform"></param> /// <param name="vector"></param> /// <param name="duration"></param> /// <param name="curveX"></param> /// <param name="curveY"></param> /// <param name="curveZ"></param> /// <param name="multiplier"></param> /// <returns></returns> protected virtual IEnumerator AnimateScale(Transform targetTransform, Vector3 vector, float duration, AnimationCurve curveX, AnimationCurve curveY, AnimationCurve curveZ, float remapCurveZero = 0f, float remapCurveOne = 1f) { if (targetTransform == null) { yield break; } if ((curveX == null) || (curveY == null) || (curveZ == null)) { yield break; } if (duration == 0f) { yield break; } float journey = 0f; while (journey < duration) { float percent = Mathf.Clamp01(journey / duration); vector.x = AnimateX ? curveX.Evaluate(percent) + Offset : targetTransform.localScale.x; vector.y = AnimateY ? curveY.Evaluate(percent) + Offset : targetTransform.localScale.y; vector.z = AnimateZ ? curveZ.Evaluate(percent) + Offset : targetTransform.localScale.z; vector.x = MMFeedbacksHelpers.Remap(vector.x, 0f, 1f, RemapCurveZero, RemapCurveOne); vector.y = MMFeedbacksHelpers.Remap(vector.y, 0f, 1f, RemapCurveZero, RemapCurveOne); vector.z = MMFeedbacksHelpers.Remap(vector.z, 0f, 1f, RemapCurveZero, RemapCurveOne); if (Mode == Modes.Additive) { vector += _initialScale; } targetTransform.localScale = vector; journey += (TimeScale == TimeScales.Scaled) ? Time.deltaTime : Time.unscaledDeltaTime; yield return(null); } vector.x = AnimateX ? curveX.Evaluate(1f) + Offset : targetTransform.localScale.x; vector.y = AnimateY ? curveY.Evaluate(1f) + Offset : targetTransform.localScale.y; vector.z = AnimateZ ? curveZ.Evaluate(1f) + Offset : targetTransform.localScale.z; vector.x = MMFeedbacksHelpers.Remap(vector.x, 0f, 1f, RemapCurveZero, RemapCurveOne); vector.y = MMFeedbacksHelpers.Remap(vector.y, 0f, 1f, RemapCurveZero, RemapCurveOne); vector.z = MMFeedbacksHelpers.Remap(vector.z, 0f, 1f, RemapCurveZero, RemapCurveOne); if (Mode == Modes.Additive) { vector += _initialScale; } targetTransform.localScale = vector; yield return(null); }
/// <summary> /// An internal coroutine used to scale the target to its destination scale /// </summary> /// <returns></returns> protected virtual IEnumerator ScaleToDestination() { if (AnimateScaleTarget == null) { yield break; } if ((AnimateScaleX == null) || (AnimateScaleY == null) || (AnimateScaleZ == null)) { yield break; } if (AnimateScaleDuration == 0f) { yield break; } float journey = 0f; _initialScale = AnimateScaleTarget.localScale; _newScale = _initialScale; while (journey < AnimateScaleDuration) { float percent = Mathf.Clamp01(journey / AnimateScaleDuration); if (AnimateX) { _newScale.x = Mathf.LerpUnclamped(_initialScale.x, DestinationScale.x, AnimateScaleX.Evaluate(percent) + Offset); _newScale.x = MMFeedbacksHelpers.Remap(_newScale.x, 0f, 1f, RemapCurveZero, RemapCurveOne); } if (AnimateY) { _newScale.y = Mathf.LerpUnclamped(_initialScale.y, DestinationScale.y, AnimateScaleY.Evaluate(percent) + Offset); _newScale.y = MMFeedbacksHelpers.Remap(_newScale.y, 0f, 1f, RemapCurveZero, RemapCurveOne); } if (AnimateZ) { _newScale.z = Mathf.LerpUnclamped(_initialScale.z, DestinationScale.z, AnimateScaleZ.Evaluate(percent) + Offset); _newScale.z = MMFeedbacksHelpers.Remap(_newScale.z, 0f, 1f, RemapCurveZero, RemapCurveOne); } AnimateScaleTarget.localScale = _newScale; journey += (TimeScale == TimeScales.Scaled) ? Time.deltaTime : Time.unscaledDeltaTime; yield return(null); } AnimateScaleTarget.localScale = DestinationScale; yield return(null); }
/// <summary> /// Applies the scale to the target material /// </summary> /// <param name="time"></param> protected virtual void SetMaterialValues(float time, float intensityMultiplier) { _newValue.x = MMFeedbacksHelpers.Remap(ScaleCurve.Evaluate(time), 0f, 1f, RemapZero.x, RemapOne.x); _newValue.y = MMFeedbacksHelpers.Remap(ScaleCurve.Evaluate(time), 0f, 1f, RemapZero.y, RemapOne.y); if (RelativeValues) { _newValue += _initialValue; } ApplyValue(_newValue * intensityMultiplier); }
/// <summary> /// Applies the scale to the target material /// </summary> /// <param name="time"></param> protected virtual void SetMaterialValues(float time, float intensityMultiplier) { _newValue.x = MMFeedbacksHelpers.Remap(ScaleCurve.Evaluate(time), 0f, 1f, RemapZero.x, RemapOne.x); _newValue.y = MMFeedbacksHelpers.Remap(ScaleCurve.Evaluate(time), 0f, 1f, RemapZero.y, RemapOne.y); if (RelativeValues) { _newValue += _initialValue; } TargetRenderer.materials[MaterialIndex].SetTextureScale(MaterialPropertyName, _newValue * intensityMultiplier); }
/// <summary> /// A method used to "shake" a flot over time along a curve /// </summary> /// <param name="curve"></param> /// <param name="remapMin"></param> /// <param name="remapMax"></param> /// <param name="relativeIntensity"></param> /// <param name="initialValue"></param> /// <returns></returns> protected virtual float ShakeFloat(AnimationCurve curve, float remapMin, float remapMax, bool relativeIntensity, float initialValue) { float newValue = 0f; _remappedTimeSinceStart = MMFeedbacksHelpers.Remap(Time.time - _shakeStartedTimestamp, 0f, ShakeDuration, 0f, 1f); float curveValue = curve.Evaluate(_remappedTimeSinceStart); newValue = MMFeedbacksHelpers.Remap(curveValue, 0f, 1f, remapMin, remapMax); if (relativeIntensity) { newValue += initialValue; } return(newValue); }
/// <summary> /// A coroutine used to interpolate between materials /// </summary> /// <param name="originalMaterial"></param> /// <param name="newMaterial"></param> /// <returns></returns> protected virtual IEnumerator TransitionMaterial(Material originalMaterial, Material newMaterial) { _startedAt = GetTime(); while (GetTime() - _startedAt < TransitionDuration) { float time = MMFeedbacksHelpers.Remap(GetTime() - _startedAt, 0f, TransitionDuration, 0f, 1f); float t = TransitionCurve.Evaluate(time); TargetRenderer.material.Lerp(originalMaterial, newMaterial, t); yield return(null); } float finalt = TransitionCurve.Evaluate(1f); TargetRenderer.material.Lerp(originalMaterial, newMaterial, finalt); }
/// <summary> /// A method used to "shake" a flot over time along a curve /// </summary> /// <param name="curve"></param> /// <param name="remapMin"></param> /// <param name="remapMax"></param> /// <param name="relativeIntensity"></param> /// <param name="initialValue"></param> /// <returns></returns> protected virtual float ShakeFloat(AnimationCurve curve, float remapMin, float remapMax, bool relativeIntensity, float initialValue) { float newValue = 0f; float remappedTime = MMFeedbacksHelpers.Remap(_journey, 0f, ShakeDuration, 0f, 1f); float curveValue = curve.Evaluate(remappedTime); newValue = MMFeedbacksHelpers.Remap(curveValue, 0f, 1f, remapMin, remapMax); if (relativeIntensity) { newValue += initialValue; } return(newValue); }
/// <summary> /// This coroutine will modify the values on the fog settings /// </summary> /// <returns></returns> protected virtual IEnumerator SpriteRendererSequence() { float journey = 0f; while (journey < Duration) { float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, Duration, 0f, 1f); SetFogValues(remappedTime); journey += FeedbackDeltaTime; yield return(null); } SetFogValues(1f); yield return(null); }
/// <summary> /// An internal coroutine used to scale the target to its destination scale /// </summary> /// <returns></returns> protected virtual IEnumerator ScaleToDestination() { if (SquashAndStretchTarget == null) { yield break; } if (FeedbackDuration == 0f) { yield break; } float journey = NormalPlayDirection ? 0f : FeedbackDuration; _initialScale = SquashAndStretchTarget.localScale; _newScale = _initialScale; GetAxisScale(); IsPlaying = true; while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0)) { float percent = Mathf.Clamp01(journey / FeedbackDuration); float newScale = Mathf.LerpUnclamped(_initialAxisScale, DestinationScale, AnimateCurve.Evaluate(percent) + Offset); newScale = MMFeedbacksHelpers.Remap(newScale, 0f, 1f, RemapCurveZero, RemapCurveOne); ApplyScale(newScale); SquashAndStretchTarget.localScale = _newScale; if (TimeScale == TimeScales.Scaled) { journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; } else { journey += NormalPlayDirection ? Time.unscaledDeltaTime : -Time.unscaledDeltaTime; } yield return(null); } ApplyScale(DestinationScale); SquashAndStretchTarget.localScale = NormalPlayDirection ? _newScale : _initialScale; _coroutine = null; IsPlaying = false; yield return(null); }
/// <summary> /// Changes the color of the text over time /// </summary> /// <returns></returns> protected virtual IEnumerator ChangeColor() { float journey = NormalPlayDirection ? 0f : FeedbackDuration; while ((journey >= 0) && (journey <= FeedbackDuration)) { float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f); SetColor(remappedTime); journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; yield return(null); } SetColor(FinalNormalizedTime); _coroutine = null; yield break; }
/// <summary> /// A coroutine used to interpolate between materials /// </summary> /// <param name="originalMaterial"></param> /// <param name="newMaterial"></param> /// <returns></returns> protected virtual IEnumerator TransitionMaterial(Material originalMaterial, Material newMaterial, int materialIndex) { IsPlaying = true; _startedAt = GetTime(); while (GetTime() - _startedAt < TransitionDuration) { float time = MMFeedbacksHelpers.Remap(GetTime() - _startedAt, 0f, TransitionDuration, 0f, 1f); float t = TransitionCurve.Evaluate(time); LerpMaterial(originalMaterial, newMaterial, t, materialIndex); yield return(null); } float finalt = TransitionCurve.Evaluate(1f); LerpMaterial(originalMaterial, newMaterial, finalt, materialIndex); IsPlaying = false; }
/// <summary> /// Applies our dilate value over time /// </summary> /// <returns></returns> protected virtual IEnumerator ApplyValueOverTime() { float journey = NormalPlayDirection ? 0f : FeedbackDuration; while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0)) { float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f); SetValue(remappedTime); journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; yield return(null); } SetValue(FinalNormalizedTime); _coroutine = null; yield return(null); }
/// <summary> /// This coroutine will modify the values on the fog settings /// </summary> /// <returns></returns> protected virtual IEnumerator FogSequence(float intensityMultiplier) { float journey = NormalPlayDirection ? 0f : FeedbackDuration; while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0)) { float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f); SetFogValues(remappedTime, intensityMultiplier); journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; yield return(null); } SetFogValues(FinalNormalizedTime, intensityMultiplier); _coroutine = null; yield return(null); }
/// <summary> /// This coroutine will modify the offset value over time /// </summary> /// <returns></returns> protected virtual IEnumerator TransitionCo(float intensityMultiplier) { float journey = NormalPlayDirection ? 0f : FeedbackDuration; IsPlaying = true; while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0)) { float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f); SetMaterialValues(remappedTime, intensityMultiplier); journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; yield return(null); } SetMaterialValues(FinalNormalizedTime, intensityMultiplier); IsPlaying = false; _coroutine = null; yield return(null); }
/// <summary> /// Blinks the object based on its computed state /// </summary> protected virtual void Blink() { float currentValue = _currentColor.a; float initialValue = Active ? OffValue : OnValue; float targetValue = Active ? OnValue : OffValue; float newValue = targetValue; if (LerpValue && (Time.time - _lastBlinkAt < _currentLerpDuration)) { float t = MMFeedbacksHelpers.Remap(Time.time - _lastBlinkAt, 0f, _currentLerpDuration, 0f, 1f); newValue = Curve.Evaluate(t); newValue = MMFeedbacksHelpers.Remap(newValue, 0f, 1f, initialValue, targetValue); } else { newValue = targetValue; } ApplyBlink(Active, newValue); }
/// <summary> /// This coroutine will modify the values on the target property /// </summary> /// <returns></returns> protected virtual IEnumerator UpdateValueSequence() { float journey = 0f; while (journey < Duration) { float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, Duration, 0f, 1f); SetValues(remappedTime); journey += FeedbackDeltaTime; yield return(null); } SetValues(1f); if (StartsOff) { Turn(false); } yield return(null); }
/// <summary> /// This coroutine will modify the values on the Image /// </summary> /// <returns></returns> protected virtual IEnumerator ImageSequence() { float journey = NormalPlayDirection ? 0f : FeedbackDuration; _imageColor = BoundImage.color; _initialAlpha = BoundImage.color.a; IsPlaying = true; while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0)) { float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f); SetAlpha(remappedTime); journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; yield return(null); } SetAlpha(FinalNormalizedTime); _coroutine = null; IsPlaying = false; yield return(null); }
/// <summary> /// Sets the various values on the light on a specified time (between 0 and 1) /// </summary> /// <param name="time"></param> protected virtual void SetLightValues(float time) { float intensity = MMFeedbacksHelpers.Remap(IntensityCurve.Evaluate(time), 0f, 1f, RemapIntensityZero, RemapIntensityOne); float range = MMFeedbacksHelpers.Remap(RangeCurve.Evaluate(time), 0f, 1f, RemapRangeZero, RemapRangeOne); float shadowStrength = MMFeedbacksHelpers.Remap(ShadowStrengthCurve.Evaluate(time), 0f, 1f, RemapShadowStrengthZero, RemapShadowStrengthOne); if (RelativeValues) { intensity += _initialIntensity; shadowStrength += _initialShadowStrength; range += _initialRange; } BoundLight.intensity = intensity; BoundLight.range = range; BoundLight.shadowStrength = Mathf.Clamp01(shadowStrength); if (ModifyColor) { BoundLight.color = ColorOverTime.Evaluate(time); } }
/// <summary> /// This coroutine will modify the values on the Image /// </summary> /// <returns></returns> protected virtual IEnumerator ImageSequence() { float journey = NormalPlayDirection ? 0f : FeedbackDuration; while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0)) { float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f); SetImageValues(remappedTime); journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; yield return(null); } SetImageValues(FinalNormalizedTime); if (StartsOff) { Turn(false); } _coroutine = null; yield return(null); }
/// <summary> /// Blinks the object based on its computed state /// </summary> protected virtual void Blink() { float currentValue = _currentColor.a; float initialValue = Active ? OffValue : OnValue; float targetValue = Active ? OnValue : OffValue; float newValue = targetValue; if (LerpValue && (Time.time - _lastBlinkAt < _currentLerpDuration)) { float t = MMFeedbacksHelpers.Remap(Time.time - _lastBlinkAt, 0f, _currentLerpDuration, 0f, 1f); newValue = Curve.Evaluate(t); newValue = MMFeedbacksHelpers.Remap(newValue, 0f, 1f, initialValue, targetValue); } else { newValue = targetValue; } switch (Method) { case Methods.SetGameObjectActive: TargetGameObject.SetActive(Active); break; case Methods.MaterialAlpha: _currentColor.a = newValue; TargetRenderer.material.SetColor(_propertyID, _currentColor); break; case Methods.MaterialEmissionIntensity: _currentColor = _initialColor * newValue; TargetRenderer.material.SetColor(_propertyID, _currentColor); break; case Methods.ShaderFloatValue: TargetRenderer.material.SetFloat(_propertyID, newValue); break; } }
/// <summary> /// This coroutine will modify the values on the SpriteRenderer /// </summary> /// <returns></returns> protected virtual IEnumerator SpriteRendererToDestinationSequence(bool andBack) { float journey = NormalPlayDirection ? 0f : FeedbackDuration; IsPlaying = true; Flip(); while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0)) { float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f); if (andBack) { remappedTime = (remappedTime < 0.5f) ? MMFeedbacksHelpers.Remap(remappedTime, 0f, 0.5f, 0f, 1f) : MMFeedbacksHelpers.Remap(remappedTime, 0.5f, 1f, 1f, 0f); } float evalTime = ToDestinationColorCurve.Evaluate(remappedTime); if (ModifyColor) { BoundSpriteRenderer.color = Color.LerpUnclamped(_initialColor, ToDestinationColor, evalTime); } journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; yield return(null); } if (ModifyColor) { BoundSpriteRenderer.color = andBack ? _initialColor : ToDestinationColor; } if (StartsOff) { Turn(false); } _coroutine = null; IsPlaying = false; yield return(null); }
/// <summary> /// This coroutine will modify the values on the target property /// </summary> /// <returns></returns> protected virtual IEnumerator UpdateValueSequence(float feedbacksIntensity) { float journey = NormalPlayDirection ? 0f : FeedbackDuration; IsPlaying = true; while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0)) { float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f); SetValues(remappedTime, feedbacksIntensity); journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; yield return(null); } SetValues(FinalNormalizedTime, feedbacksIntensity); if (StartsOff) { Turn(false); } IsPlaying = false; _coroutine = null; yield return(null); }
/// <summary> /// Computes and applies the rotation to the object /// </summary> /// <param name="targetTransform"></param> /// <param name="multiplier"></param> /// <param name="curveX"></param> /// <param name="curveY"></param> /// <param name="curveZ"></param> /// <param name="percent"></param> protected virtual void ApplyRotation(Transform targetTransform, float remapZero, float remapOne, AnimationCurve curveX, AnimationCurve curveY, AnimationCurve curveZ, float percent) { targetTransform.transform.rotation = _initialRotation; if (AnimateX) { float x = curveX.Evaluate(percent); x = MMFeedbacksHelpers.Remap(x, 0f, 1f, remapZero, remapOne); targetTransform.Rotate(_right, x); } if (AnimateY) { float y = curveY.Evaluate(percent); y = MMFeedbacksHelpers.Remap(y, 0f, 1f, remapZero, remapOne); targetTransform.Rotate(_up, y); } if (AnimateZ) { float z = curveZ.Evaluate(percent); z = MMFeedbacksHelpers.Remap(z, 0f, 1f, remapZero, remapOne); targetTransform.Rotate(_forward, z); } }
/// <summary> /// An internal coroutine used to animate the scale over time /// </summary> /// <param name="targetTransform"></param> /// <param name="vector"></param> /// <param name="duration"></param> /// <param name="curveX"></param> /// <param name="curveY"></param> /// <param name="curveZ"></param> /// <param name="multiplier"></param> /// <returns></returns> protected virtual IEnumerator AnimateScale(Transform targetTransform, Vector3 vector, float duration, AnimationCurve curveX, AnimationCurve curveY, AnimationCurve curveZ, float remapCurveZero = 0f, float remapCurveOne = 1f) { if (targetTransform == null) { yield break; } if ((curveX == null) || (curveY == null) || (curveZ == null)) { yield break; } if (duration == 0f) { yield break; } float journey = NormalPlayDirection ? 0f : duration; _initialScale = targetTransform.localScale; while ((journey >= 0) && (journey <= duration) && (duration > 0)) { vector = Vector3.zero; float percent = Mathf.Clamp01(journey / duration); if (AnimateX) { vector.x = AnimateX ? curveX.Evaluate(percent) + Offset : targetTransform.localScale.x; vector.x = MMFeedbacksHelpers.Remap(vector.x, 0f, 1f, remapCurveZero, remapCurveOne); if (Mode == Modes.Additive) { vector.x += _initialScale.x; } } else { vector.x = targetTransform.localScale.x; } if (AnimateY) { vector.y = AnimateY ? curveY.Evaluate(percent) + Offset : targetTransform.localScale.y; vector.y = MMFeedbacksHelpers.Remap(vector.y, 0f, 1f, remapCurveZero, remapCurveOne); if (Mode == Modes.Additive) { vector.y += _initialScale.y; } } else { vector.y = targetTransform.localScale.y; } if (AnimateZ) { vector.z = AnimateZ ? curveZ.Evaluate(percent) + Offset : targetTransform.localScale.z; vector.z = MMFeedbacksHelpers.Remap(vector.z, 0f, 1f, remapCurveZero, remapCurveOne); if (Mode == Modes.Additive) { vector.z += _initialScale.z; } } else { vector.z = targetTransform.localScale.z; } targetTransform.localScale = vector; if (TimeScale == TimeScales.Scaled) { journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; } else { journey += NormalPlayDirection ? Time.unscaledDeltaTime : -Time.unscaledDeltaTime; } yield return(null); } vector = Vector3.zero; if (AnimateX) { vector.x = AnimateX ? curveX.Evaluate(FinalNormalizedTime) + Offset : targetTransform.localScale.x; vector.x = MMFeedbacksHelpers.Remap(vector.x, 0f, 1f, remapCurveZero, remapCurveOne); if (Mode == Modes.Additive) { vector.x += _initialScale.x; } } else { vector.x = targetTransform.localScale.x; } if (AnimateY) { vector.y = AnimateY ? curveY.Evaluate(FinalNormalizedTime) + Offset : targetTransform.localScale.y; vector.y = MMFeedbacksHelpers.Remap(vector.y, 0f, 1f, remapCurveZero, remapCurveOne); if (Mode == Modes.Additive) { vector.y += _initialScale.y; } } else { vector.y = targetTransform.localScale.y; } if (AnimateZ) { vector.z = AnimateZ ? curveZ.Evaluate(FinalNormalizedTime) + Offset : targetTransform.localScale.z; vector.z = MMFeedbacksHelpers.Remap(vector.z, 0f, 1f, remapCurveZero, remapCurveOne); if (Mode == Modes.Additive) { vector.z += _initialScale.z; } } else { vector.z = targetTransform.localScale.z; } targetTransform.localScale = vector; _coroutine = null; yield return(null); }
/// <summary> /// An internal coroutine used to scale the target to its destination scale /// </summary> /// <returns></returns> protected virtual IEnumerator ScaleToDestination() { if (AnimateScaleTarget == null) { yield break; } if ((AnimateScaleX == null) || (AnimateScaleY == null) || (AnimateScaleZ == null)) { yield break; } if (FeedbackDuration == 0f) { yield break; } float journey = NormalPlayDirection ? 0f : FeedbackDuration; _initialScale = AnimateScaleTarget.localScale; _newScale = _initialScale; while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0)) { float percent = Mathf.Clamp01(journey / FeedbackDuration); if (AnimateX) { _newScale.x = Mathf.LerpUnclamped(_initialScale.x, DestinationScale.x, AnimateScaleX.Evaluate(percent) + Offset); _newScale.x = MMFeedbacksHelpers.Remap(_newScale.x, 0f, 1f, RemapCurveZero, RemapCurveOne); } if (AnimateY) { _newScale.y = Mathf.LerpUnclamped(_initialScale.y, DestinationScale.y, AnimateScaleY.Evaluate(percent) + Offset); _newScale.y = MMFeedbacksHelpers.Remap(_newScale.y, 0f, 1f, RemapCurveZero, RemapCurveOne); } if (AnimateZ) { _newScale.z = Mathf.LerpUnclamped(_initialScale.z, DestinationScale.z, AnimateScaleZ.Evaluate(percent) + Offset); _newScale.z = MMFeedbacksHelpers.Remap(_newScale.z, 0f, 1f, RemapCurveZero, RemapCurveOne); } AnimateScaleTarget.localScale = _newScale; if (TimeScale == TimeScales.Scaled) { journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; } else { journey += NormalPlayDirection ? Time.unscaledDeltaTime : -Time.unscaledDeltaTime; } yield return(null); } AnimateScaleTarget.localScale = NormalPlayDirection ? DestinationScale : _initialScale; _coroutine = null; yield return(null); }
protected virtual void EvaluateCurve(AnimationCurve curve, float percent, Vector3 remapMin, Vector3 remapMax, ref Vector3 returnValue) { returnValue.x = MMFeedbacksHelpers.Remap(curve.Evaluate(percent), 0f, 1f, remapMin.x, remapMax.x); returnValue.y = MMFeedbacksHelpers.Remap(curve.Evaluate(percent), 0f, 1f, remapMin.y, remapMax.y); returnValue.z = MMFeedbacksHelpers.Remap(curve.Evaluate(percent), 0f, 1f, remapMin.z, remapMax.z); }