1
1
using System ;
2
2
using UnityEngine ;
3
+ using UnityEngine . Serialization ;
3
4
4
5
namespace Coffee . UIEffects
5
6
{
@@ -23,12 +24,6 @@ public enum UpdateMode
23
24
Manual
24
25
}
25
26
26
- public enum StartMode
27
- {
28
- Automatic ,
29
- Manual
30
- }
31
-
32
27
public enum WrapMode
33
28
{
34
29
Once ,
@@ -43,6 +38,14 @@ public enum Direction
43
38
Reverse
44
39
}
45
40
41
+ public enum PlayOnEnable
42
+ {
43
+ None ,
44
+ Forward ,
45
+ Reverse ,
46
+ KeepDirection
47
+ }
48
+
46
49
[ Tooltip ( "The culling mask of the tween." ) ]
47
50
[ SerializeField ]
48
51
private CullingMask m_CullingMask = ( CullingMask ) ( - 1 ) ;
@@ -70,9 +73,10 @@ public enum Direction
70
73
[ Range ( 0f , 10 ) ]
71
74
private float m_Interval ;
72
75
73
- [ Tooltip ( "Whether to restart the tween when enabled." ) ]
76
+ [ FormerlySerializedAs ( "m_ResetTimeOnEnable" ) ]
77
+ [ Tooltip ( "Play the tween when the component is enabled." ) ]
74
78
[ SerializeField ]
75
- private bool m_RestartOnEnable = true ;
79
+ private PlayOnEnable m_PlayOnEnable = PlayOnEnable . Forward ;
76
80
77
81
[ Tooltip ( "The wrap mode of the tween.\n " +
78
82
" Clamp: Clamp the tween value (not loop).\n " +
@@ -89,13 +93,6 @@ public enum Direction
89
93
[ SerializeField ]
90
94
private UpdateMode m_UpdateMode = UpdateMode . Normal ;
91
95
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 ;
99
96
private bool _isPaused ;
100
97
private float _rate = - 1 ;
101
98
private float _time ;
@@ -197,10 +194,17 @@ public float totalTime
197
194
}
198
195
}
199
196
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" ) ]
200
204
public bool restartOnEnable
201
205
{
202
- get => m_RestartOnEnable ;
203
- set => m_RestartOnEnable = value ;
206
+ get => m_PlayOnEnable != PlayOnEnable . Forward ;
207
+ set => m_PlayOnEnable = value ? PlayOnEnable . None : PlayOnEnable . Forward ;
204
208
}
205
209
206
210
public WrapMode wrapMode
@@ -215,12 +219,6 @@ public UpdateMode updateMode
215
219
set => m_UpdateMode = value ;
216
220
}
217
221
218
- public StartMode startMode
219
- {
220
- get => m_StartMode ;
221
- set => m_StartMode = value ;
222
- }
223
-
224
222
public AnimationCurve curve
225
223
{
226
224
get => m_Curve ;
@@ -247,9 +245,22 @@ public bool isTweening
247
245
private void OnEnable ( )
248
246
{
249
247
_isPaused = true ;
250
- if ( playOnEnable )
248
+
249
+ #if UNITY_EDITOR
250
+ if ( ! Application . isPlaying ) return ;
251
+ #endif
252
+
253
+ switch ( playOnEnable )
251
254
{
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 ;
253
264
}
254
265
}
255
266
0 commit comments