示例#1
0
        private void Update()
        {
            curStateInfo = LocomotionUtils.GetAnimatorStateInfo(animator);
            isInAir      = LocomotionUtils.IsInAir(curStateInfo);
            isWalking    = LocomotionUtils.IsWalking(curStateInfo);
            isLanding    = LocomotionUtils.IsLanding(curStateInfo);
            isJogging    = LocomotionUtils.IsJogging(curStateInfo);
            isSprinting  = LocomotionUtils.IsSprinting(curStateInfo);
            isStopping   = LocomotionUtils.IsStopping(curStateInfo);
            isPivoting   = LocomotionUtils.IsPivoting(curStateInfo);
            curFacing    = base.transform.forward;
            curFacing.y  = 0f;
            curFacing.Normalize();
            animator.SetFloat(AnimationHashes.Params.GroundFriction, mutableData.GroundFriction);
            gravityVector.y = (0f - mutableData.Gravity) * Time.deltaTime;
            updateActionRequests();
            if (wsSteerDir != Vector3.zero)
            {
                if (Behaviour.Style == PlayerLocoStyle.Style.Walk)
                {
                    curLocoMode = LocoMode.Walk;
                }
                else if (mutableData.JogParams.ElapsedJogTime >= mutableData.SprintParams.MinTimeToStartSprinting)
                {
                    curLocoMode = LocoMode.Sprint;
                }
                else if (isWalking || (isLanding && curLocoMode == LocoMode.Walk))
                {
                    float num = mutableData.JogParams.MinSteerMag * mutableData.JogParams.MinSteerMag;
                    if (wsSteerDir.sqrMagnitude >= num && mutableData.WalkParams.ElapsedWalkTime >= mutableData.JogParams.MinTimeToStartJogging)
                    {
                        curLocoMode = LocoMode.Jog;
                    }
                    else
                    {
                        curLocoMode = LocoMode.Walk;
                    }
                }
                else if (isJogging || (isLanding && curLocoMode == LocoMode.Jog))
                {
                    float num = mutableData.JogParams.MinSteerMag - 0.1f;
                    num *= num;
                    if (wsSteerDir.sqrMagnitude < num)
                    {
                        curLocoMode = LocoMode.Walk;
                    }
                    else
                    {
                        curLocoMode = LocoMode.Jog;
                    }
                }
                else
                {
                    curLocoMode = LocoMode.Walk;
                }
                desiredFacing    = wsSteerDir;
                elapsedMoveTime += Time.deltaTime;
            }
            else
            {
                curLocoMode = LocoMode.Idle;
                if (elapsedMoveTime > 0f)
                {
                    snapToDesiredFacing = true;
                }
                else if (!snapToDesiredFacing)
                {
                    desiredFacing = curFacing;
                }
                elapsedMoveTime = 0f;
            }
            Debug.DrawRay(base.transform.position, curFacing, Color.blue, 0f, depthTest: false);
            Debug.DrawRay(base.transform.position, desiredFacing, Color.red, 0f, depthTest: false);
            float normalizedTime = curStateInfo.normalizedTime;

            animator.SetInteger(AnimationHashes.Params.LoopCount, Mathf.FloorToInt(normalizedTime));
            animator.SetFloat(AnimationHashes.Params.NormTime, normalizedTime - Mathf.Floor(normalizedTime));
            animator.SetInteger(AnimationHashes.Params.LocoMode, (int)curLocoMode);
            animator.SetBool(AnimationHashes.Params.Shuffle, snapToDesiredFacing);
            int fullPathHash = curStateInfo.fullPathHash;

            if (prevAnimState != fullPathHash)
            {
                onStateTransitioned();
            }
            if (isInAir)
            {
                updateInAirState();
            }
            else
            {
                updateOnGroundState();
            }
            mutableData.JogParams.speedMult = Mathf.Clamp(mutableData.JogParams.speedMult, 0f, 1f);
            animator.SetFloat(AnimationHashes.Params.JogSpeedMult, mutableData.JogParams.speedMult);
            mutableData.WalkParams.speedMult = Mathf.Clamp(mutableData.WalkParams.speedMult, 0f, 1f);
            animator.SetFloat(AnimationHashes.Params.WalkSpeedMult, mutableData.WalkParams.speedMult);
            mutableData.SprintParams.speedMult = Mathf.Clamp(mutableData.SprintParams.speedMult, 0f, 1f);
            animator.SetFloat(AnimationHashes.Params.SprintSpeedMult, mutableData.SprintParams.speedMult);
            prevAnimState = fullPathHash;
            prevStateInfo = curStateInfo;
        }