feat: add option to not automatically plays tweener effect

Added a new option on the tweener effect called "StartMode" to set it to not automatically play on start. eg. you have an image with a UIEffect and UIEffecTweener and do not want the effect to play instantly when the object starts but still want to use Normal/Unscaled update mode to not have to tween values manually in code.
This commit is contained in:
Victor Guilherme
2024-11-29 09:16:45 -03:00
committed by mob-sakai
parent 476a0ba23d
commit 88609f5e36
2 changed files with 44 additions and 7 deletions
@@ -17,6 +17,7 @@ namespace Coffee.UIEffects.Editors
private SerializedProperty _restartOnEnable;
private SerializedProperty _updateMode;
private SerializedProperty _wrapMode;
private SerializedProperty _startMode;
private void OnEnable()
{
@@ -29,6 +30,7 @@ namespace Coffee.UIEffects.Editors
_interval = serializedObject.FindProperty("m_Interval");
_wrapMode = serializedObject.FindProperty("m_WrapMode");
_updateMode = serializedObject.FindProperty("m_UpdateMode");
_startMode = serializedObject.FindProperty("m_StartMode");
}
public override void OnInspectorGUI()
@@ -44,6 +46,7 @@ namespace Coffee.UIEffects.Editors
EditorGUILayout.PropertyField(_restartOnEnable);
EditorGUILayout.PropertyField(_wrapMode);
EditorGUILayout.PropertyField(_updateMode);
EditorGUILayout.PropertyField(_startMode);
serializedObject.ApplyModifiedProperties();
DrawPlayer(target as UIEffectTweener);
Profiler.EndSample();
+41 -7
View File
@@ -22,6 +22,12 @@ namespace Coffee.UIEffects
Manual
}
public enum StartMode
{
Automatic,
Manual
}
public enum WrapMode
{
Once,
@@ -83,6 +89,13 @@ namespace Coffee.UIEffects
[SerializeField]
private UpdateMode m_UpdateMode = UpdateMode.Normal;
[Tooltip("Specifies how the effect tweener will start.\n" +
" Automatic: Plays the tween automatically when it starts.\n" +
" Manual: Waits for the first `Play()` call to start.")]
[SerializeField]
private StartMode m_StartMode = StartMode.Automatic;
public bool _isAwaitingStart;
private float _rate;
private float _time;
private UIEffectBase _target;
@@ -208,23 +221,32 @@ namespace Coffee.UIEffects
set => m_UpdateMode = value;
}
public StartMode startMode
{
get => m_StartMode;
set => m_StartMode = value;
}
public AnimationCurve curve
{
get => m_Curve;
set => m_Curve = value;
}
private void Awake()
{
_isAwaitingStart = m_StartMode == StartMode.Manual;
}
private void Update()
{
switch (m_UpdateMode)
if (m_StartMode == StartMode.Manual && _isAwaitingStart)
{
case UpdateMode.Normal:
UpdateTime(Time.deltaTime);
break;
case UpdateMode.Unscaled:
UpdateTime(Time.unscaledDeltaTime);
break;
return;
}
float deltaTime = m_UpdateMode == UpdateMode.Unscaled ? Time.unscaledDeltaTime : Time.deltaTime;
UpdateTime(deltaTime);
}
private void OnEnable()
@@ -235,6 +257,18 @@ namespace Coffee.UIEffects
}
}
public void Play()
{
_isAwaitingStart = false;
Restart();
}
public void Stop()
{
_isAwaitingStart = true;
Restart();
}
public void Restart()
{
SetTime(0);