Skip to content

Commit 88609f5

Browse files
vgArchivesmob-sakai
authored andcommitted
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.
1 parent 476a0ba commit 88609f5

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

Packages/src/Editor/UIEffectTweenerEditor.cs

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ internal class UIMaterialPropertyTweenerEditor : Editor
1717
private SerializedProperty _restartOnEnable;
1818
private SerializedProperty _updateMode;
1919
private SerializedProperty _wrapMode;
20+
private SerializedProperty _startMode;
2021

2122
private void OnEnable()
2223
{
@@ -29,6 +30,7 @@ private void OnEnable()
2930
_interval = serializedObject.FindProperty("m_Interval");
3031
_wrapMode = serializedObject.FindProperty("m_WrapMode");
3132
_updateMode = serializedObject.FindProperty("m_UpdateMode");
33+
_startMode = serializedObject.FindProperty("m_StartMode");
3234
}
3335

3436
public override void OnInspectorGUI()
@@ -44,6 +46,7 @@ public override void OnInspectorGUI()
4446
EditorGUILayout.PropertyField(_restartOnEnable);
4547
EditorGUILayout.PropertyField(_wrapMode);
4648
EditorGUILayout.PropertyField(_updateMode);
49+
EditorGUILayout.PropertyField(_startMode);
4750
serializedObject.ApplyModifiedProperties();
4851
DrawPlayer(target as UIEffectTweener);
4952
Profiler.EndSample();

Packages/src/Runtime/UIEffectTweener.cs

+41-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public enum UpdateMode
2222
Manual
2323
}
2424

25+
public enum StartMode
26+
{
27+
Automatic,
28+
Manual
29+
}
30+
2531
public enum WrapMode
2632
{
2733
Once,
@@ -83,6 +89,13 @@ public enum Direction
8389
[SerializeField]
8490
private UpdateMode m_UpdateMode = UpdateMode.Normal;
8591

92+
[Tooltip("Specifies how the effect tweener will start.\n" +
93+
" Automatic: Plays the tween automatically when it starts.\n" +
94+
" Manual: Waits for the first `Play()` call to start.")]
95+
[SerializeField]
96+
private StartMode m_StartMode = StartMode.Automatic;
97+
98+
public bool _isAwaitingStart;
8699
private float _rate;
87100
private float _time;
88101
private UIEffectBase _target;
@@ -208,23 +221,32 @@ public UpdateMode updateMode
208221
set => m_UpdateMode = value;
209222
}
210223

224+
public StartMode startMode
225+
{
226+
get => m_StartMode;
227+
set => m_StartMode = value;
228+
}
229+
211230
public AnimationCurve curve
212231
{
213232
get => m_Curve;
214233
set => m_Curve = value;
215234
}
216235

236+
private void Awake()
237+
{
238+
_isAwaitingStart = m_StartMode == StartMode.Manual;
239+
}
240+
217241
private void Update()
218242
{
219-
switch (m_UpdateMode)
243+
if (m_StartMode == StartMode.Manual && _isAwaitingStart)
220244
{
221-
case UpdateMode.Normal:
222-
UpdateTime(Time.deltaTime);
223-
break;
224-
case UpdateMode.Unscaled:
225-
UpdateTime(Time.unscaledDeltaTime);
226-
break;
245+
return;
227246
}
247+
248+
float deltaTime = m_UpdateMode == UpdateMode.Unscaled ? Time.unscaledDeltaTime : Time.deltaTime;
249+
UpdateTime(deltaTime);
228250
}
229251

230252
private void OnEnable()
@@ -235,6 +257,18 @@ private void OnEnable()
235257
}
236258
}
237259

260+
public void Play()
261+
{
262+
_isAwaitingStart = false;
263+
Restart();
264+
}
265+
266+
public void Stop()
267+
{
268+
_isAwaitingStart = true;
269+
Restart();
270+
}
271+
238272
public void Restart()
239273
{
240274
SetTime(0);

0 commit comments

Comments
 (0)