新输入系统

This commit is contained in:
2025-05-11 21:42:24 +08:00
parent e5edaa7bca
commit aadd564c38
20 changed files with 12022 additions and 3525 deletions

View File

@@ -1,129 +1,452 @@
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;
// using Rewired;
using UnityEngine;
using UnityEngine.InputSystem;
public class InputManager : MonoBehaviour
namespace NBF
{
public struct POINT
public class InputManager : MonoBehaviour
{
public int X;
public static bool IsOp1;
public static bool IsOp2;
public int Y;
}
public static bool IsRunning;
public static event Action<bool> OnOp1Action;
public static event Action<bool> OnOp2Action;
public static event Action<bool> OnUseAction;
public static event Action<bool> OnSelectItemAction;
public static event Action<bool> OnSelectBaitAction;
public static event Action<bool> OnSelectFoodAction;
/// <summary>
/// 快速选择数值
/// </summary>
public static event Action<int> OnQuickIndexAction;
/// <summary>
/// 使用手电筒
/// </summary>
public static event Action<bool> OnUseTorchAction;
/// <summary>
/// 使用抄网
/// </summary>
public static event Action<bool> OnUseBrailAction;
/// <summary>
/// 使用望远镜
/// </summary>
public static event Action<bool> OnUseTelescopeAction;
/// <summary>
/// 添加浮漂
/// </summary>
public static event Action<bool> OnAddBobAction;
/// <summary>
/// 减少浮漂
/// </summary>
public static event Action<bool> OnSubBobAction;
/// <summary>
/// 返回背包
/// </summary>
public static event Action<bool> OnToBagAction;
// [Tooltip("Rewired Input Manager's player used for handling player's input")]
// private Player player;
/// <summary>
/// 帮助
/// </summary>
public static event Action<bool> OnHelpAction;
public bool IgnoreAllInput = false;
/// <summary>
/// 聊天
/// </summary>
public static event Action<bool> OnChatAction;
/// <summary>
/// 物品信息
/// </summary>
public static event Action<bool> OnInfoAction;
/// <summary>
/// 技能
/// </summary>
public static event Action<bool> OnSkillAction;
/// <summary>
/// 打开背包
/// </summary>
public static event Action<bool> OnOpenBagAction;
/// <summary>
/// 打开鱼护
/// </summary>
public static event Action<bool> OnKeepnetAction;
/// <summary>
/// 打开制造
/// </summary>
public static event Action<bool> OnMakeAction;
/// <summary>
/// 打开地图
/// </summary>
public static event Action<bool> OnMapAction;
public static bool IsMouseLeft;
public static bool IsMouseRight;
public static PlayerInputControl PlayerInputControl { get; private set; }
public static bool isShowSlot0;
public static bool isShowSlot1;
public static bool isShowSlot2;
public static bool isShowSlot3;
public static bool isShowSlot4;
[DllImport("user32.dll")]
private static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out POINT lpPoint);
private PlayerInputControl _playerInputControl;
private void Start()
{
_playerInputControl = new PlayerInputControl();
}
private void Update()
{
if (IgnoreAllInput)
public static Vector2 GetMovementInput()
{
return;
return PlayerInputControl.Normal.Move?.ReadValue<Vector2>() ?? Vector2.zero;
}
if (Input.GetMouseButtonDown(0))
public static Vector2 GetLookInput()
{
IsMouseLeft = true;
return PlayerInputControl.Normal.Look?.ReadValue<Vector2>() ?? Vector2.zero;
}
if (Input.GetMouseButtonUp(0))
private void Start()
{
IsMouseLeft = false;
PlayerInputControl = new PlayerInputControl();
PlayerInputControl.Enable();
PlayerInputControl.Normal.Enable();
AddEvent();
}
if (Input.GetMouseButtonDown(1))
private void OnDestroy()
{
IsMouseRight = true;
RemoveEvent();
}
if (Input.GetMouseButtonUp(1))
private void AddEvent()
{
IsMouseRight = false;
PlayerInputControl.Normal.Run.performed += OnRun;
PlayerInputControl.Normal.Run.canceled += OnRun;
PlayerInputControl.Normal.Op1.performed += OnOp1;
PlayerInputControl.Normal.Op1.canceled += OnOp1;
PlayerInputControl.Normal.Op2.performed += OnOp2;
PlayerInputControl.Normal.Op2.canceled += OnOp2;
PlayerInputControl.Normal.Use.performed += OnUse;
PlayerInputControl.Normal.Use.canceled += OnUse;
PlayerInputControl.Normal.SelectItem.performed += OnSelectItem;
PlayerInputControl.Normal.SelectItem.canceled += OnSelectItem;
PlayerInputControl.Normal.SelectFood.performed += OnSelectFood;
PlayerInputControl.Normal.SelectFood.canceled += OnSelectFood;
PlayerInputControl.Normal.SelectBait.performed += OnSelectBait;
PlayerInputControl.Normal.SelectBait.canceled += OnSelectBait;
PlayerInputControl.Normal.UseTorch.performed += OnUseTorch;
PlayerInputControl.Normal.UseTorch.canceled += OnUseTorch;
PlayerInputControl.Normal.UseTelescope.performed += OnUseTelescope;
PlayerInputControl.Normal.UseTelescope.canceled += OnUseTelescope;
PlayerInputControl.Normal.UseBrail.performed += OnUseBrail;
PlayerInputControl.Normal.UseBrail.canceled += OnUseBrail;
PlayerInputControl.Normal.AddBob.performed += OnAddBob;
PlayerInputControl.Normal.AddBob.canceled += OnAddBob;
PlayerInputControl.Normal.SubBob.performed += OnSubBob;
PlayerInputControl.Normal.SubBob.canceled += OnSubBob;
PlayerInputControl.Normal.ToBag.performed += OnToBag;
PlayerInputControl.Normal.ToBag.canceled += OnToBag;
PlayerInputControl.Normal.Help.performed += OnHelp;
PlayerInputControl.Normal.Help.canceled += OnHelp;
PlayerInputControl.Normal.Chat.performed += OnChat;
PlayerInputControl.Normal.Chat.canceled += OnChat;
PlayerInputControl.Normal.Info.performed += OnInfo;
PlayerInputControl.Normal.Info.canceled += OnInfo;
PlayerInputControl.Normal.Skill.performed += OnSkill;
PlayerInputControl.Normal.Skill.canceled += OnSkill;
PlayerInputControl.Normal.OpenBag.performed += OnOpenBag;
PlayerInputControl.Normal.OpenBag.canceled += OnOpenBag;
PlayerInputControl.Normal.Keepnet.performed += OnKeepnet;
PlayerInputControl.Normal.Keepnet.canceled += OnKeepnet;
PlayerInputControl.Normal.Make.performed += OnMake;
PlayerInputControl.Normal.Make.canceled += OnMake;
PlayerInputControl.Normal.Map.performed += OnMap;
PlayerInputControl.Normal.Map.canceled += OnMap;
PlayerInputControl.Normal.Quick1.performed += OnQuick1;
PlayerInputControl.Normal.Quick2.performed += OnQuick2;
PlayerInputControl.Normal.Quick3.performed += OnQuick3;
PlayerInputControl.Normal.Quick4.performed += OnQuick4;
PlayerInputControl.Normal.Quick5.performed += OnQuick5;
PlayerInputControl.Normal.Quick6.performed += OnQuick6;
PlayerInputControl.Normal.Quick7.performed += OnQuick7;
PlayerInputControl.Normal.Quick8.performed += OnQuick8;
PlayerInputControl.Normal.Quick9.performed += OnQuick9;
}
if (Input.GetKeyDown(KeyCode.Alpha0))
private void RemoveEvent()
{
isShowSlot0 = true;
Debug.LogError("showSlot0======");
}
else
{
isShowSlot0 = false;
PlayerInputControl.Normal.Run.performed -= OnRun;
PlayerInputControl.Normal.Run.canceled -= OnRun;
PlayerInputControl.Normal.Op1.performed -= OnOp1;
PlayerInputControl.Normal.Op1.canceled -= OnOp1;
PlayerInputControl.Normal.Op2.performed -= OnOp2;
PlayerInputControl.Normal.Op2.canceled -= OnOp2;
PlayerInputControl.Normal.Use.performed -= OnUse;
PlayerInputControl.Normal.Use.canceled -= OnUse;
PlayerInputControl.Normal.SelectItem.performed -= OnSelectItem;
PlayerInputControl.Normal.SelectItem.canceled -= OnSelectItem;
PlayerInputControl.Normal.SelectFood.performed -= OnSelectFood;
PlayerInputControl.Normal.SelectFood.canceled -= OnSelectFood;
PlayerInputControl.Normal.SelectBait.performed -= OnSelectBait;
PlayerInputControl.Normal.SelectBait.canceled -= OnSelectBait;
PlayerInputControl.Normal.UseTorch.performed -= OnUseTorch;
PlayerInputControl.Normal.UseTorch.canceled -= OnUseTorch;
PlayerInputControl.Normal.UseTelescope.performed -= OnUseTelescope;
PlayerInputControl.Normal.UseTelescope.canceled -= OnUseTelescope;
PlayerInputControl.Normal.UseBrail.performed -= OnUseBrail;
PlayerInputControl.Normal.UseBrail.canceled -= OnUseBrail;
PlayerInputControl.Normal.AddBob.performed -= OnAddBob;
PlayerInputControl.Normal.AddBob.canceled -= OnAddBob;
PlayerInputControl.Normal.SubBob.performed -= OnSubBob;
PlayerInputControl.Normal.SubBob.canceled -= OnSubBob;
PlayerInputControl.Normal.ToBag.performed -= OnToBag;
PlayerInputControl.Normal.ToBag.canceled -= OnToBag;
PlayerInputControl.Normal.Help.performed -= OnHelp;
PlayerInputControl.Normal.Help.canceled -= OnHelp;
PlayerInputControl.Normal.Chat.performed -= OnChat;
PlayerInputControl.Normal.Chat.canceled -= OnChat;
PlayerInputControl.Normal.Info.performed -= OnInfo;
PlayerInputControl.Normal.Info.canceled -= OnInfo;
PlayerInputControl.Normal.Skill.performed -= OnSkill;
PlayerInputControl.Normal.Skill.canceled -= OnSkill;
PlayerInputControl.Normal.OpenBag.performed -= OnOpenBag;
PlayerInputControl.Normal.OpenBag.canceled -= OnOpenBag;
PlayerInputControl.Normal.Keepnet.performed -= OnKeepnet;
PlayerInputControl.Normal.Keepnet.canceled -= OnKeepnet;
PlayerInputControl.Normal.Make.performed -= OnMake;
PlayerInputControl.Normal.Make.canceled -= OnMake;
PlayerInputControl.Normal.Map.performed -= OnMap;
PlayerInputControl.Normal.Map.canceled -= OnMap;
PlayerInputControl.Normal.Quick1.performed -= OnQuick1;
PlayerInputControl.Normal.Quick2.performed -= OnQuick2;
PlayerInputControl.Normal.Quick3.performed -= OnQuick3;
PlayerInputControl.Normal.Quick4.performed -= OnQuick4;
PlayerInputControl.Normal.Quick5.performed -= OnQuick5;
PlayerInputControl.Normal.Quick6.performed -= OnQuick6;
PlayerInputControl.Normal.Quick7.performed -= OnQuick7;
PlayerInputControl.Normal.Quick8.performed -= OnQuick8;
PlayerInputControl.Normal.Quick9.performed -= OnQuick9;
}
if (Input.GetKeyDown(KeyCode.Alpha1))
private void OnRun(InputAction.CallbackContext context)
{
isShowSlot1 = true;
Debug.LogError("showSlot1======");
}
else
{
isShowSlot1 = false;
IsRunning = context.performed;
}
if (Input.GetKeyDown(KeyCode.Alpha2))
private void OnOp1(InputAction.CallbackContext context)
{
isShowSlot2 = true;
Debug.LogError("showSlot2======");
}
else
{
isShowSlot2 = false;
IsOp1 = context.performed;
Debug.Log($"IsOp1={IsOp1}");
OnOp1Action?.Invoke(IsOp1);
}
if (Input.GetKeyDown(KeyCode.Alpha3))
private void OnOp2(InputAction.CallbackContext context)
{
isShowSlot3 = true;
}
else
{
isShowSlot3 = false;
IsOp2 = context.performed;
Debug.Log($"OnOp2={IsOp2}");
OnOp2Action?.Invoke(IsOp2);
}
if (Input.GetKeyDown(KeyCode.Alpha4))
private void OnUse(InputAction.CallbackContext context)
{
isShowSlot4 = true;
OnUseAction?.Invoke(context.performed);
}
else
private void OnSelectItem(InputAction.CallbackContext context)
{
isShowSlot4 = false;
OnSelectItemAction?.Invoke(context.performed);
}
private void OnSelectFood(InputAction.CallbackContext context)
{
OnSelectFoodAction?.Invoke(context.performed);
}
private void OnSelectBait(InputAction.CallbackContext context)
{
OnSelectBaitAction?.Invoke(context.performed);
}
private void OnUseTorch(InputAction.CallbackContext context)
{
OnUseTorchAction?.Invoke(context.performed);
}
private void OnUseTelescope(InputAction.CallbackContext context)
{
OnUseTelescopeAction?.Invoke(context.performed);
}
private void OnUseBrail(InputAction.CallbackContext context)
{
OnUseBrailAction?.Invoke(context.performed);
}
private void OnAddBob(InputAction.CallbackContext context)
{
OnSubBobAction?.Invoke(context.performed);
}
private void OnSubBob(InputAction.CallbackContext context)
{
OnSubBobAction?.Invoke(context.performed);
}
private void OnToBag(InputAction.CallbackContext context)
{
OnToBagAction?.Invoke(context.performed);
}
private void OnHelp(InputAction.CallbackContext context)
{
OnHelpAction?.Invoke(context.performed);
}
private void OnChat(InputAction.CallbackContext context)
{
OnChatAction?.Invoke(context.performed);
}
private void OnInfo(InputAction.CallbackContext context)
{
OnInfoAction?.Invoke(context.performed);
}
private void OnSkill(InputAction.CallbackContext context)
{
OnSkillAction?.Invoke(context.performed);
}
private void OnOpenBag(InputAction.CallbackContext context)
{
OnOpenBagAction?.Invoke(context.performed);
}
private void OnKeepnet(InputAction.CallbackContext context)
{
OnKeepnetAction?.Invoke(context.performed);
}
private void OnMake(InputAction.CallbackContext context)
{
OnMakeAction?.Invoke(context.performed);
}
private void OnMap(InputAction.CallbackContext context)
{
OnMapAction?.Invoke(context.performed);
}
private void OnQuick1(InputAction.CallbackContext context)
{
if (context.performed)
{
OnQuickIndexAction?.Invoke(1);
}
}
private void OnQuick2(InputAction.CallbackContext context)
{
if (context.performed)
{
OnQuickIndexAction?.Invoke(2);
}
}
private void OnQuick3(InputAction.CallbackContext context)
{
if (context.performed)
{
OnQuickIndexAction?.Invoke(3);
}
}
private void OnQuick4(InputAction.CallbackContext context)
{
if (context.performed)
{
OnQuickIndexAction?.Invoke(4);
}
}
private void OnQuick5(InputAction.CallbackContext context)
{
if (context.performed)
{
OnQuickIndexAction?.Invoke(5);
}
}
private void OnQuick6(InputAction.CallbackContext context)
{
if (context.performed)
{
OnQuickIndexAction?.Invoke(6);
}
}
private void OnQuick7(InputAction.CallbackContext context)
{
if (context.performed)
{
OnQuickIndexAction?.Invoke(7);
}
}
private void OnQuick8(InputAction.CallbackContext context)
{
if (context.performed)
{
OnQuickIndexAction?.Invoke(8);
}
}
private void OnQuick9(InputAction.CallbackContext context)
{
if (context.performed)
{
OnQuickIndexAction?.Invoke(9);
}
}
}
}

