new input
This commit is contained in:
159
Assets/Scripts/Fishing/Player/PlayerCharacter/PlayerCharacter.cs
Normal file
159
Assets/Scripts/Fishing/Player/PlayerCharacter/PlayerCharacter.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
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<FPlayer>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add input (affecting Yaw).
|
||||
/// This is applied to the Character's rotation.
|
||||
/// </summary>
|
||||
public virtual void AddControlYawInput(float value)
|
||||
{
|
||||
if (value != 0.0f)
|
||||
AddYawInput(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add input (affecting Pitch).
|
||||
/// This is applied to the cameraParent's local rotation.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update cameraParent local rotation applying current _cameraPitch value.
|
||||
/// </summary>
|
||||
protected virtual void UpdateCameraParentRotation()
|
||||
{
|
||||
cameraParent.transform.localRotation = Quaternion.Euler(_cameraPitch, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If overriden, base method MUST be called.
|
||||
/// </summary>
|
||||
protected virtual void LateUpdate()
|
||||
{
|
||||
UpdateCameraParentRotation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If overriden, base method MUST be called.
|
||||
/// </summary>
|
||||
protected override void Reset()
|
||||
{
|
||||
// Call base method implementation
|
||||
|
||||
base.Reset();
|
||||
|
||||
// Disable character's rotation,
|
||||
// it is handled by the AddControlYawInput method
|
||||
|
||||
SetRotationMode(RotationMode.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcefd1090dc44a539b4fcd30f2adf503
|
||||
timeCreated: 1747495536
|
||||
Reference in New Issue
Block a user