@@ -48,20 +48,35 @@ public bool flipY
48
48
}
49
49
}
50
50
51
- public bool playInEditor { get ; set ; }
51
+ private bool _playInEditor ;
52
+ public bool playInEditor { get => _playInEditor ; set => _playInEditor = value ; }
53
+
54
+ private float _clipTime ;
55
+ public float clipTime => _clipTime ;
56
+
57
+ private int _clipIndex = 0 ;
58
+ public int clipIndex => _clipIndex ;
52
59
53
- public float clipTime { get ; private set ; }
54
- public int clipIndex { get { return clipIdx ; } }
55
60
public SpriteAnimationClip3000 clip { get { return GetClipInternal ( clipIndex ) ; } }
56
61
public string clipName { get { return clip ? . name ; } }
57
62
public float clipLength { get { return clip ? . GetLength ( totalTimeScale ) ?? 0 ; } }
58
- public float normalizedTime { get { return clipTime / clipLength ; } }
63
+ public float normalizedTime
64
+ {
65
+ get
66
+ {
67
+ var l = clipLength ;
68
+ if ( l > 0 )
69
+ return _clipTime / clipLength ;
70
+ else
71
+ return 0f ;
72
+ }
73
+ }
59
74
#if UNITY_EDITOR
60
- public int editorIndex { get { return clipIdx ; } set { clipIdx = value ; } }
75
+ public int editorIndex { get { return _clipIndex ; } set { _clipIndex = value ; } }
61
76
#endif
62
- private int clipIdx = 0 ;
63
- private Action callback = null ;
64
- private bool isAnimated = false ;
77
+
78
+ private Action _callback = null ;
79
+ private bool _isAnimated = false ;
65
80
66
81
private static readonly SpriteAnimatorTimer3000 timer = new SpriteAnimatorTimer3000 ( ) ;
67
82
@@ -83,7 +98,7 @@ protected virtual void OnDestroy()
83
98
84
99
private void Update ( )
85
100
{
86
- isAnimated = true ;
101
+ _isAnimated = true ;
87
102
88
103
var dt = timer . GetDeltaTime ( m_timeThread ) ;
89
104
Animation ( clip , dt ) ;
@@ -98,14 +113,14 @@ private void Animation(SpriteAnimationClip3000 clip, float deltaTime)
98
113
Sprite sprite = SampleByNormalizedTime ( clip , normalizedTime ) ;
99
114
ChangeSprite ( sprite ) ;
100
115
101
- clipTime += dt ;
102
- if ( clipTime >= clipLength )
116
+ _clipTime += dt ;
117
+ if ( _clipTime >= clipLength )
103
118
{
104
- clipTime = 0 ;
105
- if ( callback != null )
119
+ _clipTime = 0 ;
120
+ if ( _callback != null )
106
121
{
107
- callback ( ) ;
108
- callback = null ;
122
+ _callback ( ) ;
123
+ _callback = null ;
109
124
}
110
125
}
111
126
}
@@ -166,18 +181,12 @@ private void ChangeFlip(bool flipX, bool flipY)
166
181
167
182
private bool ChangeClipIndex ( string clipName )
168
183
{
169
- if ( callback != null )
170
- {
171
- //do nothing
172
- callback = null ;
173
- }
174
-
175
184
int idx = GetClipIndex ( clipName ) ;
176
185
if ( idx == - 1 )
177
186
return false ;
178
187
179
- clipIdx = idx ;
180
- clipTime = 0 ;
188
+ _clipIndex = idx ;
189
+ _clipTime = 0 ;
181
190
return true ;
182
191
}
183
192
@@ -219,10 +228,10 @@ private bool PlayInternal(string clipName, bool immediately, Action callback = n
219
228
if ( ! res )
220
229
return false ;
221
230
222
- if ( ! isAnimated )
231
+ if ( ! _isAnimated )
223
232
Animation ( clip , 0 ) ;
224
233
225
- this . callback = callback ;
234
+ this . _callback = callback ;
226
235
return true ;
227
236
}
228
237
@@ -293,9 +302,22 @@ public void EditorUpdate()
293
302
294
303
if ( playInEditor )
295
304
{
296
- float deltaTime = Time . realtimeSinceStartup - lastRealtimeSinceStartup ;
297
- Animation ( clip , deltaTime ) ;
298
- lastRealtimeSinceStartup = Time . realtimeSinceStartup ;
305
+ if ( UnityEditor . EditorSettings . spritePackerMode != UnityEditor . SpritePackerMode . Disabled )
306
+ {
307
+ float deltaTime = Time . realtimeSinceStartup - lastRealtimeSinceStartup ;
308
+ Animation ( clip , deltaTime ) ;
309
+ lastRealtimeSinceStartup = Time . realtimeSinceStartup ;
310
+ }
311
+ else
312
+ {
313
+ playInEditor = false ;
314
+
315
+ const string url = "https://docs.unity3d.com/es/Manual/SpritePackerModes.html" ;
316
+ if ( UnityEditor . EditorUtility . DisplayDialog ( "Error" , $ "SpritePacker is disabled. Please go to the official documentation: { url } ", "Go to Documentation" , "I've got it!" ) )
317
+ {
318
+ Application . OpenURL ( url ) ;
319
+ }
320
+ }
299
321
}
300
322
}
301
323
0 commit comments