GetNextFrame() 공개 메소드

public GetNextFrame ( Vector2 &uv ) : bool
uv Vector2
리턴 bool
예제 #1
0
    public override void Update()
    {
        ElapsedTime += Time.deltaTime;
        float num = (!(UVTime <= 0f)) ? (UVTime / (float)Frames.frames.Length) : (Node.GetLifeTime() / (float)Frames.frames.Length);

        if (ElapsedTime >= num)
        {
            Vector2 uv = Vector2.zero;
            Vector2 dm = Vector2.zero;
            Frames.GetNextFrame(ref uv, ref dm);
            Node.LowerLeftUV  = uv;
            Node.UVDimensions = dm;
            ElapsedTime      -= num;
        }
    }
예제 #2
0
파일: Sprite.cs 프로젝트: cuongdv/wushi2
 // Steps to the next frame of sprite animation
 // (not to be called directly, but is invoked):
 protected void StepAnim()
 {
     if (curAnim.GetNextFrame(ref m_lowerLeftUV))
     {
         m_manager.UpdateUV(this);
     }
     else
     {
         CancelInvoke("StepAnim");   // We reached the end of our animation
         if (animCompleteDelegate != null)
         {
             animCompleteDelegate();
         }
     }
 }
예제 #3
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);

        framesPlayed += framesToAdvance;

        // If there's nothing to do, return:
        if (framesToAdvance < 1)
        {
            return(true);
        }

        while (framesToAdvance > 0)
        {
            if (curAnim.GetNextFrame(ref m_lowerLeftUV))
            {
                --framesToAdvance;
            }
            else
            {
                // We reached the end of our animation
                if (animCompleteDelegate != null)
                {
                    animCompleteDelegate(curAnim.name);
                    framesPlayed = 0;
                }
                m_manager.UpdateUV(this);

                return(false);
            }
        }

        m_manager.UpdateUV(this);
        timeSinceLastFrame = 0;

        return(true);
    }
예제 #4
0
    public override void Update()
    {
        ElapsedTime += Time.deltaTime;
        float framerate;

        if (UVTime <= 0f)
        {
            framerate = Node.GetLifeTime() / Frames.frames.Length;
        }
        else
        {
            framerate = UVTime / Frames.frames.Length;
        }
        if (ElapsedTime >= framerate)
        {
            Vector2 uv = Vector2.zero;
            Vector2 dm = Vector2.zero;
            Frames.GetNextFrame(ref uv, ref dm);
            Node.LowerLeftUV  = uv;
            Node.UVDimensions = dm;
            ElapsedTime      -= framerate;
        }
    }
예제 #5
0
    public override void Update()
    {
        float num;

        ElapsedTime += Time.deltaTime;
        if (UVTime <= 0f)
        {
            num = Node.GetLifeTime() / Frames.frames.Length;
        }
        else
        {
            num = UVTime / Frames.frames.Length;
        }

        if (ElapsedTime >= num)
        {
            var zero = Vector2.zero;
            var dm   = Vector2.zero;
            Frames.GetNextFrame(ref zero, ref dm);
            Node.LowerLeftUV  = zero;
            Node.UVDimensions = dm;
            ElapsedTime      -= num;
        }
    }
예제 #6
0
    // 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();
                    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 SPRITE_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 SPRITE_FRAME_DELEGATE
        if (animFrameDelegate != null)
        {
            animFrameDelegate(this, curAnim.GetCurPosition());
        }
#endif

        // Update mesh UVs:
        uvRect = frameInfo.uvs;
        SetBleedCompensation();

        // Resize if selected:
        if (autoResize || pixelPerfect)
        {
            CalcSize();
        }
        else if (anchor == SpriteRoot.ANCHOR_METHOD.TEXTURE_OFFSET)
        {
            SetSize(width, height);
        }

        //timeSinceLastFrame = 0;

        return(true);
    }
예제 #7
0
    // 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();
                    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 SPRITE_FRAME_DELEGATE
                 *                              if (animFrameDelegate != null)
                 *                                      animFrameDelegate(this, curAnim.GetCurPosition());
                 #endif
                 */
                if (animCompleteDelegate != null && curAnim.onAnimEnd != UVAnimation.ANIM_END_ACTION.Destroy)
                {
                    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)
        {
            int curFrame = curAnim.GetCurPosition();
            int stepDir  = curAnim.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.SetCurrentFrame(curFrame);
            curAnim.StepDirection = stepDir;

            SetColor(new Color(1f, 1f, 1f, (1f - framesToAdvance)));
        }

        /*
         #if SPRITE_FRAME_DELEGATE
         *              if (animFrameDelegate != null)
         *                      animFrameDelegate(this, curAnim.GetCurPosition());
         #endif
         */
        // Update mesh UVs:
        uvRect = frameInfo.uvs;
        SetBleedCompensation();

        // Resize if selected:
        if (autoResize || pixelPerfect)
        {
            CalcSize();
        }
        else if (anchor == SpriteRoot.ANCHOR_METHOD.TEXTURE_OFFSET)
        {
            SetSize(width, height);
        }

        //timeSinceLastFrame = 0;

        return(true);
    }