输入组件
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"version": 1,
|
||||||
"name": "PlayerInputControl",
|
"name": "PlayerInputControl",
|
||||||
"maps": [
|
"maps": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,156 @@
|
|||||||
using NBC.Entitas;
|
using System;
|
||||||
|
using NBC.Entitas;
|
||||||
|
using NBC.Entitas.Interface;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
namespace NBF.Fishing2
|
namespace NBF.Fishing2
|
||||||
{
|
{
|
||||||
public class InputComponent : Entity
|
public class InputComponent : Entity
|
||||||
{
|
{
|
||||||
|
public PlayerInputControl PlayerInputControl { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行输入事件
|
||||||
|
/// </summary>
|
||||||
|
public event Action<string> OnUIPerformed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行输入事件完毕
|
||||||
|
/// </summary>
|
||||||
|
public event Action<string> OnUICanceled;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行输入事件
|
||||||
|
/// </summary>
|
||||||
|
public event Action<string> OnPlayerPerformed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行输入事件完毕
|
||||||
|
/// </summary>
|
||||||
|
public event Action<string> OnPlayerCanceled;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 手柄输入
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsControllerInput;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ui阻止游戏输入
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsUIStopInput;
|
||||||
|
|
||||||
|
public void OnUIButtonPerformed(InputAction.CallbackContext context)
|
||||||
|
{
|
||||||
|
OnUIPerformed?.Invoke(context.action.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnUIButtonCanceled(InputAction.CallbackContext context)
|
||||||
|
{
|
||||||
|
OnUICanceled?.Invoke(context.action.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public 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);
|
||||||
|
// }
|
||||||
|
|
||||||
|
OnPlayerPerformed?.Invoke(actionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public 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);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
OnPlayerCanceled?.Invoke(actionName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InputComponentSystem
|
||||||
|
{
|
||||||
|
public class InputComponentAwakeSystem : AwakeSystem<InputComponent>
|
||||||
|
{
|
||||||
|
protected override void Awake(InputComponent self)
|
||||||
|
{
|
||||||
|
self.PlayerInputControl = new PlayerInputControl();
|
||||||
|
self.PlayerInputControl.Enable();
|
||||||
|
|
||||||
|
foreach (var actionMap in self.PlayerInputControl.asset.actionMaps)
|
||||||
|
{
|
||||||
|
actionMap.Enable();
|
||||||
|
if (actionMap.name == "UI")
|
||||||
|
{
|
||||||
|
foreach (var action in actionMap.actions)
|
||||||
|
{
|
||||||
|
if (action.type == InputActionType.Button)
|
||||||
|
{
|
||||||
|
action.performed += self.OnUIButtonPerformed;
|
||||||
|
action.canceled += self.OnUIButtonCanceled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (actionMap.name == "Player")
|
||||||
|
{
|
||||||
|
foreach (var action in actionMap.actions)
|
||||||
|
{
|
||||||
|
if (action.type == InputActionType.Button)
|
||||||
|
{
|
||||||
|
action.performed += self.OnPlayerButtonPerformed;
|
||||||
|
action.canceled += self.OnPlayerButtonCanceled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class InputComponentDestroySystem : DestroySystem<InputComponent>
|
||||||
|
{
|
||||||
|
protected override void Destroy(InputComponent self)
|
||||||
|
{
|
||||||
|
foreach (var actionMap in self.PlayerInputControl.asset.actionMaps)
|
||||||
|
{
|
||||||
|
actionMap.Enable();
|
||||||
|
if (actionMap.name == "UI")
|
||||||
|
{
|
||||||
|
foreach (var action in actionMap.actions)
|
||||||
|
{
|
||||||
|
if (action.type == InputActionType.Button)
|
||||||
|
{
|
||||||
|
action.performed -= self.OnUIButtonPerformed;
|
||||||
|
action.canceled -= self.OnUIButtonCanceled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (actionMap.name == "Player")
|
||||||
|
{
|
||||||
|
foreach (var action in actionMap.actions)
|
||||||
|
{
|
||||||
|
if (action.type == InputActionType.Button)
|
||||||
|
{
|
||||||
|
action.performed -= self.OnPlayerButtonPerformed;
|
||||||
|
action.canceled -= self.OnPlayerButtonCanceled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using NBF.Fishing2;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace NBF
|
namespace NBF
|
||||||
@@ -7,15 +8,18 @@ namespace NBF
|
|||||||
{
|
{
|
||||||
public static Global Instance { get; private set; }
|
public static Global Instance { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
public static InputComponent Input;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 主摄像机
|
/// 主摄像机
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Camera MainCamera { get; private set; }
|
public static Camera MainCamera { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 摄像机配置
|
/// 摄像机配置
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CameraScriptObject CameraConfig { get; private set; }
|
public static CameraScriptObject CameraConfig { get; private set; }
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ namespace NBF
|
|||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
|
||||||
AddEvent();
|
AddEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ namespace NBF.Fishing2
|
|||||||
scene.AddComponent<ObjectWait>();
|
scene.AddComponent<ObjectWait>();
|
||||||
scene.AddComponent<MapManageComponent>();
|
scene.AddComponent<MapManageComponent>();
|
||||||
scene.AddComponent<CameraComponent>();
|
scene.AddComponent<CameraComponent>();
|
||||||
scene.AddComponent<InputComponent>();
|
var input = scene.AddComponent<InputComponent>();
|
||||||
scene.AddComponent<SettingComponent>();
|
scene.AddComponent<SettingComponent>();
|
||||||
|
|
||||||
|
Global.Input = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
await FTask.CompletedTask;
|
await FTask.CompletedTask;
|
||||||
|
|||||||
@@ -24,5 +24,5 @@ EditorBuildSettings:
|
|||||||
path: Assets/ResRaw/Maps/Map99/Map99.unity
|
path: Assets/ResRaw/Maps/Map99/Map99.unity
|
||||||
guid: 956b354d2875715418f574fcf501363e
|
guid: 956b354d2875715418f574fcf501363e
|
||||||
m_configObjects:
|
m_configObjects:
|
||||||
com.unity.input.settings.actions: {fileID: -944628639613478452, guid: d0e3cb5a99f3d324ea14bfe64485b2e4, type: 3}
|
com.unity.input.settings.actions: {fileID: -944628639613478452, guid: 8a314d59348c97b4e96e6eb9b09285a6, type: 3}
|
||||||
m_UseUCBPForAssetBundles: 0
|
m_UseUCBPForAssetBundles: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user