input相关

This commit is contained in:
2025-05-26 00:06:37 +08:00
parent 68b88d57db
commit 763fa5103f
23 changed files with 745 additions and 68 deletions

View File

@@ -1,165 +0,0 @@
using System;
using System.Runtime.InteropServices;
using NBC;
// 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;
/// <summary>
/// 执行输入事件
/// </summary>
public static event Action<string> OnUIPerformed;
/// <summary>
/// 执行输入事件完毕
/// </summary>
public static event Action<string> OnUICanceled;
/// <summary>
/// 执行输入事件
/// </summary>
public static event Action<string> OnPlayerPerformed;
/// <summary>
/// 执行输入事件完毕
/// </summary>
public static event Action<string> OnPlayerCanceled;
/// <summary>
/// 触发交互游戏对象
/// </summary>
public static event Action<InteractiveObject> OnInteractiveObjectAction;
public static PlayerInputControl PlayerInputControl { get; private set; }
/// <summary>
/// ui阻止游戏输入
/// </summary>
public static bool IsUIStopInput;
private void Awake()
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
public static Vector2 GetMovementInput()
{
if (IsUIStopInput) return Vector2.zero;
return PlayerInputControl.Player.Move?.ReadValue<Vector2>() ?? Vector2.zero;
}
public static Vector2 GetLookInput()
{
if (IsUIStopInput) return Vector2.zero;
return PlayerInputControl.Player.Look?.ReadValue<Vector2>() ?? Vector2.zero;
}
private void Start()
{
PlayerInputControl = new PlayerInputControl();
PlayerInputControl.Enable();
AddEvent();
}
private void OnDestroy()
{
RemoveEvent();
}
private void AddEvent()
{
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()
{
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);
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: fecc50928be248b896f6ee0a17e7b76d
timeCreated: 1746892722

View File

@@ -103,12 +103,12 @@ public class FHook : FPlayerGear
private void OnCollisionEnter(Collision collision)
{
if (!waterDisplacement.isInWater && (bool)Owner.Gears.Rod &&
(bool)Owner.Gears.Rod.lineHandler && !Owner.Gears.Rod.currentFish &&
Owner.Data.lineLength > 5f &&
Vector3.Distance(transform.position, Owner.Gears.Rod.transform.position) > 5f)
{
// GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("HOOK_ON_THE_GROUND"), FScriptsHandler.Instance.m_Canvas.transform, deleteLast: true);
}
// if (!waterDisplacement.isInWater && (bool)Owner.Gears.Rod &&
// (bool)Owner.Gears.Rod.lineHandler && !Owner.Gears.Rod.currentFish &&
// Owner.Data.lineLength > 5f &&
// Vector3.Distance(transform.position, Owner.Gears.Rod.transform.position) > 5f)
// {
// GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("HOOK_ON_THE_GROUND"), FScriptsHandler.Instance.m_Canvas.transform, deleteLast: true);
// }
}
}

View File

