chore: initial commit

This commit is contained in:
2026-05-08 11:04:00 +08:00
commit f55d2a57c3
6278 changed files with 866081 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
using System;
using System.Collections;
using System.Collections.Generic;
using MoreMountains.Feedbacks;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UIElements;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// This feedback is a base for UI Toolkit feedbacks
/// </summary>
[AddComponentMenu("")]
[FeedbackHelp("This feedback is a base for UI Toolkit feedbacks")]
public class MMF_UIToolkit : MMF_Feedback
{
/// a static bool used to disable all feedbacks of this type at once
public static bool FeedbackTypeAuthorized = true;
/// sets the inspector color for this feedback
#if UNITY_EDITOR
public override Color FeedbackColor { get { return MMFeedbacksInspectorColors.UIColor; } }
public override bool EvaluateRequiresSetup() { return (TargetDocument == null); }
public override string RequiredTargetText { get { return TargetDocument != null ? TargetDocument.name : ""; } }
public override string RequiresSetupText { get { return "This feedback requires a target UI Document, set one in the TargetDocument field below"; } }
#endif
public override bool HasAutomatedTargetAcquisition => true;
protected override void AutomateTargetAcquisition() => TargetDocument = FindAutomatedTarget<UIDocument>();
public enum QueryModes { Name, Class }
[MMFInspectorGroup("Target", true, 54, true)]
/// the UI document on which to make modifications
[Tooltip("the UI document on which to make modifications")]
public UIDocument TargetDocument;
/// the way to perform the query, either via element name or via class
[Tooltip("the way to perform the query, either via element name or via class")]
public QueryModes QueryMode = QueryModes.Name;
/// the query to perform (replace this with your own element name or class)
[Tooltip("the query to perform (replace this with your own element name or class)")]
public string Query = "ButtonA";
/// whether to mark the UI document dirty after the operation. Set this to true when making a change that requires a repaint such as when using generateVisualContent to render a mesh and the mesh data has now changed.
[Tooltip("whether to mark the UI document dirty after the operation. Set this to true when making a change that requires a repaint such as when using generateVisualContent to render a mesh and the mesh data has now changed.")]
public bool MarkDirty = false;
protected List<VisualElement> _visualElements = new List<VisualElement>();
/// <summary>
/// On init we turn the Image off if needed
/// </summary>
/// <param name="owner"></param>
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
PerformQuery();
}
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1)
{
}
/// <summary>
/// Performs the query and sets _visualElements with the result
/// </summary>
protected virtual void PerformQuery()
{
switch (QueryMode)
{
case QueryModes.Name:
_visualElements = TargetDocument.rootVisualElement.Query(Query).ToList();
break;
case QueryModes.Class:
_visualElements = TargetDocument.rootVisualElement.Query(className: Query).ToList();
break;
}
}
protected virtual void HandleMarkDirty(VisualElement element)
{
if (MarkDirty)
{
element.MarkDirtyRepaint();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26da15f4b3a68a54295a67aede05e70b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,97 @@
using System.Collections;
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UIElements;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// A base feedback to set a bool on a target UI Document
/// </summary>
[AddComponentMenu("")]
public class MMF_UIToolkitBoolBase : MMF_UIToolkit
{
/// the duration of this feedback is the duration of the color transition, or 0 if instant
public override float FeedbackDuration { get { return 0f; }}
public override bool HasCustomInspectors => true;
protected bool _initialValue;
/// <summary>
/// On init we store our initial value
/// </summary>
/// <param name="owner"></param>
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
if ((_visualElements == null) || (_visualElements.Count == 0))
{
return;
}
_initialValue = GetInitialValue();
}
/// <summary>
/// On Play we change our text's alpha
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
if ((_visualElements == null) || (_visualElements.Count == 0))
{
return;
}
SetValue();
}
/// <summary>
/// Stops the animation if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
base.CustomStopFeedback(position, feedbacksIntensity);
IsPlaying = false;
}
protected virtual void SetValue()
{
}
protected virtual void SetValue(bool newValue)
{
}
protected virtual bool GetInitialValue()
{
return false;
}
/// <summary>
/// On restore, we put our object back at its initial position
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
SetValue(_initialValue);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 267821bdecaf2b14993cc3df8c285df5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,224 @@
using System.Collections;
using MoreMountains.Feedbacks;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UIElements;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// A base feedback to set a color on a target UI Document
/// </summary>
[AddComponentMenu("")]
public class MMF_UIToolkitColorBase : MMF_UIToolkit
{
/// the duration of this feedback is whatever value's been defined for it
public override float FeedbackDuration { get { return (Mode == Modes.Instant) ? 0f : ApplyTimeMultiplier(Duration); } set { Duration = value; } }
public override bool HasChannel => true;
/// the possible modes for this feedback
public enum Modes { OverTime, Instant }
[MMFInspectorGroup("Color", true, 55, true)]
/// whether the feedback should affect the Image instantly or over a period of time
[Tooltip("whether the feedback should affect the Image instantly or over a period of time")]
public Modes Mode = Modes.OverTime;
/// how long the Image should change over time
[Tooltip("how long the Image should change over time")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public float Duration = 0.2f;
/// if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over
[Tooltip("if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over")]
public bool AllowAdditivePlays = false;
/// whether or not to modify the color of the image
[Tooltip("whether or not to modify the color of the image")]
public bool ModifyColor = true;
/// the colors to apply to the Image over time
[Tooltip("the colors to apply to the Image over time")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public Gradient ColorOverTime =
new Gradient()
{
colorKeys = new GradientColorKey[]
{
new GradientColorKey(Color.white, 0f),
new GradientColorKey(Color.red, 0.5f),
new GradientColorKey(Color.white, 1f)
},
alphaKeys = new GradientAlphaKey[]
{
new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 0.5f),
new GradientAlphaKey(1f, 1f)
}
};
/// the color to move to in instant mode
[Tooltip("the color to move to in instant mode")]
[MMFEnumCondition("Mode", (int)Modes.Instant)]
public Color InstantColor;
/// if this is true, the initial color will be applied to the gradient start
[Tooltip("if this is true, the initial color will be applied to the gradient start")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public bool ApplyInitialColorToGradientStart = false;
/// if this is true, the initial color will be applied to the gradient end
[Tooltip("if this is true, the initial color will be applied to the gradient end")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public bool ApplyInitialColorToGradientEnd = false;
/// if this is true, the initial color will be applied to the gradient start and end on play
[FormerlySerializedAs("GrabInitialColorsOnPlay")]
[Tooltip("if this is true, the initial color will be applied to the gradient start and end on play")]
[MMFEnumCondition("Mode", (int)Modes.OverTime)]
public bool ApplyInitialColorsOnPlay = true;
protected Coroutine _coroutine;
protected Color _initialColor;
/// <summary>
/// On init we turn the Image off if needed
/// </summary>
/// <param name="owner"></param>
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
HandleApplyInitialColors();
}
protected virtual void HandleApplyInitialColors()
{
var colorKeys = ColorOverTime.colorKeys;
var alphaKeys = ColorOverTime.alphaKeys;
if (ApplyInitialColorToGradientStart)
{
colorKeys[0] = new GradientColorKey(GetInitialColor(),0f);
alphaKeys[0] = new GradientAlphaKey(GetInitialColor().a,0f);
}
if (ApplyInitialColorToGradientEnd)
{
int lastIndex = ColorOverTime.colorKeys.Length - 1;
colorKeys[lastIndex] = new GradientColorKey(GetInitialColor(),1f);
alphaKeys[lastIndex] = new GradientAlphaKey(GetInitialColor().a,1f);
}
if (ApplyInitialColorToGradientEnd || ApplyInitialColorToGradientStart)
{
ColorOverTime.SetKeys(colorKeys, alphaKeys);
}
}
protected virtual void ApplyColor(Color newColor)
{
}
protected virtual Color GetInitialColor()
{
return Color.white;
}
/// <summary>
/// On Play we turn our Image on and start an over time coroutine if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
_initialColor = GetInitialColor();
if (ApplyInitialColorsOnPlay)
{
HandleApplyInitialColors();
}
switch (Mode)
{
case Modes.Instant:
if (ModifyColor)
{
ApplyColor(InstantColor);
}
break;
case Modes.OverTime:
if (!AllowAdditivePlays && (_coroutine != null))
{
return;
}
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(ImageSequence());
break;
}
}
/// <summary>
/// This coroutine will modify the values on the Image
/// </summary>
/// <returns></returns>
protected virtual IEnumerator ImageSequence()
{
float journey = NormalPlayDirection ? 0f : FeedbackDuration;
IsPlaying = true;
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);
IsPlaying = false;
_coroutine = null;
yield return null;
}
/// <summary>
/// Sets the various values on the sprite renderer on a specified time (between 0 and 1)
/// </summary>
/// <param name="time"></param>
protected virtual void SetImageValues(float time)
{
if (ModifyColor)
{
ApplyColor(ColorOverTime.Evaluate(time));
}
}
/// <summary>
/// Turns the sprite renderer off on stop
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
IsPlaying = false;
base.CustomStopFeedback(position, feedbacksIntensity);
_coroutine = null;
}
/// <summary>
/// On restore, we restore our initial state
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
ApplyColor(_initialColor);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f642848870e854947bbbb090be8948d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,216 @@
using System.Collections;
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UIElements;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// A base feedback to set a float on a target UI Document
/// </summary>
[AddComponentMenu("")]
public class MMF_UIToolkitFloatBase : MMF_UIToolkit
{
/// a static bool used to disable all feedbacks of this type at once
public enum Modes { Instant, Interpolate, ToDestination }
/// the duration of this feedback is the duration of the color transition, or 0 if instant
public override float FeedbackDuration { get { return (Mode == Modes.Instant) ? 0f : ApplyTimeMultiplier(Duration); } set { Duration = value; } }
public override bool HasCustomInspectors => true;
[MMFInspectorGroup("Value", true, 16)]
/// the selected color mode :
/// None : nothing will happen,
/// gradient : evaluates the color over time on that gradient, from left to right,
/// interpolate : lerps from the current color to the destination one
[Tooltip("the selected mode :" +
"Instant : the value will change instantly to the target one," +
"Curve : the value will be interpolated along the curve," +
"interpolate : lerps from the current value to the destination one ")]
public Modes Mode = Modes.Interpolate;
/// whether or not the value should be applied relatively to the initial value
[Tooltip("whether or not the value should be applied relatively to the initial value")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate, (int)Modes.Instant)]
public bool RelativeValue = false;
/// if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over
[Tooltip("if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over")]
public bool AllowAdditivePlays = false;
/// how long the color of the text should change over time
[Tooltip("how long the color of the text should change over time")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate, (int)Modes.ToDestination)]
public float Duration = 0.2f;
/// the value to apply when in instant mode
[Tooltip("the value to apply when in instant mode")]
[MMFEnumCondition("Mode", (int)Modes.Instant)]
public float InstantValue = 1f;
/// the curve to use when interpolating towards the destination value
[Tooltip("the curve to use when interpolating towards the destination value")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate, (int)Modes.ToDestination)]
public MMTweenType Curve = new MMTweenType(MMTween.MMTweenCurve.EaseInCubic);
/// the value to which the curve's 0 should be remapped
[Tooltip("the value to which the curve's 0 should be remapped")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate)]
public float CurveRemapZero = 0f;
/// the value to which the curve's 1 should be remapped
[Tooltip("the value to which the curve's 1 should be remapped")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate)]
public float CurveRemapOne = 1f;
/// the value to aim towards when in ToDestination mode
[Tooltip("the value to aim towards when in ToDestination mode")]
[MMFEnumCondition("Mode", (int)Modes.ToDestination)]
public float DestinationValue = 1f;
protected float _initialValue;
protected Coroutine _coroutine;
/// <summary>
/// On init we store our initial value
/// </summary>
/// <param name="owner"></param>
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
if ((_visualElements == null) || (_visualElements.Count == 0))
{
return;
}
_initialValue = GetInitialValue();
}
/// <summary>
/// On Play we change our text's alpha
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
if ((_visualElements == null) || (_visualElements.Count == 0))
{
return;
}
if (RelativeValue)
{
_initialValue = GetInitialValue();
}
switch (Mode)
{
case Modes.Instant:
float newInstantValue = RelativeValue ? InstantValue + _initialValue : InstantValue;
SetValue(newInstantValue);
break;
case Modes.Interpolate:
if (!AllowAdditivePlays && (_coroutine != null))
{
return;
}
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(ChangeValue());
break;
case Modes.ToDestination:
if (!AllowAdditivePlays && (_coroutine != null))
{
return;
}
_initialValue = GetInitialValue();
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(ChangeValue());
break;
}
}
/// <summary>
/// Changes the color of the text over time
/// </summary>
/// <returns></returns>
protected virtual IEnumerator ChangeValue()
{
float journey = NormalPlayDirection ? 0f : FeedbackDuration;
IsPlaying = true;
while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0))
{
float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f);
ApplyTime(remappedTime);
journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime;
yield return null;
}
ApplyTime(FinalNormalizedTime);
_coroutine = null;
IsPlaying = false;
yield break;
}
/// <summary>
/// Stops the animation if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
base.CustomStopFeedback(position, feedbacksIntensity);
IsPlaying = false;
if (_coroutine != null)
{
Owner.StopCoroutine(_coroutine);
_coroutine = null;
}
}
/// <summary>
/// Applies the alpha change
/// </summary>
/// <param name="time"></param>
protected virtual void ApplyTime(float time)
{
float newValue = 0f;
if (Mode == Modes.Interpolate)
{
float startValue = RelativeValue ? CurveRemapZero + _initialValue : CurveRemapZero;
float endValue = RelativeValue ? CurveRemapOne + _initialValue : CurveRemapOne;
newValue = MMTween.Tween(time, 0f, 1f, startValue, endValue, Curve);
}
else if (Mode == Modes.ToDestination)
{
newValue = MMTween.Tween(time, 0f, 1f, _initialValue, DestinationValue, Curve);
}
SetValue(newValue);
}
protected virtual void SetValue(float newValue)
{
}
protected virtual float GetInitialValue()
{
return 0f;
}
/// <summary>
/// On restore, we put our object back at its initial position
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
SetValue(_initialValue);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 889e935e9689c09488cc64807a889d5e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,263 @@
using System.Collections;
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UIElements;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// A base feedback to set a vector2 on a target UI Document
/// </summary>
[AddComponentMenu("")]
public class MMF_UIToolkitVector2Base : MMF_UIToolkit
{
/// a static bool used to disable all feedbacks of this type at once
public enum Modes { Instant, Interpolate, ToDestination }
/// the duration of this feedback is the duration of the color transition, or 0 if instant
public override float FeedbackDuration { get { return (Mode == Modes.Instant) ? 0f : ApplyTimeMultiplier(Duration); } set { Duration = value; } }
public override bool HasCustomInspectors => true;
[MMFInspectorGroup("Value", true, 16)]
/// the selected color mode :
/// None : nothing will happen,
/// gradient : evaluates the color over time on that gradient, from left to right,
/// interpolate : lerps from the current color to the destination one
[Tooltip("the selected mode :" +
"Instant : the value will change instantly to the target one," +
"Curve : the value will be interpolated along the curve," +
"interpolate : lerps from the current value to the destination one ")]
public Modes Mode = Modes.Interpolate;
/// whether or not the value should be applied relatively to the initial value
[Tooltip("whether or not the value should be applied relatively to the initial value")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate, (int)Modes.Instant)]
public bool RelativeValues = false;
/// if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over
[Tooltip("if this is true, calling that feedback will trigger it, even if it's in progress. If it's false, it'll prevent any new Play until the current one is over")]
public bool AllowAdditivePlays = false;
/// how long the color of the text should change over time
[Tooltip("how long the color of the text should change over time")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate, (int)Modes.ToDestination)]
public float Duration = 0.2f;
/// the value to apply when in instant mode
[Tooltip("the value to apply when in instant mode")]
[MMFEnumCondition("Mode", (int)Modes.Instant)]
public Vector2 InstantValue = new Vector2(1f, 1f);
[Header("X")]
/// whether or not to animate the x value
[Tooltip("whether or not to animate the x value")]
public bool AnimateX = true;
/// the curve to use when interpolating towards the destination value
[Tooltip("the curve to use when interpolating towards the destination value")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate, (int)Modes.ToDestination)]
public MMTweenType CurveX = new MMTweenType(MMTween.MMTweenCurve.EaseInCubic);
/// the value to which the curve's 0 should be remapped
[Tooltip("the value to which the curve's 0 should be remapped")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate)]
public float CurveRemapZeroX = 0f;
/// the value to which the curve's 1 should be remapped
[Tooltip("the value to which the curve's 1 should be remapped")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate)]
public float CurveRemapOneX = 1f;
/// the value to aim towards when in ToDestination mode
[Tooltip("the value to aim towards when in ToDestination mode")]
[MMFEnumCondition("Mode", (int)Modes.ToDestination)]
public float DestinationValueX = 1f;
[Header("Y")]
/// whether or not to animate the y value
[Tooltip("whether or not to animate the y value")]
public bool AnimateY = true;
/// the curve to use when interpolating towards the destination value
[Tooltip("the curve to use when interpolating towards the destination value")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate, (int)Modes.ToDestination)]
public MMTweenType CurveY = new MMTweenType(MMTween.MMTweenCurve.EaseInCubic);
/// the value to which the curve's 0 should be remapped
[Tooltip("the value to which the curve's 0 should be remapped")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate)]
public float CurveRemapZeroY = 0f;
/// the value to which the curve's 1 should be remapped
[Tooltip("the value to which the curve's 1 should be remapped")]
[MMFEnumCondition("Mode", (int)Modes.Interpolate)]
public float CurveRemapOneY = 1f;
/// the value to aim towards when in ToDestination mode
[Tooltip("the value to aim towards when in ToDestination mode")]
[MMFEnumCondition("Mode", (int)Modes.ToDestination)]
public float DestinationValueY = 1f;
protected Vector2 _initialValue;
protected Coroutine _coroutine;
protected Vector2 _newValue;
/// <summary>
/// On init we store our initial value
/// </summary>
/// <param name="owner"></param>
protected override void CustomInitialization(MMF_Player owner)
{
base.CustomInitialization(owner);
if ((_visualElements == null) || (_visualElements.Count == 0))
{
return;
}
_initialValue = GetInitialValue();
}
/// <summary>
/// On Play we change our text's alpha
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
if ((_visualElements == null) || (_visualElements.Count == 0))
{
return;
}
if (RelativeValues)
{
_initialValue = GetInitialValue();
}
switch (Mode)
{
case Modes.Instant:
Vector2 newInstantValue = RelativeValues ? InstantValue + _initialValue : InstantValue;
SetValue(newInstantValue);
break;
case Modes.Interpolate:
if (!AllowAdditivePlays && (_coroutine != null))
{
return;
}
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(ChangeValue());
break;
case Modes.ToDestination:
if (!AllowAdditivePlays && (_coroutine != null))
{
return;
}
_initialValue = GetInitialValue();
if (_coroutine != null) { Owner.StopCoroutine(_coroutine); }
_coroutine = Owner.StartCoroutine(ChangeValue());
break;
}
}
/// <summary>
/// Changes the color of the text over time
/// </summary>
/// <returns></returns>
protected virtual IEnumerator ChangeValue()
{
float journey = NormalPlayDirection ? 0f : FeedbackDuration;
IsPlaying = true;
while ((journey >= 0) && (journey <= FeedbackDuration) && (FeedbackDuration > 0))
{
float remappedTime = MMFeedbacksHelpers.Remap(journey, 0f, FeedbackDuration, 0f, 1f);
ApplyTime(remappedTime);
journey += NormalPlayDirection ? FeedbackDeltaTime : -FeedbackDeltaTime;
yield return null;
}
ApplyTime(FinalNormalizedTime);
_coroutine = null;
IsPlaying = false;
yield break;
}
/// <summary>
/// Stops the animation if needed
/// </summary>
/// <param name="position"></param>
/// <param name="feedbacksIntensity"></param>
protected override void CustomStopFeedback(Vector3 position, float feedbacksIntensity = 1)
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
base.CustomStopFeedback(position, feedbacksIntensity);
IsPlaying = false;
if (_coroutine != null)
{
Owner.StopCoroutine(_coroutine);
_coroutine = null;
}
}
/// <summary>
/// Applies the alpha change
/// </summary>
/// <param name="time"></param>
protected virtual void ApplyTime(float time)
{
_newValue.x = _initialValue.x;
_newValue.y = _initialValue.y;
if (Mode == Modes.Interpolate)
{
if (AnimateX)
{
float startValueX = RelativeValues ? CurveRemapZeroX + _initialValue.x : CurveRemapZeroX;
float endValueX = RelativeValues ? CurveRemapOneX + _initialValue.x : CurveRemapOneX;
_newValue.x = MMTween.Tween(time, 0f, 1f, startValueX, endValueX, CurveX);
}
if (AnimateY)
{
float startValueY = RelativeValues ? CurveRemapZeroY + _initialValue.y : CurveRemapZeroY;
float endValueY = RelativeValues ? CurveRemapOneY + _initialValue.y : CurveRemapOneY;
_newValue.y = MMTween.Tween(time, 0f, 1f, startValueY, endValueY, CurveY);
}
}
else if (Mode == Modes.ToDestination)
{
if (AnimateX)
{
_newValue.x = MMTween.Tween(time, 0f, 1f, _initialValue.x, DestinationValueX, CurveX);
}
if (AnimateY)
{
_newValue.y = MMTween.Tween(time, 0f, 1f, _initialValue.y, DestinationValueY, CurveY);
}
}
SetValue(_newValue);
}
protected virtual void SetValue(Vector2 newValue)
{
}
protected virtual Vector2 GetInitialValue()
{
return Vector2.zero;
}
/// <summary>
/// On restore, we put our object back at its initial position
/// </summary>
protected override void CustomRestoreInitialValues()
{
if (!Active || !FeedbackTypeAuthorized)
{
return;
}
SetValue(_initialValue);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2ac2960c7e2121849bdf55de52559dd9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: