protected virtual void OnEnable()
 {
     if (canSlideFromCurrentState())
     {
         animator.SetBool(AnimationHashes.Params.Slide, value: true);
         wasInAirAtStart    = LocomotionUtils.IsInAir(LocomotionUtils.GetAnimatorStateInfo(animator));
         IsSliding          = false;
         isFloatingOnWater  = false;
         isSupportedByWater = false;
         lastSplashTime     = -1f;
         impulses           = base.gameObject.AddComponent <ForceAccumulatorPrimitive>();
         impulses.SetData(mutableData.ImpulseProperties);
         impulses.enabled            = true;
         mutableData.WaterProperties = MasterData.WaterProperties;
         maxSpeedOnWaterWhenSteering = mutableData.WaterProperties.MaxSpeed;
         curSpeedOnWater             = motion.Velocity.magnitude;
         curSpeedOnWater             = Mathf.Clamp(curSpeedOnWater, 0f, maxSpeedOnWaterWhenSteering);
         momentumAtStart             = motion.Velocity;
         if (mutableData.WaterRipples != null)
         {
             waterRipples = Object.Instantiate(mutableData.WaterRipples);
             waterRipples.Stop();
             CameraCullingMaskHelper.SetLayerIncludingChildren(waterRipples.transform, LayerMask.LayerToName(base.gameObject.layer));
         }
         base.Broadcaster.OnInteractionPreStartedEvent += onInteractionPreStartedEvent;
     }
     else
     {
         base.enabled = false;
     }
 }
        private void updateResurfacing()
        {
            if (curState == State.PostResurfacing)
            {
                return;
            }
            AnimatorStateInfo animatorStateInfo = LocomotionUtils.GetAnimatorStateInfo(animator);

            if (TriggerSnapToSurface || (animatorStateInfo.normalizedTime > 0.9f && animatorStateInfo.tagHash == AnimationHashes.Tags.Resurfacing) || (animatorStateInfo.normalizedTime > 0.8f && animatorStateInfo.tagHash == AnimationHashes.Tags.QuickResurfacing))
            {
                mainCamera.Snap();
                if (curState == State.QuickResurfacing)
                {
                    base.transform.position = mutableData.QuickResurfacingTransform.position;
                }
                else
                {
                    base.transform.position = mutableData.ResurfaceTransform.position;
                }
                curState = State.PostResurfacing;
                animator.SetBool(AnimationHashes.Params.Resurface, value: false);
                animator.SetBool(AnimationHashes.Params.QuickResurface, value: false);
                desiredAnimIndex = defaultSwimAnimIndex;
                animator.SetFloat(AnimationHashes.Params.LowAirAnimChooser, desiredAnimIndex);
                TriggerSnapToSurface    = false;
                base.transform.rotation = Quaternion.LookRotation(-cameraTransform.forward, cameraTransform.up);
                swim.ResetState();
                impulses.ResetState();
            }
        }
 private void OnControllerColliderHit(ControllerColliderHit hit)
 {
     if (!isInShallowWater && LocomotionUtils.IsTurboing(animator.GetCurrentAnimatorStateInfo(0)))
     {
         animator.SetTrigger(AnimationHashes.Params.AbortTorpedo);
     }
 }
Beispiel #4
0
        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;
                }
            }
        }
 public override void Steer(Vector2 steerInput)
 {
     if (mode == Mode.PhysicsDriven)
     {
         steerVel  = LocomotionUtils.StickInputToWorldSpaceTransform(steerInput, LocomotionUtils.AxisIndex.Z);
         steerVel *= (isFloatingOnWater ? mutableData.ImpulseScaleOnWater : mutableData.ImpulseScale);
         base.Broadcaster.BroadcastOnStickDirectionEvent(steerInput);
         base.Broadcaster.BroadcastOnSteerDirectionEvent(steerVel);
     }
 }
