/// <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> /// Changes the color of the text's outline 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> /// 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> /// 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; while (journey < AnimateScaleDuration) { float percent = Mathf.Clamp01(journey / AnimateScaleDuration); _newScale.x = Mathf.LerpUnclamped(_initialScale.x, DestinationScale.x, AnimateScaleX.Evaluate(percent) + Offset); _newScale.y = Mathf.LerpUnclamped(_initialScale.y, DestinationScale.y, AnimateScaleY.Evaluate(percent) + Offset); _newScale.z = Mathf.LerpUnclamped(_initialScale.z, DestinationScale.z, AnimateScaleZ.Evaluate(percent) + Offset); _newScale.x = MMFeedbacksHelpers.Remap(_newScale.x, 0f, 1f, RemapCurveZero, RemapCurveOne); _newScale.y = MMFeedbacksHelpers.Remap(_newScale.y, 0f, 1f, RemapCurveZero, RemapCurveOne); _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> /// 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> /// 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> /// 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> /// 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; journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime; yield return(null); } ApplyScale(DestinationScale); SquashAndStretchTarget.localScale = NormalPlayDirection ? _newScale : _initialScale; _coroutine = null; IsPlaying = 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); }
/// <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; _initialScale = targetTransform.localScale; while (journey < duration) { 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; journey += (TimeScale == TimeScales.Scaled) ? Time.deltaTime : Time.unscaledDeltaTime; yield return(null); } vector = Vector3.zero; if (AnimateX) { vector.x = AnimateX ? curveX.Evaluate(1f) + 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(1f) + 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(1f) + 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; yield return(null); }