using System; using ECM2; using UnityEngine; namespace NBF { public class PlayerCharacter : Character { [Tooltip("The first person camera parent.")] public GameObject cameraParent; private float _cameraPitch; private FPlayer _player; [HideInInspector] public int nextShowSlotIndex = -1; [Space(15.0f)] public bool invertLook = true; [Tooltip("Look sensitivity")] public Vector2 sensitivity = new Vector2(0.05f, 0.05f); [Space(15.0f)] [Tooltip("How far in degrees can you move the camera down.")] public float minPitch = -80.0f; [Tooltip("How far in degrees can you move the camera up.")] public float maxPitch = 80.0f; protected override void Start() { base.Start(); camera = BaseCamera.Main; _player = GetComponent(); transform.position = _player.Data.position; transform.rotation = _player.Data.rotation; App.Inst.SetMouseCurrsor(false); InputManager.OnQuickIndexAction += OnQuickIndexAction; InputManager.OnUseTorchAction += OnUseTorchAction; InputManager.OnUseTelescopeAction += OnUseTelescopeAction; } private void Update() { // Move Vector2 movementInput = InputManager.GetMovementInput(); Vector3 movementDirection = Vector3.zero; movementDirection += Vector3.forward * movementInput.y; movementDirection += Vector3.right * movementInput.x; movementDirection = movementDirection.relativeTo(cameraTransform, GetUpVector()); SetMovementDirection(movementDirection); // Look Vector2 lookInput = InputManager.GetLookInput() * sensitivity; AddControlYawInput(lookInput.x); AddControlPitchInput(invertLook ? -lookInput.y : lookInput.y, minPitch, maxPitch); if (_player.CanChangeGear()) { if (nextShowSlotIndex > 0) { Debug.LogError("切换钓组========="); var data = Fishing.Inst.Datasource; data.SetSelfTestGear(nextShowSlotIndex); nextShowSlotIndex = -1; } } } private void OnDestroy() { InputManager.OnQuickIndexAction -= OnQuickIndexAction; InputManager.OnUseTorchAction -= OnUseTorchAction; InputManager.OnUseTelescopeAction -= OnUseTelescopeAction; } private void OnQuickIndexAction(int index) { nextShowSlotIndex = index; } private void OnUseTorchAction(bool ret) { if (!ret) { _player.Data.openLight = !_player.Data.openLight; } } private void OnUseTelescopeAction(bool ret) { if (!ret) { _player.Data.openTelescope = !_player.Data.openTelescope; _player.ToggleTelescope(); } } /// /// Add input (affecting Yaw). /// This is applied to the Character's rotation. /// public virtual void AddControlYawInput(float value) { if (value != 0.0f) AddYawInput(value); } /// /// Add input (affecting Pitch). /// This is applied to the cameraParent's local rotation. /// public virtual void AddControlPitchInput(float value, float minPitch = -80.0f, float maxPitch = 80.0f) { if (value != 0.0f) _cameraPitch = MathLib.ClampAngle(_cameraPitch + value, minPitch, maxPitch); } /// /// Update cameraParent local rotation applying current _cameraPitch value. /// protected virtual void UpdateCameraParentRotation() { cameraParent.transform.localRotation = Quaternion.Euler(_cameraPitch, 0.0f, 0.0f); } /// /// If overriden, base method MUST be called. /// protected virtual void LateUpdate() { UpdateCameraParentRotation(); } /// /// If overriden, base method MUST be called. /// protected override void Reset() { // Call base method implementation base.Reset(); // Disable character's rotation, // it is handled by the AddControlYawInput method SetRotationMode(RotationMode.None); } } }