/// <summary> /// Plays the specified animation only if it /// is not already playing. /// </summary> /// <param name="anim">Reference to the animation to play.</param> public void DoAnim(UVAnimation_Multi anim) { if (curAnim != anim || !animating) { PlayAnim(anim); } }
/// <summary> /// Like PlayAnim, but plays the animation in reverse. /// See <see cref="PlayAnim"/>. /// </summary> /// <param name="anim">Reference to the animation to play in reverse.</param> public void PlayAnimInReverse(UVAnimation_Multi anim) { #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9 if (deleted || !gameObject.activeInHierarchy) #else if (deleted || !gameObject.active) #endif { return; } if (!m_started) { Start(); } curAnim = anim; curAnim.Reset(); curAnim.PlayInReverse(); // Ensure the framerate is not 0 so we don't // divide by zero: if (anim.framerate != 0.0f) { timeBetweenAnimFrames = 1f / anim.framerate; } else { timeBetweenAnimFrames = 1f; // Just some dummy value since it won't be used } timeSinceLastFrame = timeBetweenAnimFrames; // Only add to the animated list if // the animation has more than 1 frame: if ((anim.GetFrameCount() > 1 || anim.onAnimEnd != UVAnimation.ANIM_END_ACTION.Do_Nothing) && anim.framerate != 0.0f) { StepAnim(0); // Start coroutine if (!animating) { //animating = true; AddToAnimatedList(); //StartCoroutine(AnimationPump()); } } else { // Make sure we are no longer in the animation pump: PauseAnim(); // Since this is a single-frame anim, // call our delegate before setting // the frame so that our behavior is // consistent with multi-frame anims: if (animCompleteDelegate != null) { animCompleteDelegate(this); } StepAnim(0); } }
// Resets all sprite values to defaults for reuse: public override void Clear() { base.Clear(); if (curAnim != null) { PauseAnim(); curAnim = null; } }
//----------------------------------------------------------------- // Animation-related routines: //----------------------------------------------------------------- /// <summary> /// Adds an animation to the sprite for its use. /// </summary> /// <param name="anim">The animation to add</param> public void AddAnimation(UVAnimation_Multi anim) { UVAnimation_Multi[] temp; temp = animations; animations = new UVAnimation_Multi[temp.Length + 1]; temp.CopyTo(animations, 0); anim.index = animations.Length - 1; animations[anim.index] = anim; }
//----------------------------------------------------------------- // Animation-related routines: //----------------------------------------------------------------- /// <summary> /// Adds an animation to the sprite for its use. /// </summary> /// <param name="anim">The animation to add</param> public void AddAnimation(UVAnimation_Multi anim) { UVAnimation_Multi[] temp; temp = animations; animations = new UVAnimation_Multi[temp.Length + 1]; temp.CopyTo(animations, 0); anim.index = animations.Length - 1; animations[anim.index] = anim; }
/* * // Steps to the next frame of sprite animation * public override bool StepAnim() * { * if (curAnim == null) * return false; * * if (!curAnim.GetNextFrame(ref uvRect)) * { * // We reached the end of our animation * * // See if we should revert to a static appearance, * // default anim, or do nothing: * if (curAnim.onAnimEnd == UVAnimation.ANIM_END_ACTION.Do_Nothing) * { * PauseAnim(); * * // Update mesh UVs: * SetBleedCompensation(); * * // Resize if selected: * if (autoResize || pixelPerfect) * CalcSize(); * } * else if (curAnim.onAnimEnd == UVAnimation.ANIM_END_ACTION.Revert_To_Static) * RevertToStatic(); * else if (curAnim.onAnimEnd == UVAnimation.ANIM_END_ACTION.Play_Default_Anim) * { * // Notify the delegate: * if (animCompleteDelegate != null) * animCompleteDelegate(); * * // Play the default animation: * PlayAnim(defaultAnim); * * return false; * } * * // Notify the delegate: * if (animCompleteDelegate != null) * animCompleteDelegate(); * * // Check to see if we are still animating * // before setting the curAnim to null. * // Animating should be turned off if * // PauseAnim() was called above, or if we * // reverted to static. But it could have * // been turned on again by the * // animCompleteDelegate. * if (!animating) * curAnim = null; * * return false; * } * * // Update mesh UVs: * SetBleedCompensation(); * * UpdateUVs(); * * // Resize if selected: * if (autoResize || pixelPerfect) * CalcSize(); * * return true; * }*/ /// <summary> /// Starts playing the specified animation /// Note: this doesn't resume from a pause, /// it completely restarts the animation. To /// unpause, use <see cref="UnpauseAnim"/>. /// </summary> /// <param name="anim">A reference to the animation to play.</param> public void PlayAnim(UVAnimation_Multi anim) { if (deleted || !gameObject.active) { return; } curAnim = anim; curAnimIndex = curAnim.index; curAnim.Reset(); // Ensure the framerate is not 0 so we don't // divide by zero: if (anim.framerate != 0.0f) { timeBetweenAnimFrames = 1f / anim.framerate; } else { timeBetweenAnimFrames = 1f; // Just some dummy value since it won't be used } timeSinceLastFrame = timeBetweenAnimFrames; // Only add to the animated list if // the animation has more than 1 frame // or the framerate is non-zero: if ((anim.GetFrameCount() > 1 || anim.onAnimEnd != UVAnimation.ANIM_END_ACTION.Do_Nothing) && anim.framerate != 0.0f) { StepAnim(0); // Start coroutine if (!animating) { //animating = true; AddToAnimatedList(); //StartCoroutine(AnimationPump()); } } else { // Since this is a single-frame anim, // call our delegate before setting // the frame so that our behavior is // consistent with multi-frame anims: if (animCompleteDelegate != null) { animCompleteDelegate(this); } StepAnim(0); } }
public UVAnimation_Multi(UVAnimation_Multi anim) { this.name = anim.name; this.loopCycles = anim.loopCycles; this.loopReverse = anim.loopReverse; this.framerate = anim.framerate; this.onAnimEnd = anim.onAnimEnd; this.curClip = anim.curClip; this.stepDir = anim.stepDir; this.numLoops = anim.numLoops; this.duration = anim.duration; this.clips = new UVAnimation_Auto[anim.clips.Length]; for (int i = 0; i < this.clips.Length; i++) { this.clips[i] = anim.clips[i].Clone(); } this.CalcDuration(); }
/// <summary> /// Like PlayAnim, but plays the animation in reverse. /// See <see cref="PlayAnim"/>. /// </summary> /// <param name="anim">Reference to the animation to play in reverse.</param> public void PlayAnimInReverse(UVAnimation_Multi anim) { curAnim = anim; curAnim.Reset(); curAnim.PlayInReverse(); // Ensure the framerate is not 0 so we don't // divide by zero: anim.framerate = Mathf.Max(0.0001f, anim.framerate); timeBetweenAnimFrames = 1f / anim.framerate; timeSinceLastFrame = timeBetweenAnimFrames; // Only add to the animated list if // the animation has more than 1 frame: if (anim.GetFrameCount() > 1) { StepAnim(0); // Start coroutine if (!animating) { //animating = true; AddToAnimatedList(); //StartCoroutine(AnimationPump()); } } else { // Since this is a single-frame anim, // call our delegate before setting // the frame so that our behavior is // consistent with multi-frame anims: if (animCompleteDelegate != null) { animCompleteDelegate(this); } StepAnim(0); } }
/* // Steps to the next frame of sprite animation public bool StepAnim(float time) { if (curAnim == null) return false; timeSinceLastFrame += time; framesToAdvance = (int)(timeSinceLastFrame / timeBetweenAnimFrames); // If there's nothing to do, return: if (framesToAdvance < 1) return true; while (framesToAdvance > 0) { if (curAnim.GetNextFrame(ref lowerLeftUV)) --framesToAdvance; else { // We reached the end of our animation if (animCompleteDelegate != null) animCompleteDelegate(); // Update mesh UVs: UpdateUVs(); PauseAnim(); animating = false; return false; } } // Update mesh UVs: UpdateUVs(); timeSinceLastFrame = 0; return true; } */ // Steps to the next frame of sprite animation public override bool StepAnim(float time) { if (curAnim == null) return false; timeSinceLastFrame += Mathf.Max(0, time); //timeSinceLastFrame += time; framesToAdvance = (timeSinceLastFrame / timeBetweenAnimFrames); // If there's nothing to do, return: if (framesToAdvance < 1) { if (crossfadeFrames) SetColor(new Color(1f, 1f, 1f, (1f - framesToAdvance))); return true; } //timeSinceLastFrame -= timeBetweenAnimFrames * (float)framesToAdvance; while (framesToAdvance >= 1f) { if (curAnim.GetNextFrame(ref frameInfo)) { framesToAdvance -= 1f; timeSinceLastFrame -= timeBetweenAnimFrames; #if SPRITE_FRAME_DELEGATE // Notify the delegate: if(framesToAdvance >= 1f) if (animFrameDelegate != null) animFrameDelegate(this, curAnim.GetCurPosition()); #endif } else { // We reached the end of our animation if (crossfadeFrames) SetColor(Color.white); // See if we should revert to a static appearance, // default anim, or do nothing, etc: switch (curAnim.onAnimEnd) { case UVAnimation.ANIM_END_ACTION.Do_Nothing: PauseAnim(); // Update mesh UVs: uvRect = frameInfo.uvs; SetBleedCompensation(); // Resize if selected: if (autoResize || pixelPerfect) CalcSize(); break; case UVAnimation.ANIM_END_ACTION.Revert_To_Static: RevertToStatic(); curAnim = null; break; case UVAnimation.ANIM_END_ACTION.Play_Default_Anim: // Notify the delegates: #if SPRITE_FRAME_DELEGATE if (animFrameDelegate != null) animFrameDelegate(this, curAnim.GetCurPosition()); #endif if (animCompleteDelegate != null) animCompleteDelegate(this); // Play the default animation: PlayAnim(defaultAnim); return false; case UVAnimation.ANIM_END_ACTION.Hide: Hide(true); break; case UVAnimation.ANIM_END_ACTION.Deactivate: gameObject.active = false; break; case UVAnimation.ANIM_END_ACTION.Destroy: // Notify the delegates: #if SPRITE_FRAME_DELEGATE if (animFrameDelegate != null) animFrameDelegate(this, curAnim.GetCurPosition()); #endif if (animCompleteDelegate != null) animCompleteDelegate(this); Delete(); Destroy(gameObject); break; } // Notify the delegates: #if SM2_FRAME_DELEGATE if (animFrameDelegate != null) animFrameDelegate(this, curAnim.GetCurPosition()); #endif if (animCompleteDelegate != null) animCompleteDelegate(this); // Check to see if we are still animating // before setting the curAnim to null. // Animating should be turned off if // PauseAnim() was called above, or if we // reverted to static. But it could have // been turned on again by the // animCompleteDelegate. if (!animating) curAnim = null; return false; } } // Cross-fade to the next frame: if(crossfadeFrames) { UVAnimation curClip = curAnim.GetCurrentClip(); int curClipNum = curAnim.GetCurClipNum(); int curFrame = curClip.GetCurPosition(); int multiStepDir = curAnim.StepDirection; int clipStepDir = curClip.StepDirection; curAnim.GetNextFrame(ref nextFrameInfo); Vector2[] uvs2 = m_spriteMesh.uvs2; Rect nextUV = nextFrameInfo.uvs; uvs2[0].x = nextUV.xMin; uvs2[0].y = nextUV.yMax; uvs2[1].x = nextUV.xMin; uvs2[1].y = nextUV.yMin; uvs2[2].x = nextUV.xMax; uvs2[2].y = nextUV.yMin; uvs2[3].x = nextUV.xMax; uvs2[3].y = nextUV.yMax; // Undo our advance: curAnim.SetCurClipNum(curClipNum); curClip.SetCurrentFrame(curFrame); curAnim.StepDirection = multiStepDir; curClip.StepDirection = clipStepDir; SetColor(new Color(1f, 1f, 1f, (1f - framesToAdvance))); } #if SM2_FRAME_DELEGATE if (animFrameDelegate != null) animFrameDelegate(this, curAnim.GetCurPosition()); #endif // Update mesh UVs: uvRect = frameInfo.uvs; SetBleedCompensation(); // Resize if selected: if (autoResize || pixelPerfect) CalcSize(); //timeSinceLastFrame = 0; return true; }
/// <summary> /// Like PlayAnim, but plays the animation in reverse. /// See <see cref="PlayAnim"/>. /// </summary> /// <param name="anim">Reference to the animation to play in reverse.</param> public void PlayAnimInReverse(UVAnimation_Multi anim) { curAnim = anim; curAnim.Reset(); curAnim.PlayInReverse(); // Ensure the framerate is not 0 so we don't // divide by zero: anim.framerate = Mathf.Max(0.0001f, anim.framerate); timeBetweenAnimFrames = 1f / anim.framerate; timeSinceLastFrame = timeBetweenAnimFrames; // Only add to the animated list if // the animation has more than 1 frame: if (anim.GetFrameCount() > 1) { StepAnim(0); // Start coroutine if (!animating) { //animating = true; AddToAnimatedList(); //StartCoroutine(AnimationPump()); } } else { // Since this is a single-frame anim, // call our delegate before setting // the frame so that our behavior is // consistent with multi-frame anims: if (animCompleteDelegate != null) animCompleteDelegate(this); StepAnim(0); } }
/* * // Steps to the next frame of sprite animation * public bool StepAnim(float time) * { * if (curAnim == null) * return false; * * timeSinceLastFrame += time; * * framesToAdvance = (int)(timeSinceLastFrame / timeBetweenAnimFrames); * * // If there's nothing to do, return: * if (framesToAdvance < 1) * return true; * * while (framesToAdvance > 0) * { * if (curAnim.GetNextFrame(ref lowerLeftUV)) * --framesToAdvance; * else * { * // We reached the end of our animation * if (animCompleteDelegate != null) * animCompleteDelegate(); * * // Update mesh UVs: * UpdateUVs(); * PauseAnim(); * animating = false; * * return false; * } * } * * // Update mesh UVs: * UpdateUVs(); * * timeSinceLastFrame = 0; * * return true; * } */ // Steps to the next frame of sprite animation public override bool StepAnim(float time) { if (curAnim == null) { return(false); } timeSinceLastFrame += Mathf.Max(0, time); //timeSinceLastFrame += time; framesToAdvance = (int)(timeSinceLastFrame / timeBetweenAnimFrames); // If there's nothing to do, return: if (framesToAdvance < 1) { return(true); } //timeSinceLastFrame -= timeBetweenAnimFrames * (float)framesToAdvance; while (framesToAdvance > 0) { if (curAnim.GetNextFrame(ref frameInfo)) { --framesToAdvance; timeSinceLastFrame -= timeBetweenAnimFrames; #if SPRITE_FRAME_DELEGATE // Notify the delegate: if (framesToAdvance > 0) { if (animFrameDelegate != null) { animFrameDelegate(this, curAnim.GetCurPosition()); } } #endif } else { // We reached the end of our animation // See if we should revert to a static appearance, // default anim, or do nothing, etc: switch (curAnim.onAnimEnd) { case UVAnimation.ANIM_END_ACTION.Do_Nothing: PauseAnim(); // Update mesh UVs: uvRect = frameInfo.uvs; SetBleedCompensation(); // Resize if selected: if (autoResize || pixelPerfect) { CalcSize(); } break; case UVAnimation.ANIM_END_ACTION.Revert_To_Static: RevertToStatic(); curAnim = null; break; case UVAnimation.ANIM_END_ACTION.Play_Default_Anim: // Notify the delegates: #if SPRITE_FRAME_DELEGATE if (animFrameDelegate != null) { animFrameDelegate(this, curAnim.GetCurPosition()); } #endif if (animCompleteDelegate != null) { animCompleteDelegate(this); } // Play the default animation: PlayAnim(defaultAnim); return(false); case UVAnimation.ANIM_END_ACTION.Hide: Hide(true); break; case UVAnimation.ANIM_END_ACTION.Deactivate: gameObject.active = false; break; case UVAnimation.ANIM_END_ACTION.Destroy: // Notify the delegates: #if SPRITE_FRAME_DELEGATE if (animFrameDelegate != null) { animFrameDelegate(this, curAnim.GetCurPosition()); } #endif if (animCompleteDelegate != null) { animCompleteDelegate(this); } Delete(); Destroy(gameObject); break; } // Notify the delegates: #if SM2_FRAME_DELEGATE if (animFrameDelegate != null) { animFrameDelegate(this, curAnim.GetCurPosition()); } #endif if (animCompleteDelegate != null) { animCompleteDelegate(this); } // Check to see if we are still animating // before setting the curAnim to null. // Animating should be turned off if // PauseAnim() was called above, or if we // reverted to static. But it could have // been turned on again by the // animCompleteDelegate. if (!animating) { curAnim = null; } return(false); } } #if SM2_FRAME_DELEGATE if (animFrameDelegate != null) { animFrameDelegate(this, curAnim.GetCurPosition()); } #endif // Update mesh UVs: uvRect = frameInfo.uvs; SetBleedCompensation(); // Resize if selected: if (autoResize || pixelPerfect) { CalcSize(); } //timeSinceLastFrame = 0; return(true); }
/* // Steps to the next frame of sprite animation public bool StepAnim(float time) { if (curAnim == null) return false; timeSinceLastFrame += time; framesToAdvance = (int)(timeSinceLastFrame / timeBetweenAnimFrames); // If there's nothing to do, return: if (framesToAdvance < 1) return true; while (framesToAdvance > 0) { if (curAnim.GetNextFrame(ref lowerLeftUV)) --framesToAdvance; else { // We reached the end of our animation if (animCompleteDelegate != null) animCompleteDelegate(); // Update mesh UVs: UpdateUVs(); PauseAnim(); animating = false; return false; } } // Update mesh UVs: UpdateUVs(); timeSinceLastFrame = 0; return true; } */ // Steps to the next frame of sprite animation public override bool StepAnim(float time) { if (curAnim == null) return false; timeSinceLastFrame += Mathf.Max(0, time); //timeSinceLastFrame += time; framesToAdvance = (int)(timeSinceLastFrame / timeBetweenAnimFrames); // If there's nothing to do, return: if (framesToAdvance < 1) return true; //timeSinceLastFrame -= timeBetweenAnimFrames * (float)framesToAdvance; while (framesToAdvance > 0) { if (curAnim.GetNextFrame(ref frameInfo)) { --framesToAdvance; timeSinceLastFrame -= timeBetweenAnimFrames; #if SPRITE_FRAME_DELEGATE // Notify the delegate: if(framesToAdvance > 0) if (animFrameDelegate != null) animFrameDelegate(this, curAnim.GetCurPosition()); #endif } else { // We reached the end of our animation // See if we should revert to a static appearance, // default anim, or do nothing, etc: switch (curAnim.onAnimEnd) { case UVAnimation.ANIM_END_ACTION.Do_Nothing: PauseAnim(); // Update mesh UVs: uvRect = frameInfo.uvs; SetBleedCompensation(); // Resize if selected: if (autoResize || pixelPerfect) CalcSize(); break; case UVAnimation.ANIM_END_ACTION.Revert_To_Static: RevertToStatic(); curAnim = null; break; case UVAnimation.ANIM_END_ACTION.Play_Default_Anim: // Notify the delegates: #if SPRITE_FRAME_DELEGATE if (animFrameDelegate != null) animFrameDelegate(this, curAnim.GetCurPosition()); #endif if (animCompleteDelegate != null) animCompleteDelegate(this); // Play the default animation: PlayAnim(defaultAnim); return false; case UVAnimation.ANIM_END_ACTION.Hide: Hide(true); break; case UVAnimation.ANIM_END_ACTION.Deactivate: gameObject.active = false; break; case UVAnimation.ANIM_END_ACTION.Destroy: // Notify the delegates: #if SPRITE_FRAME_DELEGATE if (animFrameDelegate != null) animFrameDelegate(this, curAnim.GetCurPosition()); #endif if (animCompleteDelegate != null) animCompleteDelegate(this); Delete(); Destroy(gameObject); break; } // Notify the delegates: #if SM2_FRAME_DELEGATE if (animFrameDelegate != null) animFrameDelegate(this, curAnim.GetCurPosition()); #endif if (animCompleteDelegate != null) animCompleteDelegate(this); // Check to see if we are still animating // before setting the curAnim to null. // Animating should be turned off if // PauseAnim() was called above, or if we // reverted to static. But it could have // been turned on again by the // animCompleteDelegate. if (!animating) curAnim = null; return false; } } #if SM2_FRAME_DELEGATE if (animFrameDelegate != null) animFrameDelegate(this, curAnim.GetCurPosition()); #endif // Update mesh UVs: uvRect = frameInfo.uvs; SetBleedCompensation(); // Resize if selected: if (autoResize || pixelPerfect) CalcSize(); //timeSinceLastFrame = 0; return true; }
// Copy constructor: public UVAnimation_Multi(UVAnimation_Multi anim) { name = anim.name; loopCycles = anim.loopCycles; loopReverse = anim.loopReverse; framerate = anim.framerate; onAnimEnd = anim.onAnimEnd; curClip = anim.curClip; stepDir = anim.stepDir; numLoops = anim.numLoops; duration = anim.duration; clips = new UVAnimation_Auto[anim.clips.Length]; for (int i = 0; i < clips.Length; ++i) clips[i] = anim.clips[i].Clone(); CalcDuration(); }
// Resets all sprite values to defaults for reuse: public override void Clear() { base.Clear(); if (curAnim != null) { PauseAnim(); curAnim = null; } }
/// <summary> /// Plays the specified animation only if it /// is not already playing. /// </summary> /// <param name="anim">Reference to the animation to play.</param> public void DoAnim(UVAnimation_Multi anim) { if (curAnim != anim || !animating) PlayAnim(anim); }
/// <summary> /// Like PlayAnim, but plays the animation in reverse. /// See <see cref="PlayAnim"/>. /// </summary> /// <param name="anim">Reference to the animation to play in reverse.</param> public void PlayAnimInReverse(UVAnimation_Multi anim) { if (deleted || !gameObject.active) return; if (!m_started) Start(); curAnim = anim; curAnim.Reset(); curAnim.PlayInReverse(); // Ensure the framerate is not 0 so we don't // divide by zero: if (anim.framerate != 0.0f) { timeBetweenAnimFrames = 1f / anim.framerate; } else { timeBetweenAnimFrames = 1f; // Just some dummy value since it won't be used } timeSinceLastFrame = timeBetweenAnimFrames; // Only add to the animated list if // the animation has more than 1 frame: if ((anim.GetFrameCount() > 1 || anim.onAnimEnd != UVAnimation.ANIM_END_ACTION.Do_Nothing) && anim.framerate != 0.0f) { StepAnim(0); // Start coroutine if (!animating) { //animating = true; AddToAnimatedList(); //StartCoroutine(AnimationPump()); } } else { // Make sure we are no longer in the animation pump: PauseAnim(); // Since this is a single-frame anim, // call our delegate before setting // the frame so that our behavior is // consistent with multi-frame anims: if (animCompleteDelegate != null) animCompleteDelegate(this); StepAnim(0); } }
/* * // Steps to the next frame of sprite animation * public bool StepAnim(float time) * { * if (curAnim == null) * return false; * * timeSinceLastFrame += time; * * framesToAdvance = (int)(timeSinceLastFrame / timeBetweenAnimFrames); * * // If there's nothing to do, return: * if (framesToAdvance < 1) * return true; * * while (framesToAdvance > 0) * { * if (curAnim.GetNextFrame(ref lowerLeftUV)) * --framesToAdvance; * else * { * // We reached the end of our animation * if (animCompleteDelegate != null) * animCompleteDelegate(); * * // Update mesh UVs: * UpdateUVs(); * PauseAnim(); * animating = false; * * return false; * } * } * * // Update mesh UVs: * UpdateUVs(); * * timeSinceLastFrame = 0; * * return true; * } */ // Steps to the next frame of sprite animation public override bool StepAnim(float time) { if (curAnim == null) { return(false); } timeSinceLastFrame += Mathf.Max(0, time); //timeSinceLastFrame += time; framesToAdvance = (timeSinceLastFrame / timeBetweenAnimFrames); // If there's nothing to do, return: if (framesToAdvance < 1) { if (crossfadeFrames) { SetColor(new Color(1f, 1f, 1f, (1f - framesToAdvance))); } return(true); } //timeSinceLastFrame -= timeBetweenAnimFrames * (float)framesToAdvance; while (framesToAdvance >= 1f) { if (curAnim.GetNextFrame(ref frameInfo)) { #if SPRITE_FRAME_DELEGATE // Notify the delegate: if (framesToAdvance >= 1f) { if (animFrameDelegate != null) { animFrameDelegate(this, curAnim.GetCurPosition()); } } #endif framesToAdvance -= 1f; timeSinceLastFrame -= timeBetweenAnimFrames; } else { // We reached the end of our animation if (crossfadeFrames) { SetColor(Color.white); } // See if we should revert to a static appearance, // default anim, or do nothing, etc: switch (curAnim.onAnimEnd) { case UVAnimation.ANIM_END_ACTION.Do_Nothing: PauseAnim(); // Update mesh UVs: uvRect = frameInfo.uvs; SetBleedCompensation(); // Resize if selected: if (autoResize || pixelPerfect) { CalcSize(); } break; case UVAnimation.ANIM_END_ACTION.Revert_To_Static: RevertToStatic(); curAnim = null; break; case UVAnimation.ANIM_END_ACTION.Play_Default_Anim: // Notify the delegates: /* #if SPRITE_FRAME_DELEGATE * if (animFrameDelegate != null) * animFrameDelegate(this, curAnim.GetCurPosition()); #endif */ if (animCompleteDelegate != null) { animCompleteDelegate(this); } // Play the default animation: PlayAnim(defaultAnim); return(false); case UVAnimation.ANIM_END_ACTION.Hide: Hide(true); break; case UVAnimation.ANIM_END_ACTION.Deactivate: #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9 gameObject.SetActive(false); #else gameObject.active = false; #endif break; case UVAnimation.ANIM_END_ACTION.Destroy: // Notify the delegates: /* #if SPRITE_FRAME_DELEGATE * if (animFrameDelegate != null) * animFrameDelegate(this, curAnim.GetCurPosition()); #endif */ if (animCompleteDelegate != null) { animCompleteDelegate(this); } Delete(); Destroy(gameObject); break; } // Notify the delegates: /* #if SM2_FRAME_DELEGATE * if (animFrameDelegate != null) * animFrameDelegate(this, curAnim.GetCurPosition()); #endif */ if (animCompleteDelegate != null) { animCompleteDelegate(this); } // Check to see if we are still animating // before setting the curAnim to null. // Animating should be turned off if // PauseAnim() was called above, or if we // reverted to static. But it could have // been turned on again by the // animCompleteDelegate. if (!animating) { curAnim = null; } return(false); } } // Cross-fade to the next frame: if (crossfadeFrames) { UVAnimation curClip = curAnim.GetCurrentClip(); int curClipNum = curAnim.GetCurClipNum(); int curFrame = curClip.GetCurPosition(); int multiStepDir = curAnim.StepDirection; int clipStepDir = curClip.StepDirection; curAnim.GetNextFrame(ref nextFrameInfo); Vector2[] uvs2 = m_spriteMesh.uvs2; Rect nextUV = nextFrameInfo.uvs; uvs2[0].x = nextUV.xMin; uvs2[0].y = nextUV.yMax; uvs2[1].x = nextUV.xMin; uvs2[1].y = nextUV.yMin; uvs2[2].x = nextUV.xMax; uvs2[2].y = nextUV.yMin; uvs2[3].x = nextUV.xMax; uvs2[3].y = nextUV.yMax; // Undo our advance: curAnim.SetCurClipNum(curClipNum); curClip.SetCurrentFrame(curFrame); curAnim.StepDirection = multiStepDir; curClip.StepDirection = clipStepDir; SetColor(new Color(1f, 1f, 1f, (1f - framesToAdvance))); } /* #if SM2_FRAME_DELEGATE * if (animFrameDelegate != null) * animFrameDelegate(this, curAnim.GetCurPosition()); #endif */ // Update mesh UVs: uvRect = frameInfo.uvs; SetBleedCompensation(); // Resize if selected: if (autoResize || pixelPerfect) { CalcSize(); } //timeSinceLastFrame = 0; return(true); }
/* // Steps to the next frame of sprite animation public override bool StepAnim() { if (curAnim == null) return false; if (!curAnim.GetNextFrame(ref uvRect)) { // We reached the end of our animation // See if we should revert to a static appearance, // default anim, or do nothing: if (curAnim.onAnimEnd == UVAnimation.ANIM_END_ACTION.Do_Nothing) { PauseAnim(); // Update mesh UVs: SetBleedCompensation(); // Resize if selected: if (autoResize || pixelPerfect) CalcSize(); } else if (curAnim.onAnimEnd == UVAnimation.ANIM_END_ACTION.Revert_To_Static) RevertToStatic(); else if (curAnim.onAnimEnd == UVAnimation.ANIM_END_ACTION.Play_Default_Anim) { // Notify the delegate: if (animCompleteDelegate != null) animCompleteDelegate(); // Play the default animation: PlayAnim(defaultAnim); return false; } // Notify the delegate: if (animCompleteDelegate != null) animCompleteDelegate(); // Check to see if we are still animating // before setting the curAnim to null. // Animating should be turned off if // PauseAnim() was called above, or if we // reverted to static. But it could have // been turned on again by the // animCompleteDelegate. if (!animating) curAnim = null; return false; } // Update mesh UVs: SetBleedCompensation(); UpdateUVs(); // Resize if selected: if (autoResize || pixelPerfect) CalcSize(); return true; }*/ /// <summary> /// Starts playing the specified animation /// Note: this doesn't resume from a pause, /// it completely restarts the animation. To /// unpause, use <see cref="UnpauseAnim"/>. /// </summary> /// <param name="anim">A reference to the animation to play.</param> public void PlayAnim(UVAnimation_Multi anim) { #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9 if (deleted || !gameObject.activeInHierarchy) #else if (deleted || !gameObject.active) #endif return; if (!m_started) Start(); curAnim = anim; curAnimIndex = curAnim.index; curAnim.Reset(); // Ensure the framerate is not 0 so we don't // divide by zero: if (anim.framerate != 0.0f) { timeBetweenAnimFrames = 1f / anim.framerate; } else { timeBetweenAnimFrames = 1f; // Just some dummy value since it won't be used } timeSinceLastFrame = timeBetweenAnimFrames; // Only add to the animated list if // the animation has more than 1 frame // or the framerate is non-zero: if ((anim.GetFrameCount() > 1 || anim.onAnimEnd != UVAnimation.ANIM_END_ACTION.Do_Nothing) && anim.framerate != 0.0f) { StepAnim(0); // Start coroutine if (!animating) { //animating = true; AddToAnimatedList(); //StartCoroutine(AnimationPump()); } } else { // Make sure we are no longer in the animation pump: PauseAnim(); // Since this is a single-frame anim, // call our delegate before setting // the frame so that our behavior is // consistent with multi-frame anims: if (animCompleteDelegate != null) { // See if we need to delay calling // our delegate to be consistent // with our framerate: if (anim.framerate != 0) { Invoke("CallAnimCompleteDelegate", 1f / anim.framerate); } else animCompleteDelegate(this); } StepAnim(0); } }