Beispiel #6
0
 public override void SteerRotation(Vector2 steerInput)
 {
     if (!Behaviour.IgnoreStickInput)
     {
         Vector3 wsSteerInput = LocomotionUtils.StickInputToWorldSpaceTransform(steerInput, LocomotionUtils.AxisIndex.Z);
         if (snapToDesiredFacing || (int)Vector3.Angle(desiredFacing, wsSteerInput) > mutableData.IdleParams.RotationDegreesOffsetThreshold)
         {
             applySteerRotation(ref wsSteerInput);
         }
     }
 }
Beispiel #7
0
 public override void Steer(Vector2 steerInput)
 {
     if (!Behaviour.IgnoreStickInput)
     {
         float magnitude = steerInput.magnitude;
         wsSteerDir = LocomotionUtils.StickInputToWorldSpaceTransform(steerInput, LocomotionUtils.AxisIndex.Z);
         wsSteerDir = Vector3.ClampMagnitude(wsSteerDir, magnitude);
         base.Broadcaster.BroadcastOnStickDirectionEvent(steerInput);
         base.Broadcaster.BroadcastOnSteerDirectionEvent(wsSteerDir);
     }
 }
        private void Update()
        {
            switch (curState)
            {
            case State.Resurfacing:
            case State.QuickResurfacing:
            case State.PostResurfacing:
                updateResurfacing();
                break;

            case State.ExitingWater:
                animator.SetTrigger(AnimationHashes.Params.SwimToWalk);
                base.transform.rotation = Quaternion.LookRotation(new Vector3(base.transform.forward.x, 0f, base.transform.forward.z), Vector3.up);
                LocomotionHelper.SetCurrentController <RunController>(base.gameObject);
                break;

            case State.Interacting:
                if (SceneRefs.ActionSequencer.GetTrigger(base.gameObject) == null)
                {
                    curState = State.None;
                    swim.ResetState();
                }
                break;

            case State.ReactingToHit:
                if (!LocomotionUtils.IsReactingToHit(LocomotionUtils.GetAnimatorStateInfo(animator)))
                {
                    curState = State.None;
                    swim.ResetState();
                }
                break;

            default:
                if (LocomotionUtils.IsReactingToHit(LocomotionUtils.GetAnimatorStateInfo(animator)))
                {
                    curState = State.ReactingToHit;
                }
                if (isWaterTooShallow(mutableData.MaxShallowWaterDepth))
                {
                    curState = State.ExitingWater;
                }
                updateFX();
                break;
            }
            if (TriggerResurface)
            {
                onTriggerResurface();
            }
            if (TriggerQuickResurface)
            {
                pauseHealth();
                TriggerQuickResurface = false;
            }
        }
        protected override void OnEnable()
        {
            AnimatorStateInfo    animatorStateInfo = LocomotionUtils.GetAnimatorStateInfo(animator);
            LocomotionController currentController = GetComponent <LocomotionTracker>().GetCurrentController();

            if (currentController is SlideController)
            {
                base.Sled          = ((SlideController)currentController).Sled;
                base.SledTransform = ((SlideController)currentController).SledTransform;
                base.Pilot         = ((SlideController)currentController).Pilot;
                if (base.Sled == null || base.SledTransform == null || base.Pilot == null || LocomotionUtils.IsInAir(animatorStateInfo) || LocomotionUtils.IsLanding(animatorStateInfo) || ((SlideController)currentController).CurrentMode == Mode.Animated)
                {
                    base.enabled = false;
                    return;
                }
                ((SlideController)currentController).ToRaceController = true;
                FromSlideController = true;
            }
            else if (!LocomotionUtils.IsIdling(animatorStateInfo) && !LocomotionUtils.IsLocomoting(animatorStateInfo))
            {
                base.enabled = false;
                return;
            }
            base.OnEnable();
            if (myMutableData.SpeedLinesTubeRacePrefab != null)
            {
                speedLines = Object.Instantiate(myMutableData.SpeedLinesTubeRacePrefab);
                CameraCullingMaskHelper.SetLayerIncludingChildren(speedLines.transform, LayerMask.LayerToName(base.gameObject.layer));
                Vector3    localPosition = new Vector3(speedLines.transform.position.x, speedLines.transform.position.y, speedLines.transform.position.z);
                Quaternion localRotation = new Quaternion(speedLines.transform.rotation.x, speedLines.transform.rotation.y, speedLines.transform.rotation.z, speedLines.transform.rotation.w);
                speedLines.transform.parent        = base.transform;
                speedLines.transform.localPosition = localPosition;
                speedLines.transform.localRotation = localRotation;
                speedLines.SetActive(value: false);
            }
            if (visualizeTrackSegment)
            {
                steeringObject         = new GameObject();
                steeringObjectRenderer = steeringObject.AddComponent <LineRenderer>();
                steeringObjectRenderer.transform.parent = base.gameObject.transform;
                steeringObjectRenderer.useWorldSpace    = true;
                trackDirObject   = new GameObject();
                trackDirRenderer = trackDirObject.AddComponent <LineRenderer>();
                trackDirObject.transform.parent = base.gameObject.transform;
                trackDirRenderer.useWorldSpace  = true;
            }
            if (FromSlideController)
            {
                mode           = Mode.Animated;
                base.IsSliding = true;
            }
            steerVel = Vector3.zero;
        }
        public void SurfaceFX(string alias)
        {
            if (!base.enabled)
            {
                return;
            }
            Vector3 hitPoint;
            int     num = LocomotionUtils.SampleSurface(base.transform, MasterData, out hitPoint);

            if (num < 0)
            {
                return;
            }
            if (prevEffect != null)
            {
                prevEffect.Stop();
                if (system[prevSurfaceTypeIndex] != null)
                {
                    system[prevSurfaceTypeIndex].Unspawn(prevEffect.gameObject);
                }
            }
            Vector3 position = Vector3.zero;
            bool    flag     = false;

            if (emitterPoints.TryGetValue(alias, out var value))
            {
                position = value.position;
                flag     = true;
            }
            if (flag)
            {
                if (MasterData.Effects[num].UseCollisionHeight)
                {
                    position.y = hitPoint.y;
                }
                if (system[num] != null)
                {
                    ParticleSystem component = system[num].Spawn().GetComponent <ParticleSystem>();
                    component.transform.position = position;
                    component.Play();
                    prevEffect           = component;
                    prevSurfaceTypeIndex = num;
                }
            }
        }
        public void OnCollisionEnter(Collision collision)
        {
            if (!base.enabled)
            {
                return;
            }
            if (collision.gameObject.layer == waterLayer)
            {
                if (collision.contacts.Length > 0 && mutableData.WaterSplash != null && pilotBody != null && Time.time - lastSplashTime >= mutableData.SplashCooldown)
                {
                    GameObject gameObject = Object.Instantiate(mutableData.WaterSplash);
                    if (gameObject != null)
                    {
                        Vector3 position = pilotBody.transform.position;
                        position.y = collision.contacts[0].point.y + mutableData.SplashOffset;
                        gameObject.transform.position = position;
                        CameraCullingMaskHelper.SetLayerIncludingChildren(gameObject.transform, LayerMask.LayerToName(base.gameObject.layer));
                    }
                    lastSplashTime = Time.time;
                }
                transitionToWater();
            }
            if (LocomotionUtils.GetAnimatorStateInfo(animator).tagHash == AnimationHashes.Tags.ReactingToHit || !(collision.impulse.sqrMagnitude >= minMagnitudeForBumpSq) || !(Mathf.Abs(collision.impulse.y) < 0.707f))
            {
                return;
            }
            Vector3 vector = thisTransform.position - collision.contacts[0].point;

            vector.y = 0f;
            if (vector.x != 0f && vector.z != 0f)
            {
                Vector3 forward = thisTransform.forward;
                forward.y = 0f;
                if (forward.x != 0f && forward.z != 0f)
                {
                    float num = LocomotionUtils.SignedAngle(forward.normalized, vector.normalized);
                    num = ((num < -157.5f) ? 180f : ((num < -112.5f) ? (-135f) : ((num < -67.5f) ? (-90f) : ((num < -22.5f) ? (-45f) : ((num < 22.5f) ? 0f : ((num < 67.5f) ? 45f : ((num < 112.5f) ? 90f : ((!(num < 157.5f)) ? 180f : 135f))))))));
                    animator.SetFloat(AnimationHashes.Params.Angle, num);
                    animator.SetTrigger(AnimationHashes.Params.Bump);
                }
            }
        }
        protected void DefaultDoAction(LocomotionAction action, object userData = null)
        {
            switch (action)
            {
            case LocomotionAction.ChargeThrow:
                if (snowballThrow != null)
                {
                    snowballThrow.ChargeSnowball();
                }
                break;

            case LocomotionAction.LaunchThrow:
                if (snowballThrow != null)
                {
                    snowballThrow.LaunchSnowball((float)userData);
                }
                break;

            case LocomotionAction.Interact:
            {
                PenguinInteraction component = GetComponent <PenguinInteraction>();
                if (component != null && component.RequestInteraction())
                {
                    Broadcaster.BroadcastOnDoAction(action, userData);
                }
                break;
            }

            case LocomotionAction.Action1:
            case LocomotionAction.Action2:
            case LocomotionAction.Action3:
            {
                PenguinInteraction component = GetComponent <PenguinInteraction>();
                if (component != null && !LocomotionUtils.IsInAir(LocomotionUtils.GetAnimatorStateInfo(animator)))
                {
                    Broadcaster.BroadcastOnDoAction(action, userData);
                }
                break;
            }
            }
        }
