新输入系统
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user