Files
Fishing2/Assets/Scripts/Fishing/Player/Sync/FPlayerMainSync.cs
2025-05-14 16:14:32 +08:00

121 lines
3.7 KiB
C#

using System;
using NBC;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
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 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;
}
private void OnDestroy()
{
InputManager.OnQuickIndexAction -= OnQuickIndexAction;
InputManager.OnUseTorchAction -= OnUseTorchAction;
InputManager.OnUseTelescopeAction -= OnUseTelescopeAction;
}
private void EnableFirstPersonController()
{
firstPersonController.enabled = true;
}
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();
}
}
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 = InputManager.IsRunning;
// 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;
}
}
}
}
}