View File

@@ -52,7 +52,7 @@ namespace NBF
player.currentGear = new FPlayerGearData();
var gear = player.currentGear;
if (slot == 0)
if (slot == 1)
{
player.lineLength = 3.6f;
gear.Type = GearType.Pole;
@@ -88,7 +88,7 @@ namespace NBF
};
gear.reel = null;
}
else if (slot == 1)
else if (slot == 2)
{
player.lineLength = 0.4f;
gear.Type = GearType.SpinningFloat;
@@ -128,7 +128,7 @@ namespace NBF
configId = 800001
};
}
else if (slot == 2)
else if (slot == 3)
{
player.lineLength = 0.4f;
gear.Type = GearType.Spinning;

View File

@@ -39,7 +39,7 @@ namespace NBF
return States.Player.Idle;
}
if (InputManager.IsMouseLeft)
if (InputManager.IsOp1)
{
if (_owner.PlayerAnimatorCtrl.ThrowMode == ThrowModeEnum.Float)
{
@@ -53,7 +53,7 @@ namespace NBF
}
}
if (InputManager.IsMouseRight)
if (InputManager.IsOp2)
{
if (_owner.PlayerAnimatorCtrl.ThrowMode == ThrowModeEnum.Spin)
{

View File

@@ -85,7 +85,7 @@ namespace NBF
if (_owner.Gears.Rod)
{
//如果准备好了杆子,则可进入抛竿
if (Input.GetMouseButtonDown(0))
if (InputManager.IsOp1)
{
return States.Player.WaitThrow;
}

View File

@@ -65,7 +65,7 @@ namespace NBF
ChargedProgress = 1;
}
if (!InputManager.IsMouseLeft)
if (!InputManager.IsOp1)
{
Stage = Phase.Confirm;
}

View File

@@ -34,6 +34,13 @@ namespace NBF
Timer.Once(1f, this, EnableFirstPersonController);
App.Inst.SetMouseCurrsor(false);
InputManager.OnQuickIndexAction += OnQuickIndexAction;
}
private void OnDestroy()
{
InputManager.OnQuickIndexAction -= OnQuickIndexAction;
}
private void EnableFirstPersonController()
@@ -41,14 +48,24 @@ namespace NBF
firstPersonController.enabled = true;
}
private void OnQuickIndexAction(int index)
{
nextShowSlotIndex = index;
}
private void Update()
{
// firstPersonController.horizontal = InputManager.movementAxis.x;
// firstPersonController.vertical = InputManager.movementAxis.y;
//
// firstPersonController.isJumping = InputManager.isJumping;
// firstPersonController.isRuning = InputManager.isRunning;
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;
@@ -67,42 +84,10 @@ namespace NBF
firstPersonController.m_RunSpeed = runningSpeed;
}
// firstPersonController.m_MouseLook.XSensitivity =
// GameManager.Instance._playerData.Player[GameManager.Instance._playerData.currentPlayerProfileIndex]
// .mouseSensitivity * GetPlayerHandPower();
// firstPersonController.m_MouseLook.YSensitivity =
// GameManager.Instance._playerData.Player[GameManager.Instance._playerData.currentPlayerProfileIndex]
// .mouseSensitivity * GetPlayerHandPower();
if (_player.CanChangeGear())
{
// if (InputManager.isShowSlot0)
// {
// nextShowSlotIndex = 0;
// }
//
// if (InputManager.isShowSlot1)
// {
// nextShowSlotIndex = 1;
// }
//
// if (InputManager.isShowSlot2)
// {
// nextShowSlotIndex = 2;
// }
//
// if (InputManager.isShowSlot3)
// {
// nextShowSlotIndex = 3;
// }
//
// if (InputManager.isShowSlot4)
// {
// nextShowSlotIndex = 4;
// }
if (nextShowSlotIndex != -1)
if (nextShowSlotIndex > 0)
{
Debug.LogError("切换钓组=========");
var data = Fishing.Inst.Datasource;

File diff suppressed because it is too large Load Diff