快捷键重构
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using NBC;
|
||||
// using Rewired;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
@@ -13,95 +14,28 @@ namespace NBF
|
||||
public static bool IsOp1;
|
||||
public static bool IsOp2;
|
||||
|
||||
|
||||
public static event Action<bool> OnOp1Action;
|
||||
public static event Action<bool> OnOp2Action;
|
||||
public static event Action OnUseAction;
|
||||
public static event Action OnUse2Action;
|
||||
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;
|
||||
public static event Action<string> OnUIPerformed;
|
||||
|
||||
/// <summary>
|
||||
/// 使用手电筒
|
||||
/// 执行输入事件完毕
|
||||
/// </summary>
|
||||
public static event Action<bool> OnUseTorchAction;
|
||||
public static event Action<string> OnUICanceled;
|
||||
|
||||
/// <summary>
|
||||
/// 使用抄网
|
||||
/// 执行输入事件
|
||||
/// </summary>
|
||||
public static event Action<bool> OnUseBrailAction;
|
||||
public static event Action<string> OnPlayerPerformed;
|
||||
|
||||
/// <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;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 帮助
|
||||
/// </summary>
|
||||
public static event Action<bool> OnHelpAction;
|
||||
|
||||
/// <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;
|
||||
|
||||
/// <summary>
|
||||
/// 奔跑
|
||||
/// </summary>
|
||||
public static event Action<bool> OnRunAction;
|
||||
public static event Action<string> OnPlayerCanceled;
|
||||
|
||||
/// <summary>
|
||||
/// 触发交互游戏对象
|
||||
@@ -110,6 +44,11 @@ namespace NBF
|
||||
|
||||
public static PlayerInputControl PlayerInputControl { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// ui阻止游戏输入
|
||||
/// </summary>
|
||||
public static bool IsUIStopInput;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
@@ -118,19 +57,20 @@ namespace NBF
|
||||
|
||||
public static Vector2 GetMovementInput()
|
||||
{
|
||||
return PlayerInputControl.Normal.Move?.ReadValue<Vector2>() ?? Vector2.zero;
|
||||
if (IsUIStopInput) return Vector2.zero;
|
||||
return PlayerInputControl.Player.Move?.ReadValue<Vector2>() ?? Vector2.zero;
|
||||
}
|
||||
|
||||
public static Vector2 GetLookInput()
|
||||
{
|
||||
return PlayerInputControl.Normal.Look?.ReadValue<Vector2>() ?? Vector2.zero;
|
||||
if (IsUIStopInput) return Vector2.zero;
|
||||
return PlayerInputControl.Player.Look?.ReadValue<Vector2>() ?? Vector2.zero;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
PlayerInputControl = new PlayerInputControl();
|
||||
PlayerInputControl.Enable();
|
||||
PlayerInputControl.Normal.Enable();
|
||||
AddEvent();
|
||||
}
|
||||
|
||||
@@ -141,348 +81,85 @@ namespace NBF
|
||||
|
||||
private void AddEvent()
|
||||
{
|
||||
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.Use2.performed += OnUse2;
|
||||
PlayerInputControl.Normal.Use2.canceled += OnUse2;
|
||||
|
||||
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;
|
||||
foreach (var actionMap in PlayerInputControl.asset.actionMaps)
|
||||
{
|
||||
actionMap.Enable();
|
||||
if (actionMap.name == "UI")
|
||||
{
|
||||
foreach (var action in actionMap.actions)
|
||||
{
|
||||
if (action.type == InputActionType.Button)
|
||||
{
|
||||
action.performed += OnUIButtonPerformed;
|
||||
action.canceled += OnUIButtonCanceled;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (actionMap.name == "Normal")
|
||||
{
|
||||
foreach (var action in actionMap.actions)
|
||||
{
|
||||
if (action.type == InputActionType.Button)
|
||||
{
|
||||
action.performed += OnPlayerButtonPerformed;
|
||||
action.canceled += OnPlayerButtonCanceled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveEvent()
|
||||
{
|
||||
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.Use2.performed -= OnUse2;
|
||||
PlayerInputControl.Normal.Use2.canceled -= OnUse2;
|
||||
|
||||
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;
|
||||
OnUIPerformed = null;
|
||||
OnUICanceled = null;
|
||||
OnPlayerPerformed = null;
|
||||
OnPlayerCanceled = null;
|
||||
}
|
||||
|
||||
private void OnUIButtonPerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
OnUIPerformed?.Invoke(context.action.name);
|
||||
}
|
||||
|
||||
private void OnUIButtonCanceled(InputAction.CallbackContext context)
|
||||
{
|
||||
OnUICanceled?.Invoke(context.action.name);
|
||||
}
|
||||
|
||||
private void OnPlayerButtonPerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
if (IsUIStopInput) return;
|
||||
var actionName = context.action.name;
|
||||
if (actionName == "Op1")
|
||||
{
|
||||
OnOp1Action?.Invoke(true);
|
||||
}
|
||||
else if (actionName == "Op2")
|
||||
{
|
||||
OnOp2Action?.Invoke(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerButtonCanceled(InputAction.CallbackContext context)
|
||||
{
|
||||
if (IsUIStopInput) return;
|
||||
var actionName = context.action.name;
|
||||
if (actionName == "Op1")
|
||||
{
|
||||
OnOp1Action?.Invoke(false);
|
||||
}
|
||||
else if (actionName == "Op2")
|
||||
{
|
||||
OnOp2Action?.Invoke(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void OnInteractiveObject(InteractiveObject interactiveObject)
|
||||
{
|
||||
Debug.LogError($"OnInteractiveObject {interactiveObject != null}");
|
||||
OnInteractiveObjectAction?.Invoke(interactiveObject);
|
||||
}
|
||||
|
||||
private void OnRun(InputAction.CallbackContext context)
|
||||
{
|
||||
OnRunAction?.Invoke(context.performed);
|
||||
}
|
||||
|
||||
private void OnOp1(InputAction.CallbackContext context)
|
||||
{
|
||||
IsOp1 = context.performed;
|
||||
OnOp1Action?.Invoke(IsOp1);
|
||||
}
|
||||
|
||||
private void OnOp2(InputAction.CallbackContext context)
|
||||
{
|
||||
IsOp2 = context.performed;
|
||||
OnOp2Action?.Invoke(IsOp2);
|
||||
}
|
||||
|
||||
private void OnUse(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed)
|
||||
{
|
||||
OnUseAction?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUse2(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed)
|
||||
{
|
||||
OnUse2Action?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSelectItem(InputAction.CallbackContext context)
|
||||
{
|
||||
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