@@ -55,7 +55,7 @@ namespace NBF
transform.position = _player.Data.position;
transform.rotation = _player.Data.rotation;
App.Inst.SetMouseCurrsor(false);
InputManager.OnPlayerCanceled += OnPlayerCanceled;
InputManager.OnPlayerPerformed += OnPlayerPerformed;
// InputManager.OnRunAction += OnRunAction;
@@ -192,7 +192,7 @@ namespace NBF
{
// Move
Vector2 movementInput = InputManager.GetMovementInput();
Vector3 movementDirection = Vector3.zero;
movementDirection += Vector3.forward * movementInput.y;

View File

@@ -547,7 +547,7 @@ namespace NBF
""id"": ""c1f7a91b-d0fd-4a62-997e-7fb9b69bf235"",
""path"": ""<Gamepad>/rightStick"",
""interactions"": """",
""processors"": """",
""processors"": ""ScaleVector2(x=40,y=40)"",
""groups"": "";Gamepad"",
""action"": ""Look"",
""isComposite"": false,
@@ -1066,7 +1066,7 @@ namespace NBF
""id"": ""348bd961-a6a0-4d13-b414-83b43201bc10"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""interactions"": ""Hold"",
""initialStateCheck"": false
},
{
@@ -1075,7 +1075,7 @@ namespace NBF
""id"": ""da1344ed-a4b5-43ef-bad6-a3f6bb06ff23"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""interactions"": ""Hold"",
""initialStateCheck"": false
},
{
@@ -1084,7 +1084,7 @@ namespace NBF
""id"": ""dafd152b-aa0a-48bb-890d-289ab3a3e713"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""interactions"": ""Hold"",
""initialStateCheck"": false
},
{
@@ -1093,7 +1093,7 @@ namespace NBF
""id"": ""e0dbeebd-c69d-44bd-83de-94fcce8c6727"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""interactions"": ""Hold"",
""initialStateCheck"": false
},
{
@@ -1129,6 +1129,28 @@ namespace NBF
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""e834d5a6-95f1-4142-9da6-4cbcc8618342"",
""path"": ""<XInputController>/buttonEast"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Back"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""48a10b34-e3b4-4a90-98a2-95e128a3417a"",
""path"": ""<Gamepad>/buttonEast"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Back"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""a6e94404-e896-4fec-b3bf-affd31b12571"",
@@ -1140,6 +1162,17 @@ namespace NBF
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""7028032c-6c7f-4846-8d2c-a41c3c2822fd"",
""path"": ""<XInputController>/buttonEast"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Enter"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""23dac47b-935f-4261-8044-a8612edf3fda"",
@@ -1162,6 +1195,28 @@ namespace NBF
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""5e809757-a6a4-4f89-9256-619af1216748"",
""path"": ""<XInputController>/leftShoulder"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Prev"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""5a43b881-410f-4e67-913f-cbc379ae6953"",
""path"": ""<Gamepad>/leftShoulder"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Prev"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""2661bf5d-0afe-4f8c-a4e8-2aa6150c724d"",
@@ -1173,6 +1228,28 @@ namespace NBF
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""7250c0b2-9b1c-445e-8c8e-125dcf79e29f"",
""path"": ""<XInputController>/rightShoulder"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Next"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""9fa9e49d-5262-4890-8ba2-6c84695f88aa"",
""path"": ""<Gamepad>/rightShoulder"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Next"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""487ceb23-336d-45f6-a782-3b4e9d9f0cd1"",
@@ -1184,6 +1261,28 @@ namespace NBF
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""589ddbb5-aedc-483d-957c-1fd7c1a12002"",
""path"": ""<XInputController>/leftTrigger"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""SubPrev"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""0fe51227-7d8b-4baa-9d25-8396deefc34d"",
""path"": ""<Gamepad>/leftTrigger"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""SubPrev"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""463ec073-6e9d-4b1d-9956-8ec19838aa3e"",
@@ -1195,6 +1294,28 @@ namespace NBF
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""2c584e41-80cd-463e-8423-ac74c932c90b"",
""path"": ""<XInputController>/rightTrigger"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""SubNext"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""c8394c43-028f-4056-b5bd-f81395997f15"",
""path"": ""<Gamepad>/rightTrigger"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""SubNext"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""053ddbac-9f73-4672-be59-abfdb6037aea"",
@@ -1206,6 +1327,17 @@ namespace NBF
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""2e150513-8adf-4e87-b5c9-cab09870835e"",
""path"": ""<Gamepad>/leftStick/right"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Right"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""031b930d-59b6-4a26-9dfe-97764c3e8b37"",
@@ -1217,6 +1349,17 @@ namespace NBF
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""dced9424-e4e1-40d9-8aea-b69491365e74"",
""path"": ""<Gamepad>/leftStick/left"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Left"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""45f78626-cbf2-4e1f-904d-d82e4c2a2f41"",
@@ -1228,6 +1371,17 @@ namespace NBF
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""2e119597-8f21-4c82-916c-57ffcd0f34c5"",
""path"": ""<Gamepad>/leftStick/down"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Down"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""f1a47b3c-e79f-4ab3-86b6-fcc0a6470114"",
@@ -1239,6 +1393,17 @@ namespace NBF
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""9a43ed61-260a-4f92-9e49-3df421db4051"",
""path"": ""<Gamepad>/leftStick/up"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Up"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""393f1eb9-d10d-4cd1-87e7-ea299f92b2da"",