修改FPS控制

This commit is contained in:
2025-05-28 23:45:19 +08:00
parent 8e7afd9ea1
commit cdcb007d6d
18 changed files with 1012 additions and 54 deletions

View File

@@ -37,7 +37,7 @@ public partial class FPlayer : MonoBehaviour
public CapsuleCollider Collider;
public Rigidbody Rigidbody;
private void Awake()
{
PlayerAnimatorCtrl = gameObject.GetComponent<PlayerAnimator>();
@@ -77,6 +77,7 @@ public partial class FPlayer : MonoBehaviour
if (data.PlayerID == GameModel.RoleID)
{
Fishing.Inst.Player.SelfPlayer = this;
var mainSync = gameObject.AddComponent<FPlayerMainSync>();
BaseCamera.Main.transform.SetParent(CameraRoot);
BaseCamera.Main.transform.localPosition = Vector3.zero;
}

View File

@@ -0,0 +1,143 @@
using NBC;
using UnityEngine;
namespace NBF
{
public class FPlayerMainSync : MonoBehaviour
{
public FirstPersonController firstPersonController;
[HideInInspector] public int nextShowSlotIndex = -1;
private float walkingSpeed = 1f;
private float runningSpeed = 2f;
private FPlayer _player;
private bool _isRun;
private void Start()
{
firstPersonController = GetComponent<FirstPersonController>();
walkingSpeed = firstPersonController.m_WalkSpeed;
runningSpeed = firstPersonController.m_RunSpeed;
_player = GetComponent<FPlayer>();
transform.position = _player.Data.position;
transform.rotation = _player.Data.rotation;
Timer.Once(1f, this, EnableFirstPersonController);
// App.Inst.SetMouseCurrsor(false);
// InputManager.OnQuickIndexAction += OnQuickIndexAction;
// InputManager.OnUseTorchAction += OnUseTorchAction;
// InputManager.OnUseTelescopeAction += OnUseTelescopeAction;
InputManager.OnPlayerCanceled += OnPlayerCanceled;
InputManager.OnPlayerPerformed += OnPlayerPerformed;
}
private void OnDestroy()
{
InputManager.OnPlayerCanceled -= OnPlayerCanceled;
InputManager.OnPlayerPerformed -= OnPlayerPerformed;
// InputManager.OnQuickIndexAction -= OnQuickIndexAction;
// InputManager.OnUseTorchAction -= OnUseTorchAction;
// InputManager.OnUseTelescopeAction -= OnUseTelescopeAction;
}
private void OnPlayerPerformed(string action)
{
if (action == "Run")
{
// Sprint();
_isRun = true;
}
}
private void OnPlayerCanceled(string action)
{
if (action == "Run")
{
_isRun = false;
// StopSprinting();
}
else if (action.StartsWith("Quick"))
{
nextShowSlotIndex = int.Parse(action.Substring("Quick".Length));
}
else if (action == "UseTorch")
{
_player.Data.openLight = !_player.Data.openLight;
}
else if (action == "UseTelescope")
{
_player.Data.openTelescope = !_player.Data.openTelescope;
_player.ToggleTelescope();
}
}
private void EnableFirstPersonController()
{
firstPersonController.enabled = true;
}
private void Update()
{
var movementAxis = InputManager.GetMovementInput();
if (movementAxis != Vector2.zero)
{
// Debug
}
firstPersonController.horizontal = movementAxis.x;
firstPersonController.vertical = movementAxis.y;
// firstPersonController.isJumping = InputManager.IsJumping;
firstPersonController.isRuning = _isRun;
// firstPersonController.m_MouseLook.ControllerHandMode = GameManager.Instance._playerData
// .Player[GameManager.Instance._playerData.currentPlayerProfileIndex].controllerSetup;
if (firstPersonController.isWater)
{
firstPersonController.m_WalkSpeed = walkingSpeed - Mathf.Abs(transform.position.y - 1f);
firstPersonController.m_RunSpeed = firstPersonController.m_WalkSpeed;
firstPersonController.m_WalkSpeed = Mathf.Clamp(firstPersonController.m_WalkSpeed, 0.7f, 2f);
firstPersonController.m_RunSpeed = Mathf.Clamp(firstPersonController.m_RunSpeed, 0.8f, 2f);
}
else
{
firstPersonController.m_WalkSpeed = walkingSpeed;
firstPersonController.m_RunSpeed = runningSpeed;
}
if (_player.CanChangeGear())
{
if (nextShowSlotIndex > 0)
{
Debug.LogError("切换钓组=========");
var data = Fishing.Inst.Datasource;
data.SetSelfTestGear(nextShowSlotIndex);
nextShowSlotIndex = -1;
}
}
}
private void FixedUpdate()
{
if (_player.MainArm)
{
// _player.MainArm.Shoulder.SetCameraEulerAngleX(BaseCamera.Main.transform.localEulerAngles.x);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5cf18b87277f477ab6a9b59759ee17cb
timeCreated: 1748446764