Beispiel #1
0
        void TickEvents(AnimationInstanceParam _clip, float _timeElapsed, float _deltaTime, Action <string> _onEvents)
        {
            float lastFrame = _timeElapsed * _clip.m_FrameRate;
            float nextFrame = lastFrame + _deltaTime * _clip.m_FrameRate;

            float checkOffset = _clip.m_Loop ? _clip.m_FrameCount * Mathf.Floor((nextFrame / _clip.m_FrameCount)) : 0;

            foreach (AnimationInstanceEvent animEvent in _clip.m_Events)
            {
                float frameCheck = checkOffset + animEvent.m_EventFrame;
                if (lastFrame < frameCheck && frameCheck <= nextFrame)
                {
                    _onEvents(animEvent.m_EventIdentity);
                }
            }
        }
Beispiel #2
0
        public bool Tick(float _deltaTime, out int curFrame, out int nextFrame, out float framePassed, Action <string> _onEvents = null)
        {
            curFrame    = 0;
            nextFrame   = 0;
            framePassed = 0;
            if (m_AnimIndex < 0 || m_AnimIndex >= m_Animations.Length)
            {
                return(false);
            }

            AnimationInstanceParam param = m_Animations[m_AnimIndex];

            if (_onEvents != null)
            {
                TickEvents(param, m_TimeElapsed, _deltaTime, _onEvents);
            }
            m_TimeElapsed += _deltaTime;

            if (param.m_Loop)
            {
                framePassed = (m_TimeElapsed % param.m_Length) * param.m_FrameRate;
                curFrame    = Mathf.FloorToInt(framePassed) % param.m_FrameCount;
                nextFrame   = (curFrame + 1) % param.m_FrameCount;
            }
            else
            {
                framePassed = Mathf.Min(param.m_Length, m_TimeElapsed) * param.m_FrameRate;
                curFrame    = Mathf.Min(Mathf.FloorToInt(framePassed), param.m_FrameCount - 1);
                nextFrame   = Mathf.Min(curFrame + 1, param.m_FrameCount - 1);
            }

            curFrame    += param.m_FrameBegin;
            nextFrame   += param.m_FrameBegin;
            framePassed %= 1;
            return(true);
        }