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(); walkingSpeed = firstPersonController.m_WalkSpeed; runningSpeed = firstPersonController.m_RunSpeed; _player = GetComponent(); 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); } } } }