protected IEnumerator waitForValidLocomotionModeToInteract() { if (locomotionTracker != null && locomotionTracker.GetCurrentController() is RunController) { Animator anim = GetComponent <Animator>(); RunController runController = (RunController)locomotionTracker.GetCurrentController(); RunController.ControllerBehaviour oldBehaviour = runController.Behaviour; runController.Behaviour = new RunController.ControllerBehaviour { IgnoreCollisions = false, IgnoreGravity = false, IgnoreRotation = false, IgnoreTranslation = false, IgnoreJumpRequests = true, IgnoreStickInput = true, LastModifier = this }; AnimatorStateInfo animStateInfo = LocomotionUtils.GetAnimatorStateInfo(anim); while (!LocomotionUtils.IsLocomoting(animStateInfo) && !LocomotionUtils.IsLanding(animStateInfo) && !LocomotionUtils.IsIdling(animStateInfo)) { yield return(null); animStateInfo = LocomotionUtils.GetAnimatorStateInfo(anim); } runController.ResetMomentum(); if (runController.Behaviour.LastModifier == this) { runController.Behaviour = oldBehaviour; } } }
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)); } }
private IEnumerator doMoveTo() { if (runController != null && runController.enabled) { Animator anim = actionTarget.GetComponent <Animator>(); Transform tempTransform = null; RunController.ControllerBehaviour oldRunBehaviour = runController.Behaviour; runController.Behaviour = new RunController.ControllerBehaviour { IgnoreCollisions = false, IgnoreGravity = false, IgnoreRotation = false, IgnoreTranslation = false, IgnoreJumpRequests = true, IgnoreStickInput = true, Style = Style }; bool runControllerBehaviourWasSet = true; AnimatorStateInfo animStateInfo = LocomotionUtils.GetAnimatorStateInfo(anim); while (!LocomotionUtils.IsLocomoting(animStateInfo) && !LocomotionUtils.IsLanding(animStateInfo) && !LocomotionUtils.IsIdling(animStateInfo)) { yield return(null); animStateInfo = LocomotionUtils.GetAnimatorStateInfo(anim); } runController.ResetMomentum(); if (IncomingUserData != null && IncomingUserData.GetType() == typeof(Vector3)) { Vector3 vector = (Vector3)IncomingUserData; Vector3 vector2 = vector - actionTarget.transform.position; vector2.y = 0f; if (vector2 == Vector3.zero) { vector2 = base.transform.forward; } tempTransform = new GameObject().transform; tempTransform.rotation = Quaternion.LookRotation(vector2); tempTransform.position = vector; Waypoints.Clear(); Waypoints.Add(tempTransform); } if (Waypoints.Count > 0) { float distThresholdSq = DistanceThreshold * DistanceThreshold; float prevDistSq = float.PositiveInfinity; float elapsedTime = 0f; bool done = false; int curWaypoint2 = 0; do { if (thisTransform.IsDestroyed() || actionTarget.IsDestroyed()) { Log.LogError(this, "Aborting LocomoteToAction as an object has been destroyed"); break; } if (UseShortestPath) { curWaypoint2 = FindFarthestReachableWaypoint(curWaypoint2); } Vector3 toTarget = Waypoints[curWaypoint2].position - thisTransform.position; toTarget.y = 0f; float distSq = toTarget.sqrMagnitude; if (distSq <= distThresholdSq || distSq > prevDistSq) { curWaypoint2++; if (curWaypoint2 >= Waypoints.Count) { done = true; } else { toTarget = Waypoints[curWaypoint2].position - thisTransform.position; toTarget.y = 0f; runController.Steer(toTarget.normalized); } } else { runController.Steer(toTarget.normalized); } elapsedTime += Time.deltaTime; if (elapsedTime > 5f) { done = true; } yield return(null); }while (!done); curWaypoint2 = Waypoints.Count - 1; runController.Steer(Vector3.zero); if (DontSnapYPosAtEnd) { Vector3 position = Waypoints[curWaypoint2].position; position.y = thisTransform.position.y; runController.SnapToPosition(position); } else { runController.SnapToPosition(Waypoints[curWaypoint2].position); } if (SnapRotAtEnd) { runController.SnapToFacing(Waypoints[curWaypoint2].forward); } } if (tempTransform != null) { Object.Destroy(tempTransform.gameObject); Waypoints.Clear(); } if (runControllerBehaviourWasSet) { runController.Behaviour = oldRunBehaviour; } } Completed(); }
private bool canSitFromCurrentState() { AnimatorStateInfo animatorStateInfo = LocomotionUtils.GetAnimatorStateInfo(animator); return(LocomotionUtils.IsIdling(animatorStateInfo) || LocomotionUtils.IsLocomoting(animatorStateInfo) || LocomotionUtils.IsInAir(animatorStateInfo) || LocomotionUtils.IsLanding(animatorStateInfo) || LocomotionUtils.IsSwimming(animatorStateInfo)); }