Beispiel #13
0
        private void LateUpdate()
        {
            AnimatorStateInfo animatorStateInfo = LocomotionUtils.GetAnimatorStateInfo(animator);
            LocoMode          integer           = (LocoMode)animator.GetInteger(AnimationHashes.Params.LocoMode);
            Vector3           vector            = animator.deltaPosition / Time.deltaTime;
            Vector3           vector2           = (animator.GetBool(AnimationHashes.Params.Scripted) ? vector : Vector3.zero);

            vector.y = 0f;
            if (isWalking || (isLanding && integer == LocoMode.Walk))
            {
                if (Vector3.Angle(desiredFacing, curFacing) >= mutableData.MinFacingAngleToResetMomentum * Time.deltaTime)
                {
                    mutableData.WalkParams.speedMult       = mutableData.WalkParams.TurnSpeedMult;
                    mutableData.WalkParams.ElapsedWalkTime = 0f;
                }
                vector2 = vector * mutableData.WalkParams.Speed;
                TurnToDesiredFacing(mutableData.WalkParams.TurnSmoothing, mutableData.WalkParams.MaxTurnDegreesPerSec);
            }
            else if (isJogging || (isLanding && integer == LocoMode.Jog))
            {
                if (Vector3.Angle(desiredFacing, curFacing) >= mutableData.MinFacingAngleToResetMomentum * Time.deltaTime)
                {
                    mutableData.JogParams.speedMult      = mutableData.JogParams.TurnSpeedMult;
                    mutableData.JogParams.ElapsedJogTime = 0f;
                }
                vector2 = desiredFacing * mutableData.JogParams.Speed * mutableData.JogParams.speedMult;
                TurnToDesiredFacing(mutableData.JogParams.TurnSmoothing, mutableData.JogParams.MaxTurnDegreesPerSec);
            }
            else if (isSprinting || (isLanding && integer == LocoMode.Sprint))
            {
                if (Vector3.Angle(desiredFacing, curFacing) >= mutableData.MinFacingAngleToResetMomentum * Time.deltaTime)
                {
                    mutableData.SprintParams.speedMult = mutableData.SprintParams.TurnSpeedMult;
                }
                vector2 = desiredFacing * mutableData.SprintParams.Speed * mutableData.SprintParams.speedMult;
                TurnToDesiredFacing(mutableData.SprintParams.TurnSmoothing, mutableData.SprintParams.MaxTurnDegreesPerSec);
            }
            else if (isStopping)
            {
                vector2 = vector * mutableData.StopAnimVelMultiplier;
            }
            else if (isPivoting)
            {
                float normalizedTime = animatorStateInfo.normalizedTime;
                vector2 = Vector3.Lerp(prevVel, Vector3.zero, normalizedTime * normalizedTime * normalizedTime);
                if (animatorStateInfo.normalizedTime > 0.2f)
                {
                    float num = normalizedTime * normalizedTime * normalizedTime;
                    TurnToDesiredFacing(num / Time.deltaTime, mutableData.SprintParams.MaxTurnDegreesPerSec);
                }
            }
            else if (isInAir)
            {
                vector2 = inAirVel;
                TurnToDesiredFacing(mutableData.InAirParams.TurnSmoothing, mutableData.InAirParams.MaxTurnDegreesPerSec);
            }
            if (snapToDesiredFacing)
            {
                if (Vector3.Angle(curFacing, desiredFacing) < 1f)
                {
                    snapToDesiredFacing = false;
                }
                TurnToDesiredFacing(mutableData.IdleParams.TurnSmoothing, mutableData.IdleParams.MaxTurnDegreesPerSec);
            }
            if (!Behaviour.IgnoreTranslation)
            {
                prevVel   = vector2;
                prevVel.y = 0f;
                vector2  += impulseVel;
                if (Behaviour.IgnoreCollisions)
                {
                    base.transform.position += vector2 * Time.deltaTime;
                    return;
                }
                if (vector2 == gravityVector && characterController.isGrounded && prevPosition == base.transform.position)
                {
                    timeSinceLastPhysicsCheck += Time.deltaTime;
                    if (timeSinceLastPhysicsCheck < 1f)
                    {
                        return;
                    }
                }
                timeSinceLastPhysicsCheck = 0f;
                prevPosition = base.transform.position;
                characterController.Move(vector2 * Time.deltaTime);
            }
            else
            {
                prevVel = Vector3.zero;
            }
        }
