474 lines
16 KiB
C#
474 lines
16 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
// using Rewired;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace NBF
|
|
{
|
|
public class InputManager : MonoBehaviour
|
|
{
|
|
public static InputManager Instance { get; private set; }
|
|
|
|
public static bool IsOp1;
|
|
public static bool IsOp2;
|
|
|
|
|
|
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;
|
|
|
|
|
|
/// <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;
|
|
|
|
/// <summary>
|
|
/// 触发交互游戏对象
|
|
/// </summary>
|
|
public static event Action<InteractiveObject> OnInteractiveObjectAction;
|
|
|
|
public static PlayerInputControl PlayerInputControl { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
public static Vector2 GetMovementInput()
|
|
{
|
|
return PlayerInputControl.Normal.Move?.ReadValue<Vector2>() ?? Vector2.zero;
|
|
}
|
|
|
|
public static Vector2 GetLookInput()
|
|
{
|
|
return PlayerInputControl.Normal.Look?.ReadValue<Vector2>() ?? Vector2.zero;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
PlayerInputControl = new PlayerInputControl();
|
|
PlayerInputControl.Enable();
|
|
PlayerInputControl.Normal.Enable();
|
|
AddEvent();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
RemoveEvent();
|
|
}
|
|
|
|
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.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;
|
|
}
|
|
|
|
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.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;
|
|
}
|
|
|
|
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;
|
|
Debug.Log($"IsOp1={IsOp1}");
|
|
OnOp1Action?.Invoke(IsOp1);
|
|
}
|
|
|
|
private void OnOp2(InputAction.CallbackContext context)
|
|
{
|
|
IsOp2 = context.performed;
|
|
Debug.Log($"OnOp2={IsOp2}");
|
|
OnOp2Action?.Invoke(IsOp2);
|
|
}
|
|
|
|
private void OnUse(InputAction.CallbackContext context)
|
|
{
|
|
OnUseAction?.Invoke(context.performed);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |