示例#1
0
        private bool getIdealDistanceToTarget(ref float distance, ref float height)
        {
            bool result = false;

            if (AlwaysUseDistOnIdle)
            {
                distance = DistanceOnIdle;
                height   = HeightOffset;
                result   = true;
            }
            else
            {
                setup();
                distance = originalDistance;
                height   = originalHeight;
                AnimatorStateInfo currentAnimatorStateInfo = anim.GetCurrentAnimatorStateInfo(AnimationHashes.Layers.Base);
                if (LocomotionUtils.IsIdling(currentAnimatorStateInfo) || LocomotionHelper.IsCurrentControllerOfType <SitController>(localPlayer))
                {
                    distance = DistanceOnIdle;
                    height   = HeightOffset;
                    result   = true;
                }
            }
            return(result);
        }
    private void Update()
    {
        AnimatorStateInfo animatorStateInfo = LocomotionUtils.GetAnimatorStateInfo(anim);

        curFacing   = base.transform.forward;
        curFacing.y = 0f;
        curFacing.Normalize();
        updateFX();
        bool flag = LocomotionUtils.IsIdling(animatorStateInfo);

        if (isInTorpedoState)
        {
            lerpSpin();
            if (!LocomotionUtils.IsTurboing(animatorStateInfo))
            {
                isInTorpedoState = false;
                wsLastSteerDir   = wsSteerDir;
                torpedoBubbles.Stop();
            }
        }
        else if (LocomotionUtils.IsTurboing(animatorStateInfo))
        {
            isInTorpedoState = true;
            curSpin          = 0f;
            if (!IsInShallowWater)
            {
                torpedoBubbles.Play();
            }
        }
        if (wsSteerDir != Vector3.zero)
        {
            speedMultAnimParam += mutableData.Accel * Time.deltaTime;
        }
        else if (flag)
        {
            speedMultAnimParam = mutableData.MinSpeedMult;
        }
        if (flag)
        {
            Momentum = Vector3.Lerp(Momentum, Vector3.zero, mutableData.DragSmoothing * Time.deltaTime);
            if ((double)Momentum.magnitude < 0.25)
            {
                Momentum = Vector3.zero;
            }
        }
        else
        {
            Momentum      = (base.transform.position - prevPos) / Time.deltaTime;
            desiredFacing = wsSteerDir;
        }
        speedMultAnimParam = Mathf.Clamp(speedMultAnimParam, mutableData.MinSpeedMult, 1f);
        anim.SetFloat(AnimationHashes.Params.SwimSpeedMult, speedMultAnimParam);
        anim.SetFloat(AnimationHashes.Params.SwimSpeed, wsSteerDir.magnitude);
        prevPos = base.transform.position;
    }
        private bool checkAnimatorState()
        {
            bool result = false;

            if (animator != null)
            {
                AnimatorStateInfo animatorStateInfo = LocomotionUtils.GetAnimatorStateInfo(animator);
                result = LocomotionUtils.IsIdling(animatorStateInfo);
            }
            return(result);
        }
    private void OnAnimatorMove()
    {
        AnimatorStateInfo animatorStateInfo = LocomotionUtils.GetAnimatorStateInfo(anim);

        if (wsSteerDir != Vector3.zero)
        {
            Quaternion identity = Quaternion.identity;
            if (LocomotionUtils.IsTurboing(animatorStateInfo))
            {
                identity = Quaternion.LookRotation(wsLastSteerDir, wsUpDir);
                identity = Quaternion.AngleAxis(curSpin, wsLastSteerDir) * identity;
            }
            else
            {
                identity = Quaternion.LookRotation(wsSteerDir);
            }
            Output.wsRotation = Quaternion.Slerp(base.transform.rotation, identity, mutableData.RotationSmoothing * Time.deltaTime);
        }
        else if (!IsInShallowWater)
        {
            Quaternion identity = Quaternion.LookRotation(-cameraTransform.forward, cameraTransform.up);
            Output.wsRotation = Quaternion.Slerp(base.transform.rotation, identity, mutableData.RotationSmoothing * Time.deltaTime);
        }
        else if (snapToDesiredFacing)
        {
            if (Vector3.Angle(curFacing, desiredFacing) < 1f)
            {
                snapToDesiredFacing = false;
            }
            TurnToDesiredFacing(mutableData.RotationSmoothing);
        }
        else
        {
            Output.wsRotation = base.transform.rotation;
        }
        if (LocomotionUtils.IsIdling(animatorStateInfo))
        {
            Output.wsDeltaPos = Momentum * Time.deltaTime;
        }
        else if (LocomotionUtils.IsTurboing(animatorStateInfo))
        {
            Output.wsDeltaPos = anim.deltaPosition;
        }
        else
        {
            Output.wsDeltaPos = anim.deltaPosition * stickMagnitude;
        }
    }
示例#5
0
        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();
        }
    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 bool canSitFromCurrentState()
    {
        AnimatorStateInfo animatorStateInfo = LocomotionUtils.GetAnimatorStateInfo(animator);

        return(LocomotionUtils.IsIdling(animatorStateInfo) || LocomotionUtils.IsLocomoting(animatorStateInfo) || LocomotionUtils.IsInAir(animatorStateInfo) || LocomotionUtils.IsLanding(animatorStateInfo) || LocomotionUtils.IsSwimming(animatorStateInfo));
    }