Beispiel #14
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;
        }
Beispiel #15
0
        private bool canSitFromCurrentState()
        {
            AnimatorStateInfo animatorStateInfo = LocomotionUtils.GetAnimatorStateInfo(animator);

            return(LocomotionUtils.IsIdling(animatorStateInfo) || LocomotionUtils.IsLocomoting(animatorStateInfo) || LocomotionUtils.IsInAir(animatorStateInfo) || LocomotionUtils.IsLanding(animatorStateInfo) || LocomotionUtils.IsSwimming(animatorStateInfo));
        }
 private void applyIK()
 {
     if (propUser == null)
     {
         propUser = GetComponent <PropUser>();
         if (propUser == null)
         {
             return;
         }
     }
     if (curPropGO == null)
     {
         if (propUser.Prop != null)
         {
             resetIK(propUser.Prop.gameObject);
         }
         else
         {
             InvitationalItemController componentInChildren = GetComponentInChildren <InvitationalItemController>();
             if (componentInChildren != null)
             {
                 curPropGO = componentInChildren.gameObject;
                 resetIK(curPropGO);
             }
         }
     }
     if (curPropGO == null && isHoldingProp)
     {
         AnimatorStateInfo currentAnimatorStateInfo = animator.GetCurrentAnimatorStateInfo(1);
         if (!LocomotionUtils.IsUsing(currentAnimatorStateInfo))
         {
             resetIK(null);
         }
     }
     if (propIK != null && ikBones.Count > 0)
     {
         AnimatorStateInfo animatorStateInfo = LocomotionUtils.GetAnimatorStateInfo(animator);
         for (int i = 0; i < ikBones.Count; i++)
         {
             if (swim.IsInShallowWater)
             {
                 if (LocomotionUtils.IsIdling(animatorStateInfo))
                 {
                     ikBones[i].TargetAngle = propIK.IKModifiers[i].IdleZRot;
                 }
                 else
                 {
                     ikBones[i].TargetAngle = propIK.IKModifiers[i].SwimMoveZRot;
                 }
             }
             else if (LocomotionUtils.IsIdling(animatorStateInfo))
             {
                 ikBones[i].TargetAngle = propIK.IKModifiers[i].IdleZRot;
             }
             else
             {
                 ikBones[i].TargetAngle = propIK.IKModifiers[i].DiveMoveZRot;
             }
         }
     }
     blendIK();
 }
 private void LateUpdate()
 {
     if (!Active)
     {
         return;
     }
     if (curState == State.Resurfacing || curState == State.QuickResurfacing)
     {
         base.transform.position += animator.deltaPosition;
         base.transform.rotation  = getSmoothFaceCameraRotation();
     }
     else
     {
         if (curState == State.Interacting)
         {
             return;
         }
         if (curState != State.ExitingWater && !LocomotionUtils.IsSwimming(LocomotionUtils.GetAnimatorStateInfo(animator)))
         {
             animator.SetTrigger(AnimationHashes.Params.Swim);
         }
         LocomotionPrimitive.PrimitiveOutput output = swim.GetOutput();
         Vector3    vector   = output.wsDeltaPos;
         Quaternion rotation = output.wsRotation;
         if (isInShallowWater)
         {
             vector *= mutableData.ShallowWaterSwimSpeedMultiplier;
         }
         if (curState == State.ExitingWater)
         {
             rotation = Quaternion.LookRotation(new Vector3(base.transform.forward.x, 0f, base.transform.forward.z), Vector3.up);
             rotation = Quaternion.Slerp(base.transform.rotation, rotation, 5f * Time.deltaTime);
             vector   = animator.deltaPosition;
         }
         else
         {
             if (curState == State.ReactingToHit)
             {
                 rotation = getSmoothFaceCameraRotation();
             }
             vector += impulses.GetOutput().wsVelocity *Time.deltaTime;
             if (!isInShallowWater && mutableData.FreezeAxis != SwimControllerData.FreezeAxisType.None)
             {
                 vector[(int)mutableData.FreezeAxis] = mutableData.FreezeDist;
             }
         }
         Vector3 position = base.transform.position;
         base.transform.rotation = rotation;
         if (vector != Vector3.zero)
         {
             characterController.Move(vector);
         }
         if (curState != 0)
         {
             return;
         }
         Vector3 position2;
         if (isInShallowWater)
         {
             position2               = base.transform.position;
             position2.y             = logicalSurfaceHeight;
             base.transform.position = position2;
         }
         else
         {
             if (mutableData.FreezeAxis != SwimControllerData.FreezeAxisType.None && !isCloseToSurface())
             {
                 position2 = base.transform.position;
                 position2[(int)mutableData.FreezeAxis] = Mathf.Lerp(position2[(int)mutableData.FreezeAxis], mutableData.FreezeDist, 5f * Time.deltaTime);
                 if (Mathf.Abs(position2[(int)mutableData.FreezeAxis] - mutableData.FreezeDist) < 0.01f)
                 {
                     position2[(int)mutableData.FreezeAxis] = mutableData.FreezeDist;
                 }
                 base.transform.position = position2;
             }
             if (base.transform.position.y >= logicalSurfaceHeight && curState != State.PostResurfacing)
             {
                 position2               = base.transform.position;
                 position2.y             = logicalSurfaceHeight;
                 base.transform.position = position2;
                 if (LocomotionUtils.IsTurboing(animator.GetCurrentAnimatorStateInfo(0)))
                 {
                     animator.SetTrigger(AnimationHashes.Params.AbortTorpedo);
                 }
             }
         }
         applyIK();
     }
 }
Beispiel #18
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));
     }
 }
        protected virtual bool canSlideFromCurrentState()
        {
            AnimatorStateInfo animatorStateInfo = LocomotionUtils.GetAnimatorStateInfo(animator);

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