public void Mecanim_Update(float weight, float timeRatio, int playOrder, int playLayer, BLEND_METHOD blendMethod, float speed)
        {
            if (_linkedAnimClip == null)
            {
                //Debug.LogError("No AnimClip");
                return;
            }
            _unitWeight          = weight;
            _totalRequestWeights = 1.0f;

            _blendMethod = blendMethod;
            _playOrder   = playOrder;
            _layer       = playLayer;

            _isMecanimResetable = false;
            //_isMecanimLoopingFrame = false;

            //2.28 일단 이거 제외 [1.1.6]
            //1.1.4 / 1.1.5에서 메카님 음수 speed에 적용하려고 만든 것 같은데, 오작동을 일으킨다.
            //Debug.Log("Mecanim [" + timeRatio + " ( " + speed + " )]");
            //if((speed > 0.0f && timeRatio < _timeRatioPrev) ||
            //	(speed < 0.0f && timeRatio > _timeRatioPrev))
            //{
            //	//Debug.LogWarning("[" + _linkedAnimClip._name + "] 메카님 Speed와 TimeRatio 증감이 반대 : " + (timeRatio - _timeRatioPrev) + " / Speed : " + speed);
            //	//Debug.LogWarning("[" + _linkedAnimClip._name + "] 메카님 Speed와 TimeRatio 증감이 반대 : " + _timeRatioPrev + " >> " + timeRatio + " / Speed : " + speed);
            //	//Speed와 맞지 않은 증감폭이다.

            //	//이전
            //	//timeRatio = _timeRatioPrev - (timeRatio - _timeRatioPrev);<<이게 문제.. 근데 왜..
            //}
            //_timeRatioPrev = timeRatio;//<<1.1.6에서 삭제


            if (_linkedAnimClip.IsLoop)
            {
                //int curTimeRatioLoopCount = (int)timeRatio;
                //if(_mecanimTimeRatioLoopCount != curTimeRatioLoopCount)
                //{
                //	Debug.LogError("[Index Changed] _isMecanimLoopingFrame > True : " + timeRatio + " (" + _mecanimTimeRatioLoopCount + " >> " + curTimeRatioLoopCount + ")");
                //	//루프 카운트가 바뀌었다. > //이번 프레임에서 루프가 된다.
                //	_isMecanimLoopingFrame = true;
                //	_mecanimTimeRatioLoopCount = curTimeRatioLoopCount;
                //}
                //else
                //{
                //	if(
                //		(speed > 0.0f && timeRatio < 0.0f) ||
                //		(speed < 0.0f && timeRatio > 0.0f)
                //		)
                //	{
                //		Debug.LogError("[Speed And Time Inverted] _isMecanimLoopingFrame > True : " + timeRatio + " (Speed : " + speed + ")");
                //		//앞으로 진행하는데, timeRatio가 뒤로 가거나 또는 그 반대
                //		//Loop가 발생한 것이다.
                //		_isMecanimLoopingFrame = true;
                //	}
                //}

                if (timeRatio > 1.0f)
                {
                    timeRatio -= (int)timeRatio;
                }
                else if (timeRatio < 0.0f)
                {
                    timeRatio = (1.0f - Mathf.Abs(timeRatio) - (int)Mathf.Abs(timeRatio));
                }
            }
            else
            {
                if (timeRatio > 1.0f)
                {
                    //timeRatio = 2.0f;//이전
                    timeRatio = 1.0f;                    //변경
                }
                else if (timeRatio < 0.0f)
                {
                    //timeRatio = -1.0f;//이전
                    timeRatio = 0.0f;                    //변경
                }
                else
                {
                    //Time Ratio가 0~1의 값을 가지면 Reset이 가능하다.
                    _isMecanimResetable = true;
                }
            }

            _mecanimTime = timeRatio * _mecanimTimeLength;



            bool isResetFrame = false;

            if (!_linkedAnimClip.IsLoop && _isMecanimResetable)
            {
                if (speed > 0.0f)
                {
                    if (_mecanimTime < _mecanimTimePrev)
                    {
                        isResetFrame = true;
                        _linkedAnimClip.ResetEvents();
                        _linkedAnimClip.ResetFrame();
                    }
                }
                else if (speed < 0.0f)
                {
                    if (_mecanimTime > _mecanimTimePrev)
                    {
                        isResetFrame = true;
                        _linkedAnimClip.ResetEvents();
                        _linkedAnimClip.ResetFrame();
                    }
                }
            }
            //if(_isMecanimLoopingFrame)
            //{
            //	Debug.LogError(">> Reset Event");
            //	_linkedAnimClip.ResetEvents();
            //}

            //TODO : 여기서 tDelta로만 Forward/Backward를 결정하는게 아니라, 메카님의 Speed로 방향을 인식하도록 바꾸어야 한다.
            if (!isResetFrame)
            {
                _mecanimDeltaTime = _mecanimTime - _mecanimTimePrev;
                if (_mecanimTimeLength > 0.0f)
                {
                    if (_mecanimDeltaTime < 0.0f && speed > 0.0f)
                    {
                        //진행 방향과 시간이 반대라면
                        while (_mecanimDeltaTime < 0.0f)
                        {
                            _mecanimDeltaTime += _mecanimTimeLength;
                        }
                    }
                    else if (_mecanimDeltaTime > 0.0f && speed < 0.0f)
                    {
                        //진행 방향과 시간이 반대라면
                        while (_mecanimDeltaTime > 0.0f)
                        {
                            _mecanimDeltaTime -= _mecanimTimeLength;
                        }
                    }
                }

                //변경 1.17 : 일반 Update_Opt에서 UpdateMecanim_Opt로 변경한다.
                //_linkedAnimClip.UpdateMecanim_Opt(_mecanimTime - _mecanimTimePrev, speed);
            }
            else
            {
                _mecanimDeltaTime = _mecanimTime;
                //변경 1.17 : 일반 Update_Opt에서 UpdateMecanim_Opt로 변경한다.
                //_linkedAnimClip.UpdateMecanim_Opt(_mecanimTime, speed);
            }
            _linkedAnimClip.UpdateMecanim_Opt(_mecanimDeltaTime, speed);

            _mecanimTimePrev = _mecanimTime;
        }
