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 TestRoutine() { startPos = base.transform.position; startRot = base.transform.rotation; RunController.ControllerBehaviour behaviourRun = controller.Behaviour; behaviourRun.Style = PlayerLocoStyle.Style.Run; RunController.ControllerBehaviour behaviourWalk = controller.Behaviour; behaviourWalk.Style = PlayerLocoStyle.Style.Walk; while (true) { controller.Behaviour.SetStyle(PlayerLocoStyle.Style.Run); controller.Steer(Vector2.up); yield return(new WaitForSeconds(RunTime)); controller.DoAction(LocomotionController.LocomotionAction.Jump); yield return(new WaitForSeconds(JumpTime)); controller.DoAction(LocomotionController.LocomotionAction.Jump); yield return(new WaitForSeconds(Jump2Time)); controller.Behaviour.SetStyle(PlayerLocoStyle.Style.Walk); yield return(new WaitForSeconds(WalkTime)); controller.DoAction(LocomotionController.LocomotionAction.Jump); yield return(new WaitForSeconds(Jump3Time)); controller.Steer(Vector2.zero); yield return(new WaitForSeconds(StopTime)); base.transform.position = startPos; base.transform.rotation = startRot; } }
protected override void Update() { if (!animFound) { Completed(); return; } bool flag = false; if (!animStarted) { AnimatorStateInfo animatorStateInfo = (anim.IsInTransition(LayerIndex) ? anim.GetNextAnimatorStateInfo(LayerIndex) : anim.GetCurrentAnimatorStateInfo(LayerIndex)); if (animatorStateInfo.fullPathHash == stateID) { animDuration = ((Duration == 0f) ? animatorStateInfo.length : Duration); animStarted = true; if (runController != null && getImplementsOnAnimatorMove()) { oldRunBehaviour = runController.Behaviour; runController.Behaviour = new RunController.ControllerBehaviour { IgnoreCollisions = true, IgnoreGravity = true, IgnoreRotation = true, IgnoreTranslation = true }; runControllerBehaviourWasSet = true; } startRot = thisTransform.rotation; startPos = thisTransform.position; } } if (animStarted) { elapsedTime += Time.deltaTime; if (isWarping) { if (AnimateTranslation) { thisTransform.position = Vector3.zero; } if (AnimateRotation) { thisTransform.rotation = Quaternion.identity; } } if (animDuration < 0f) { if ((anim.IsInTransition(LayerIndex) ? anim.GetNextAnimatorStateInfo(LayerIndex) : anim.GetCurrentAnimatorStateInfo(LayerIndex)).fullPathHash != stateID) { flag = true; } } else if (elapsedTime >= animDuration) { flag = true; } } if (flag) { if (runController != null && runControllerBehaviourWasSet) { runController.Behaviour = oldRunBehaviour; } if (isWarping) { thisTransform.position = lastValidPos; thisTransform.rotation = lastValidRot; } Completed(); } }
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(); }