using System; using SLSUtilities.FunctionalAnimation; using UniRx; using UnityEngine; namespace Cielonos.MainGame.Characters { public partial class PlayerLandMovementSubcontroller : LandMovementSubcontroller, IPlayerSubcontroller { public Player player => owner as Player; public override void OnAnimatorMove() { if (DeltaTime == 0) { return; } Rotate(); Move(); Jump(); base.OnAnimatorMove(); InitiativeMove(); } } public partial class PlayerLandMovementSubcontroller { void Rotate() { if (animationSc.isDuringRootMotion) return; Vector3 inputDirection = new Vector3(player.inputSc.Move.x, 0.0f, player.inputSc.Move.y).normalized; if (player.inputSc.IsMoving) { targetRotation = Mathf.Atan2(inputDirection.x, inputDirection.z) * Mathf.Rad2Deg + player.viewSc.playerCamera.transform.eulerAngles.y; if (rotationType == CharacterRotationType.ByMovement && canRotate.value) { float rotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref rotationVelocity, rotationSmoothTime); player.transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f); } } targetDirection = Quaternion.Euler(0.0f, targetRotation, 0.0f) * Vector3.forward; } void Move() { if (!canMove.value) { moveSpeed = 0; return; } float targetSpeed = player.attributeSm.GetAttribute("MoveSpeed", 10f) * (isSprinting ? sprintSpeedMultiplier : 1f); float movementAnimationSpeedMultiplier = !player.inputSc.IsWalking && targetSpeed > 10f ? targetSpeed / 10f : 1; float inputMagnitude = player.inputSc.Move.magnitude; moveAcceleration = player.attributeSm.GetAttribute("MoveAcceleration", 6); moveDeceleration = player.attributeSm.GetAttribute("MoveDeceleration", 8); if (player.inputSc.IsMoving) { bool success = animationSc.fullBodyFuncAnimSm.Stop(DisruptionType.Movement, 0.25f); if (!success && animationSc.isDuringRootMotion) { if (!isDashing) { moveSpeed = Mathf.Lerp(moveSpeed, 0, DeltaTime * moveDeceleration); } return; } } else { isSprinting = false; } animator.SetFloat("MoveSpeedMultiplier", movementAnimationSpeedMultiplier); if (!isRushStopping && !isJumpLanding && player.inputSc.IsMoving) { float finalTargetSpeed = !player.inputSc.IsWalking ? targetSpeed * inputMagnitude : 2f; finalTargetSpeed = Mathf.Max(finalTargetSpeed, 1); moveSpeed = Mathf.Lerp(moveSpeed, finalTargetSpeed, DeltaTime * moveAcceleration); } else if (!isDashing) { moveSpeed = Mathf.Lerp(moveSpeed, 0, DeltaTime * moveDeceleration); } /*if (MotionController.characterRotationType == PlayerMotionController.CharacterRotationType.ByAiming) { mx = Mathf.Lerp(mx, Player.inputController.InputMoveValue.x, DeltaTime * movementSpeedAccelerationRate); my = Mathf.Lerp(my, Player.inputController.InputMoveValue.y, DeltaTime * movementSpeedAccelerationRate); Player.animator.SetFloat("MovementSpeedX", mx * movementSpeed); Player.animator.SetFloat("MovementSpeedZ", my * movementSpeed); } else */ { animator.SetFloat("MoveSpeedZ", moveSpeed); } if (moveSpeed > 5f * DeltaTime && player.inputSc.IsMoving) { runningTime += DeltaTime; } else { runningTime = 0; } } void Jump() { if (player.inputSc.JumpPressed) { if (player.inputSc.IsWalking) { Observable.Timer(TimeSpan.FromSeconds(0.16f)).Subscribe(_ => movementModifier = targetDirection.normalized * 10 * DeltaTime); } if (!isJumping && groundDetector.isOnGround) { animator.SetTrigger("Jump"); Observable.Timer(TimeSpan.FromSeconds(0.16f)).Subscribe(_ => { jumpVelocity = jumpForce; isJumping = true; jumpTime = 0; jumpHeldTime = 0; animator.SetBool("IsLandingOnGround", false); }); } } if (isJumping) { jumpTime += DeltaTime; if (jumpVelocity > 0) { jumpVelocity -= jumpGravity * DeltaTime; } else { // --- 玩家正在下落 --- // [不对称重力] 玩家正在下落 // 使用较大的 'fallingGravity' 让他感觉更“重” jumpVelocity -= jumpGravity * DeltaTime; if (groundDetector.DetectGround(0.8f) || groundDetector.isOnGround) { if (isJumping && jumpTime > 10000f) { animator.SetTrigger("LandFromHighAltitude"); isJumpLanding = true; Observable.Timer(TimeSpan.FromSeconds(0.4f)).Subscribe(_ => { isJumpLanding = false; }); } animator.SetBool("IsLandingOnGround", true); isJumping = false; movementModifier = Vector3.zero; } } } } protected override void UpdateFinalMovement() { base.UpdateFinalMovement(); float horizontalSpeed = horizontalMovement.magnitude / DeltaTime; float remapFactor = Mathf.InverseLerp(10f, 15f, horizontalSpeed); PostProcessingManager.Instance.speedLinesSm.SetRemap(1 - remapFactor); } } }