Example #2
0
        public void Mecanim_Update(float weight, float timeRatio, int playOrder, int playLayer, BLEND_METHOD blendMethod, float speed)
        {
            if (_linkedAnimClip == null)
            {
                //Debug.LogError("No AnimClip");
                return;
            }
            _unitWeight          = weight;
            _totalRequestWeights = 1.0f;

            _blendMethod = blendMethod;
            _playOrder   = playOrder;
            _layer       = playLayer;

            _isMecanimResetable = false;

            if (_linkedAnimClip.IsLoop)
            {
                if (timeRatio > 1.0f)
                {
                    timeRatio -= (int)timeRatio;
                }
                else if (timeRatio < 0.0f)
                {
                    timeRatio = (1.0f - Mathf.Abs(timeRatio) - (int)Mathf.Abs(timeRatio));
                }
            }
            else
            {
                if (timeRatio > 1.0f)
                {
                    timeRatio = 2.0f;
                }
                else if (timeRatio < 0.0f)
                {
                    timeRatio = -1.0f;
                }
                else
                {
                    //Time Ratio가 0~1의 값을 가지면 Reset이 가능하다.
                    _isMecanimResetable = true;
                }
            }

            _mecanimTime = timeRatio * _mecanimTimeLength;


            bool isResetFrame = false;

            if (!_linkedAnimClip.IsLoop && _isMecanimResetable)
            {
                if (speed > 0.0f)
                {
                    if (_mecanimTime < _mecanimTimePrev)
                    {
                        isResetFrame = true;
                        _linkedAnimClip.ResetEvents();
                        _linkedAnimClip.ResetFrame();
                    }
                }
                else if (speed < 0.0f)
                {
                    if (_mecanimTime > _mecanimTimePrev)
                    {
                        isResetFrame = true;
                        _linkedAnimClip.ResetEvents();
                        _linkedAnimClip.ResetFrame();
                    }
                }
            }

            //Debug.Log("Mecanim_Update - " + timeRatio);
            //_linkedAnimClip.UpdateFrame_OptMecanim(_mecanimTime - _mecanimTimePrev, speed);
            if (!isResetFrame)
            {
                _linkedAnimClip.Update_Opt(_mecanimTime - _mecanimTimePrev);                //<<기존
            }
            else
            {
                //Debug.Log("Reset Frame : _mecanimTime : " + _mecanimTime);
                _linkedAnimClip.Update_Opt(_mecanimTime);
            }

            //_linkedAnimClip.Update_Opt(Time.deltaTime * speed);//<<테스트
            _mecanimTimePrev = _mecanimTime;
        }