コード例 #1
0
 private IEnumerator SampleSurface()
 {
     while (true)
     {
         if (base.isActiveAndEnabled)
         {
             Vector3           hitPoint          = Vector3.zero;
             int               num               = LocomotionUtils.SampleSurface(base.transform, SurfaceSamplingData, out hitPoint);
             AnimatorStateInfo animatorStateInfo = LocomotionUtils.GetAnimatorStateInfo(anim);
             if (LocomotionUtils.IsLocomoting(animatorStateInfo))
             {
                 if (LocomotionUtils.IsWalking(animatorStateInfo))
                 {
                     if (locoStatus != LocomotionStatus.Walking || num != prevSurfaceTypeIndex)
                     {
                         locoStatus = LocomotionStatus.Walking;
                         if (num >= 0)
                         {
                             if (!string.IsNullOrEmpty(SurfaceSamplingData.Effects[num].WalkSwitch.SwitchValue))
                             {
                                 EventManager.Instance.PostEvent(SurfaceSamplingData.Effects[num].WalkSwitch.EventName, EventAction.SetSwitch, SurfaceSamplingData.Effects[num].WalkSwitch.SwitchValue, base.gameObject);
                             }
                         }
                         else if (!string.IsNullOrEmpty(SurfaceSamplingData.DefaultWalkSwitch.EventName))
                         {
                             EventManager.Instance.PostEvent(SurfaceSamplingData.DefaultWalkSwitch.EventName, EventAction.SetSwitch, SurfaceSamplingData.DefaultWalkSwitch.SwitchValue, base.gameObject);
                         }
                     }
                 }
                 else if (locoStatus != LocomotionStatus.Jogging || num != prevSurfaceTypeIndex)
                 {
                     locoStatus = LocomotionStatus.Jogging;
                     if (num >= 0)
                     {
                         if (!string.IsNullOrEmpty(SurfaceSamplingData.Effects[num].JogSwitch.SwitchValue))
                         {
                             EventManager.Instance.PostEvent(SurfaceSamplingData.Effects[num].JogSwitch.EventName, EventAction.SetSwitch, SurfaceSamplingData.Effects[num].JogSwitch.SwitchValue, base.gameObject);
                         }
                     }
                     else if (!string.IsNullOrEmpty(SurfaceSamplingData.DefaultJogSwitch.EventName))
                     {
                         EventManager.Instance.PostEvent(SurfaceSamplingData.DefaultJogSwitch.EventName, EventAction.SetSwitch, SurfaceSamplingData.DefaultJogSwitch.SwitchValue, base.gameObject);
                     }
                 }
             }
             else if (LocomotionUtils.IsInAir(animatorStateInfo) || LocomotionUtils.IsLanding(animatorStateInfo))
             {
                 if (locoStatus != LocomotionStatus.InAir || num != prevSurfaceTypeIndex)
                 {
                     locoStatus = LocomotionStatus.InAir;
                     if (num >= 0)
                     {
                         if (!string.IsNullOrEmpty(SurfaceSamplingData.Effects[num].LandSwitch.SwitchValue))
                         {
                             EventManager.Instance.PostEvent(SurfaceSamplingData.Effects[num].LandSwitch.EventName, EventAction.SetSwitch, SurfaceSamplingData.Effects[num].LandSwitch.SwitchValue, base.gameObject);
                         }
                     }
                     else if (!string.IsNullOrEmpty(SurfaceSamplingData.DefaultLandSwitch.EventName))
                     {
                         EventManager.Instance.PostEvent(SurfaceSamplingData.DefaultLandSwitch.EventName, EventAction.SetSwitch, SurfaceSamplingData.DefaultLandSwitch.SwitchValue, base.gameObject);
                     }
                 }
             }
             else if (tracker.IsCurrentControllerOfType <SlideController>())
             {
                 if (locoStatus != LocomotionStatus.Tubing || num != prevSurfaceTypeIndex)
                 {
                     locoStatus = LocomotionStatus.Tubing;
                     if (num >= 0)
                     {
                         if (!string.IsNullOrEmpty(SurfaceSamplingData.Effects[num].TubeSlideLoopSwitch.SwitchValue))
                         {
                             EventManager.Instance.PostEvent(SurfaceSamplingData.Effects[num].TubeSlideLoopSwitch.EventName, EventAction.SetSwitch, SurfaceSamplingData.Effects[num].TubeSlideLoopSwitch.SwitchValue, base.gameObject);
                         }
                     }
                     else if (!string.IsNullOrEmpty(SurfaceSamplingData.DefaultTubeSlideLoopSwitch.EventName))
                     {
                         EventManager.Instance.PostEvent(SurfaceSamplingData.DefaultTubeSlideLoopSwitch.EventName, EventAction.SetSwitch, SurfaceSamplingData.DefaultTubeSlideLoopSwitch.SwitchValue, base.gameObject);
                     }
                 }
             }
             else
             {
                 locoStatus = LocomotionStatus.Unknown;
             }
             prevSurfaceTypeIndex = num;
         }
         yield return(new WaitForSeconds(sampleTime));
     }
 }
コード例 #2
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;
        }