protected virtual void StartFading(float initialAlpha, float endAlpha, float duration, MMTween.MMTweenCurve curve, int id, bool ignoreTimeScale, Vector3 worldPosition) { if (id != ID) { return; } if (TargetCamera == null) { Debug.LogWarning(this.name + " : You're using a fader round but its TargetCamera hasn't been setup in its inspector. It can't fade."); return; } FaderMask.anchoredPosition = Vector3.zero; Vector3 viewportPosition = TargetCamera.WorldToViewportPoint(worldPosition); viewportPosition.x = Mathf.Clamp01(viewportPosition.x); viewportPosition.y = Mathf.Clamp01(viewportPosition.y); viewportPosition.z = Mathf.Clamp01(viewportPosition.z); FaderMask.anchorMin = viewportPosition; FaderMask.anchorMax = viewportPosition; IgnoreTimescale = ignoreTimeScale; EnableFader(); _fading = true; _initialScale = initialAlpha; _currentTargetScale = endAlpha; _fadeStartedAt = IgnoreTimescale ? Time.unscaledTime : Time.time; _currentCurve = curve; _currentDuration = duration; }
protected static IEnumerator RotateTransformAroundCo(Transform targetTransform, Transform center, Transform destination, float angle, WaitForSeconds delay, float delayDuration, float duration, MMTween.MMTweenCurve curve, bool ignoreTimescale = false) { if (delayDuration > 0f) { yield return(delay); } Vector3 initialRotationPosition = targetTransform.transform.position; Quaternion initialRotationRotation = targetTransform.transform.rotation; float rate = 1f / duration; float timeSpent = 0f; while (timeSpent < duration) { float newAngle = MMTween.Tween(timeSpent, 0f, duration, 0f, angle, curve); targetTransform.transform.position = initialRotationPosition; initialRotationRotation = targetTransform.transform.rotation; targetTransform.RotateAround(center.transform.position, center.transform.up, newAngle); targetTransform.transform.rotation = initialRotationRotation; timeSpent += ignoreTimescale ? Time.unscaledDeltaTime : Time.deltaTime; yield return(null); } targetTransform.transform.position = destination.position; }
/// <summary> /// Creates an animation curve of the specified type and resolution, and adds it to the specified asset /// </summary> /// <param name="asset"></param> /// <param name="curveType"></param> /// <param name="curveResolution"></param> /// <param name="anti"></param> protected virtual void CreateAnimationCurve(ScriptableObject asset, MMTween.MMTweenCurve curveType, int curveResolution, bool anti) { // generates an animation curve AnimationCurve animationCurve = new AnimationCurve(); for (int i = 0; i < curveResolution; i++) { _keyframe.time = i / (curveResolution - 1f); if (anti) { _keyframe.value = MMTween.Tween(_keyframe.time, 0f, 1f, 1f, 0f, curveType); } else { _keyframe.value = MMTween.Tween(_keyframe.time, 0f, 1f, 0f, 1f, curveType); } animationCurve.AddKey(_keyframe); } // smoothes the curve's tangents for (int j = 0; j < curveResolution; j++) { animationCurve.SmoothTangents(j, 0f); } // we add the curve to the scriptable object _parameters = new object[] { animationCurve, curveType.ToString() }; _addMethodInfo.Invoke(asset, _parameters); }
protected static IEnumerator MoveTransformCo(Transform targetTransform, Transform origin, Transform destination, WaitForSeconds delay, float delayDuration, float duration, MMTween.MMTweenCurve curve, bool updatePosition = true, bool updateRotation = true, bool ignoreTimescale = false) { if (delayDuration > 0f) { yield return(delay); } float timeLeft = duration; while (timeLeft > 0f) { if (updatePosition) { targetTransform.transform.position = MMTween.Tween(duration - timeLeft, 0f, duration, origin.position, destination.position, curve); } if (updateRotation) { targetTransform.transform.rotation = MMTween.Tween(duration - timeLeft, 0f, duration, origin.rotation, destination.rotation, curve); } timeLeft -= ignoreTimescale ? Time.unscaledDeltaTime : Time.deltaTime; yield return(null); } if (updatePosition) { targetTransform.transform.position = destination.position; } if (updateRotation) { targetTransform.transform.localEulerAngles = destination.localEulerAngles; } }
public MMSpriteMaskEvent(MMSpriteMaskEventTypes eventType, Vector2 newPosition, Vector2 newSize, float duration, MMTween.MMTweenCurve curve) { EventType = eventType; NewPosition = newPosition; NewSize = newSize; Duration = duration; Curve = curve; }
/// <summary> /// Initializes a new instance of the <see cref="MoreMountains.MMInterface.MMFadeInEvent"/> struct. /// </summary> /// <param name="duration">Duration.</param> public MMFadeInEvent(float duration, MMTween.MMTweenCurve tween = MMTween.MMTweenCurve.LinearTween, int id = 0, bool ignoreTimeScale = true, Vector3 worldPosition = new Vector3()) { ID = id; Duration = duration; Curve = tween; IgnoreTimeScale = ignoreTimeScale; WorldPosition = worldPosition; }
public static void Trigger(float duration, MMTween.MMTweenCurve tween = MMTween.MMTweenCurve.LinearTween, int id = 0, bool ignoreTimeScale = true, Vector3 worldPosition = new Vector3()) { e.ID = id; e.Duration = duration; e.Curve = tween; e.IgnoreTimeScale = ignoreTimeScale; e.WorldPosition = worldPosition; MMEventManager.TriggerEvent(e); }
protected virtual void StartFading(float initialAlpha, float endAlpha, float duration, MMTween.MMTweenCurve curve, int id, bool ignoreTimeScale) { if (id != ID) { return; } IgnoreTimescale = ignoreTimeScale; EnableFader(); _fading = true; _initialAlpha = initialAlpha; _currentTargetAlpha = endAlpha; _fadeStartedAt = IgnoreTimescale ? Time.unscaledTime : Time.time; _currentCurve = curve; _currentDuration = duration; }
/// <summary> /// if we get a PostProcessingTriggerEvent /// </summary> /// <param name="curve"></param> /// <param name="active"></param> /// <param name="duration"></param> /// <param name="channel"></param> public virtual void OnMMPostProcessingMovingFilterEvent(MMTween.MMTweenCurve curve, bool active, bool toggle, float duration, int channel = 0) { if ((channel != Channel) && (channel != -1) && (Channel != -1)) { return; } Curve = curve; _duration = duration; if (toggle) { Active = !Active; } else { Active = active; } float currentTime = (TimeScale == TimeScales.Unscaled) ? Time.unscaledTime : Time.time; _lastMovementStartedAt = currentTime; }
public MMTweenType(MMTween.MMTweenCurve newCurve) { MMTweenCurve = newCurve; MMTweenDefinitionType = MMTweenDefinitionTypes.MMTween; }
public static void Trigger(MMSpriteMaskEventTypes eventType, Vector2 newPosition, Vector2 newSize, float duration, MMTween.MMTweenCurve curve) { e.EventType = eventType; e.NewPosition = newPosition; e.NewSize = newSize; e.Duration = duration; e.Curve = curve; MMEventManager.TriggerEvent(e); }
/// <summary> /// A coroutine that expands the mask to cover both its current position and its destination area, then resizes itself to match the destination size /// </summary> /// <param name="newPosition"></param> /// <param name="newSize"></param> /// <param name="duration"></param> /// <param name="curve"></param> /// <returns></returns> protected virtual IEnumerator ExpandAndMoveMaskToCoroutine(Vector2 newPosition, Vector2 newSize, float duration, MMTween.MMTweenCurve curve) { if (duration > 0) { _initialPosition = this.transform.position; _initialScale = this.transform.localScale; float startedAt = MaskTime; // first we move to the total size and position _targetScale.x = this.transform.localScale.x / 2f + Mathf.Abs((this.transform.position - (Vector3)newPosition).x) * ScaleMultiplier + ComputeTargetScale(newSize).x / 2f; _targetScale.y = this.transform.localScale.y / 2f + Mathf.Abs((this.transform.position - (Vector3)newPosition).y) * ScaleMultiplier + ComputeTargetScale(newSize).y / 2f; _targetScale.z = 1f; _targetPosition = ( (this.transform.position + (Vector3.up * this.transform.localScale.y / ScaleMultiplier / 2f) + (Vector3.left * this.transform.localScale.x / ScaleMultiplier / 2f)) + ((Vector3)newPosition + (Vector3.down * newSize.y / 2f) + (Vector3.right * newSize.x / 2f)) ) / 2f; while (MaskTime - startedAt <= (duration / 2f)) { float currentTime = MaskTime - startedAt; _newPosition = MMTween.Tween(currentTime, 0f, (duration / 2f), _initialPosition, _targetPosition, curve); _newScale = MMTween.Tween(currentTime, 0f, (duration / 2f), _initialScale, _targetScale, curve); this.transform.position = _newPosition; this.transform.localScale = _newScale; yield return(null); } // then we move to the final position startedAt = MaskTime; _initialPosition = this.transform.position; _initialScale = this.transform.localScale; _targetPosition = ComputeTargetPosition(newPosition); _targetScale = ComputeTargetScale(newSize); while (MaskTime - startedAt <= duration / 2f) { float currentTime = MaskTime - startedAt; _newPosition = MMTween.Tween(currentTime, 0f, (duration / 2f), _initialPosition, _targetPosition, curve); _newScale = MMTween.Tween(currentTime, 0f, (duration / 2f), _initialScale, _targetScale, curve); this.transform.position = _newPosition; this.transform.localScale = _newScale; yield return(null); } } this.transform.position = ComputeTargetPosition(newPosition); this.transform.localScale = ComputeTargetScale(newSize); }
protected static IEnumerator MoveRectTransformCo(RectTransform targetTransform, Vector3 origin, Vector3 destination, WaitForSeconds delay, float delayDuration, float duration, MMTween.MMTweenCurve curve) { if (delayDuration > 0f) { yield return(delay); } float timeLeft = duration; while (timeLeft > 0f) { targetTransform.localPosition = MMTween.Tween(duration - timeLeft, 0f, duration, origin, destination, curve); timeLeft -= Time.deltaTime; yield return(null); } targetTransform.localPosition = destination; }
/// <summary> /// Coroutine that moves the mask /// </summary> /// <param name="newPosition"></param> /// <param name="newSize"></param> /// <param name="duration"></param> /// <param name="curve"></param> /// <returns></returns> protected virtual IEnumerator MoveMaskToCoroutine(Vector2 newPosition, Vector2 newSize, float duration, MMTween.MMTweenCurve curve) { if (duration > 0) { _initialPosition = this.transform.position; _initialScale = this.transform.localScale; _targetPosition = ComputeTargetPosition(newPosition); _targetScale = ComputeTargetScale(newSize); float startedAt = MaskTime; while (MaskTime - startedAt <= duration) { float currentTime = MaskTime - startedAt; _newPosition = MMTween.Tween(currentTime, 0f, duration, _initialPosition, _targetPosition, curve); _newScale = MMTween.Tween(currentTime, 0f, duration, _initialScale, _targetScale, curve); this.transform.position = _newPosition; this.transform.localScale = _newScale; yield return(null); } } this.transform.position = ComputeTargetPosition(newPosition); this.transform.localScale = ComputeTargetScale(newSize); }
/// <summary> /// Moves the mask to a new size and position after having expanded to encompass its origin size/position and /// the destination's size/position /// </summary> /// <param name="newPosition"></param> /// <param name="newSize"></param> /// <param name="duration"></param> /// <param name="curve"></param> public virtual void ExpandAndMoveMaskTo(Vector2 newPosition, Vector2 newSize, float duration, MMTween.MMTweenCurve curve) { StartCoroutine(ExpandAndMoveMaskToCoroutine(newPosition, newSize, duration, curve)); }
public static Coroutine RotateTransformAround(MonoBehaviour mono, Transform targetTransform, Transform center, Transform destination, float angle, WaitForSeconds delay, float delayDuration, float duration, MMTween.MMTweenCurve curve) { return(mono.StartCoroutine(RotateTransformAroundCo(targetTransform, center, destination, angle, delay, delayDuration, duration, curve))); }
public static Coroutine MoveTransform(MonoBehaviour mono, Transform targetTransform, Transform origin, Transform destination, WaitForSeconds delay, float delayDuration, float duration, MMTween.MMTweenCurve curve, bool updatePosition = true, bool updateRotation = true) { return(mono.StartCoroutine(MoveTransformCo(targetTransform, origin, destination, delay, delayDuration, duration, curve, updatePosition, updateRotation))); }
/// <summary> /// Returns the corresponding value based on the selected SignalType for a given time value /// </summary> /// <param name="time"></param> /// <param name="signalType"></param> /// <param name="phase"></param> /// <param name="amplitude"></param> /// <param name="frequency"></param> /// <param name="offset"></param> /// <param name="Invert"></param> /// <returns></returns> public static float GetValue(float time, SignalType signalType, float phase, float amplitude, float frequency, float offset, bool Invert = false, AnimationCurve curve = null, MMTween.MMTweenCurve tweenCurve = MMTween.MMTweenCurve.LinearTween) { float value = 0f; float invert = Invert ? -1 : 1; float t = frequency * time + phase; switch (signalType) { case SignalType.Sine: value = (float)Mathf.Sin(2f * Mathf.PI * t); break; case SignalType.Square: value = Mathf.Sign(Mathf.Sin(2f * Mathf.PI * t)); break; case SignalType.Triangle: value = 1f - 4f * (float)Mathf.Abs(Mathf.Round(t - 0.25f) - (t - 0.25f)); break; case SignalType.Sawtooth: value = 2f * (t - (float)Mathf.Floor(t + 0.5f)); break; case SignalType.Pulse: value = (Mathf.Abs(Mathf.Sin(2 * Mathf.PI * t)) < 1.0 - 10E-3) ? (0) : (1); break; case SignalType.WhiteNoise: value = 2f * Random.Range(0, int.MaxValue) / int.MaxValue - 1f; break; case SignalType.DigitalNoise: value = Random.Range(0, 2); break; case SignalType.PerlinNoise: value = Mathf.PerlinNoise(time * frequency, time * amplitude); break; case SignalType.ValueNoise: value = ValueNoise(time, frequency) * amplitude; break; case SignalType.AnimationCurve: if (curve == null) { return(0f); } t = (t != 1f) ? t - Mathf.Floor(t) : 1f; value = curve.Evaluate(t); break; case SignalType.MMTween: t = (t != 1f) ? t - Mathf.Floor(t) : 1f; value = MMTween.Tween(t, 0f, 1f, 0f, 1f, tweenCurve); break; } return(invert * amplitude * value + offset); }
public static float GetValueNormalized(float time, SignalType signalType, float phase, float amplitude, float frequency, float offset, bool Invert = false, AnimationCurve curve = null, MMTween.MMTweenCurve tweenCurve = MMTween.MMTweenCurve.LinearTween, bool clamp = true, float clampMin = 0f, float clampMax = 1f, bool backAndForth = false, float backAndForthTippingPoint = 0.5f) { float value = 0f; float invert = Invert ? -1 : 1; if (backAndForth) { if (time < backAndForthTippingPoint) { time = MMMaths.Remap(time, 0f, backAndForthTippingPoint, 0f, 1f); } else if (time == backAndForthTippingPoint) { time = 1f; } else if (time > backAndForthTippingPoint) { time = MMMaths.Remap(time, backAndForthTippingPoint, 1f, 1f, 0f); } } float t = frequency * time + phase; switch (signalType) { case SignalType.Sine: value = (float)Mathf.Sin(2f * Mathf.PI * t); value = MMMaths.Remap(value, -1f, 1f, 0f, 1f); break; case SignalType.Square: value = Mathf.Sign(Mathf.Sin(2f * Mathf.PI * t)); value = MMMaths.Remap(value, -1f, 1f, 0f, 1f); break; case SignalType.Triangle: value = 1f - 4f * (float)Mathf.Abs(Mathf.Round(t - 0.25f) - (t - 0.25f)); value = MMMaths.Remap(value, -1f, 1f, 0f, 1f); break; case SignalType.Sawtooth: value = 2f * (t - (float)Mathf.Floor(t + 0.5f)); value = MMMaths.Remap(value, -1f, 1f, 0f, 1f); break; case SignalType.Pulse: value = (Mathf.Abs(Mathf.Sin(2 * Mathf.PI * t)) < 1.0 - 10E-3) ? (0) : (1); break; case SignalType.WhiteNoise: value = 2f * Random.Range(0, int.MaxValue) / int.MaxValue - 1f; value = MMMaths.Remap(value, -1f, 1f, 0f, 1f); break; case SignalType.DigitalNoise: value = Random.Range(0, 2); break; case SignalType.PerlinNoise: value = Mathf.PerlinNoise(t, t * amplitude); break; case SignalType.ValueNoise: value = ValueNoise(time, frequency) * amplitude; break; case SignalType.AnimationCurve: if (curve == null) { return(0f); } t = (t != 1f) ? t - Mathf.Floor(t) : 1f; value = curve.Evaluate(t); break; case SignalType.MMTween: t = (t != 1f) ? t - Mathf.Floor(t) : 1f; value = MMTween.Tween(t, 0f, 1f, 0f, 1f, tweenCurve); break; } if (Invert) { value = MMMaths.Remap(value, 0f, 1f, 1f, 0f); } float returnValue = amplitude * value + offset; // we clamp the value if (clamp) { returnValue = Mathf.Clamp(returnValue, clampMin, clampMax); } return(returnValue); }
protected static IEnumerator MoveTransformCo(Transform targetTransform, Vector3 origin, Vector3 destination, WaitForSeconds delay, float delayDuration, float duration, MMTween.MMTweenCurve curve, bool ignoreTimescale = false) { if (delayDuration > 0f) { yield return(delay); } float timeLeft = duration; while (timeLeft > 0f) { targetTransform.transform.position = MMTween.Tween(duration - timeLeft, 0f, duration, origin, destination, curve); timeLeft -= ignoreTimescale ? Time.unscaledDeltaTime : Time.deltaTime; yield return(null); } targetTransform.transform.position = destination; }
public static Coroutine MoveRectTransform(MonoBehaviour mono, RectTransform targetTransform, Vector3 origin, Vector3 destination, WaitForSeconds delay, float delayDuration, float duration, MMTween.MMTweenCurve curve, bool ignoreTimescale = false) { return(mono.StartCoroutine(MoveRectTransformCo(targetTransform, origin, destination, delay, delayDuration, duration, curve, ignoreTimescale))); }
static public void Trigger(MMTween.MMTweenCurve curve, bool active, bool toggle, float duration, int channel = 0) { OnEvent?.Invoke(curve, active, toggle, duration, channel); }