Skip to content

Commit 1558736

Browse files
committed
feat: add PlayOnEnable option for UIEffectTweener
1 parent 54825ee commit 1558736

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

Packages/src/Editor/UIEffectTweenerEditor.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,21 @@ internal class UIMaterialPropertyTweenerEditor : Editor
1414
private SerializedProperty _delay;
1515
private SerializedProperty _duration;
1616
private SerializedProperty _interval;
17-
private SerializedProperty _restartOnEnable;
17+
private SerializedProperty _playOnEnable;
1818
private SerializedProperty _updateMode;
1919
private SerializedProperty _wrapMode;
20-
private SerializedProperty _startMode;
2120

2221
private void OnEnable()
2322
{
2423
_cullingMask = serializedObject.FindProperty("m_CullingMask");
2524
_direction = serializedObject.FindProperty("m_Direction");
2625
_curve = serializedObject.FindProperty("m_Curve");
27-
_restartOnEnable = serializedObject.FindProperty("m_RestartOnEnable");
26+
_playOnEnable = serializedObject.FindProperty("m_PlayOnEnable");
2827
_delay = serializedObject.FindProperty("m_Delay");
2928
_duration = serializedObject.FindProperty("m_Duration");
3029
_interval = serializedObject.FindProperty("m_Interval");
3130
_wrapMode = serializedObject.FindProperty("m_WrapMode");
3231
_updateMode = serializedObject.FindProperty("m_UpdateMode");
33-
_startMode = serializedObject.FindProperty("m_StartMode");
3432
}
3533

3634
public override void OnInspectorGUI()
@@ -43,10 +41,9 @@ public override void OnInspectorGUI()
4341
EditorGUILayout.PropertyField(_delay);
4442
EditorGUILayout.PropertyField(_duration);
4543
EditorGUILayout.PropertyField(_interval);
46-
EditorGUILayout.PropertyField(_restartOnEnable);
44+
EditorGUILayout.PropertyField(_playOnEnable);
4745
EditorGUILayout.PropertyField(_wrapMode);
4846
EditorGUILayout.PropertyField(_updateMode);
49-
EditorGUILayout.PropertyField(_startMode);
5047
serializedObject.ApplyModifiedProperties();
5148
DrawPlayer(target as UIEffectTweener);
5249
Profiler.EndSample();

Packages/src/Runtime/UIEffectTweener.cs

+36-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using UnityEngine;
3+
using UnityEngine.Serialization;
34

45
namespace Coffee.UIEffects
56
{
@@ -23,12 +24,6 @@ public enum UpdateMode
2324
Manual
2425
}
2526

26-
public enum StartMode
27-
{
28-
Automatic,
29-
Manual
30-
}
31-
3227
public enum WrapMode
3328
{
3429
Once,
@@ -43,6 +38,14 @@ public enum Direction
4338
Reverse
4439
}
4540

41+
public enum PlayOnEnable
42+
{
43+
None,
44+
Forward,
45+
Reverse,
46+
KeepDirection
47+
}
48+
4649
[Tooltip("The culling mask of the tween.")]
4750
[SerializeField]
4851
private CullingMask m_CullingMask = (CullingMask)(-1);
@@ -70,9 +73,10 @@ public enum Direction
7073
[Range(0f, 10)]
7174
private float m_Interval;
7275

73-
[Tooltip("Whether to restart the tween when enabled.")]
76+
[FormerlySerializedAs("m_ResetTimeOnEnable")]
77+
[Tooltip("Play the tween when the component is enabled.")]
7478
[SerializeField]
75-
private bool m_RestartOnEnable = true;
79+
private PlayOnEnable m_PlayOnEnable = PlayOnEnable.Forward;
7680

7781
[Tooltip("The wrap mode of the tween.\n" +
7882
" Clamp: Clamp the tween value (not loop).\n" +
@@ -89,13 +93,6 @@ public enum Direction
8993
[SerializeField]
9094
private UpdateMode m_UpdateMode = UpdateMode.Normal;
9195

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;
9996
private bool _isPaused;
10097
private float _rate = -1;
10198
private float _time;
@@ -197,10 +194,17 @@ public float totalTime
197194
}
198195
}
199196

197+
public PlayOnEnable playOnEnable
198+
{
199+
get => m_PlayOnEnable;
200+
set => m_PlayOnEnable = value;
201+
}
202+
203+
[Obsolete("UIEffectTweener.restartOnEnable has been deprecated. Use UIEffectTweener.playOnEnable instead")]
200204
public bool restartOnEnable
201205
{
202-
get => m_RestartOnEnable;
203-
set => m_RestartOnEnable = value;
206+
get => m_PlayOnEnable != PlayOnEnable.Forward;
207+
set => m_PlayOnEnable = value ? PlayOnEnable.None : PlayOnEnable.Forward;
204208
}
205209

206210
public WrapMode wrapMode
@@ -215,12 +219,6 @@ public UpdateMode updateMode
215219
set => m_UpdateMode = value;
216220
}
217221

218-
public StartMode startMode
219-
{
220-
get => m_StartMode;
221-
set => m_StartMode = value;
222-
}
223-
224222
public AnimationCurve curve
225223
{
226224
get => m_Curve;
@@ -247,9 +245,22 @@ public bool isTweening
247245
private void OnEnable()
248246
{
249247
_isPaused = true;
250-
if (playOnEnable)
248+
249+
#if UNITY_EDITOR
250+
if (!Application.isPlaying) return;
251+
#endif
252+
253+
switch (playOnEnable)
251254
{
252-
Play();
255+
case PlayOnEnable.KeepDirection:
256+
Play();
257+
break;
258+
case PlayOnEnable.Forward:
259+
PlayForward();
260+
break;
261+
case PlayOnEnable.Reverse:
262+
PlayReverse();
263+
break;
253264
}
254265
}
255266

0 commit comments

Comments
 (0)