// ------------------------------------------------------------------
// Desc:
// ------------------------------------------------------------------
void Update()
{
if (playing && (curAnimation != null))
{
// advance the time and check if we trigger any animation events
float delta = Time.deltaTime * curAnimation.speed;
float curTime = curAnimation.time;
// advance the time
curAnimation.time += delta;
Step(curAnimation);
// save the last state
float lastAnimTime = curAnimation.time;
exSpriteAnimState lastAnimation = curAnimation;
//
int newIdx = curAnimation.clip.TriggerEvents(this,
lastAnimation,
lastEventInfoIndex,
curTime,
delta,
curAnimation.wrapMode);
// NOTE: it is possible in the events, user destroy this component. In this case,
// the curAnimation will be null.
if (curAnimation == null ||
curAnimation != lastAnimation ||
lastAnimTime != curAnimation.time /*NOTE: it is possible in the event we reply the same animation*/)
{
return;
}
lastEventInfoIndex = newIdx;
// set sprite to current time
exSpriteAnimClip.FrameInfo fi = GetCurFrameInfo();
if (fi != null)
{
sprite.SetSprite(fi.atlas, fi.index);
}
// check if stop
if (curAnimation.wrapMode == WrapMode.Once ||
curAnimation.wrapMode == WrapMode.Default)
{
if ((curAnimation.speed > 0.0f && curAnimation.time >= curAnimation.length) ||
(curAnimation.speed < 0.0f && curAnimation.time <= 0.0f))
{
Stop();
}
}
}
}