浏览代码
Added Direct Input Event, Fixes in Screenshot Manger / UIEventManager Prefab
/feature-new-input-system
Added Direct Input Event, Fixes in Screenshot Manger / UIEventManager Prefab
/feature-new-input-system
Thomas ICHÉ
4 年前
当前提交
2ae47452
共有 6 个文件被更改,包括 382 次插入 和 8 次删除
-
105Resources/Default_UIEventManager.prefab
-
183Runtime/Input/InputSystemManager.cs
-
2Runtime/LevelScripting/Events/OnKeyDownEvent.cs
-
11Runtime/Managers/Implementations/ScreenshotManager.cs
-
78Runtime/LevelScripting/Events/OnInputSystemDirectInputEvent.cs
-
11Runtime/LevelScripting/Events/OnInputSystemDirectInputEvent.cs.meta
|
|||
using GameplayIngredients.Managers; |
|||
using NaughtyAttributes; |
|||
using UnityEngine; |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
using UnityEngine.InputSystem; |
|||
using UnityEngine.InputSystem.Controls; |
|||
#endif
|
|||
|
|||
namespace GameplayIngredients.Events |
|||
{ |
|||
#if !ENABLE_INPUT_SYSTEM
|
|||
[WarnDisabledModule("New Input System")] |
|||
#endif
|
|||
public class OnInputSystemDirectInputEvent : EventBase |
|||
{ |
|||
[SerializeField] |
|||
Device device = Device.Keyboard; |
|||
[SerializeField, ShowIf("IsMouse")] |
|||
MouseButton mouseButton = MouseButton.Left; |
|||
[SerializeField, ShowIf("IsGamepad")] |
|||
GamepadButton gamepadButton = GamepadButton.A; |
|||
[SerializeField, ShowIf("IsKeyboard")] |
|||
Key keyboardKey = Key.Space; |
|||
|
|||
public Callable[] onPressed; |
|||
public Callable[] onReleased; |
|||
|
|||
bool IsMouse() => device == Device.Mouse; |
|||
bool IsGamepad() => device == Device.Gamepad; |
|||
bool IsKeyboard() => device == Device.Keyboard; |
|||
|
|||
ButtonControl button; |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
|
|||
private void OnEnable() |
|||
{ |
|||
button = GetButton(device); |
|||
Manager.Get<SingleUpdateManager>().Register(SingleUpdate); |
|||
} |
|||
|
|||
private void OnDisable() |
|||
{ |
|||
Manager.Get<SingleUpdateManager>().Remove(SingleUpdate); |
|||
} |
|||
|
|||
private void SingleUpdate() |
|||
{ |
|||
if (button == null) |
|||
return; |
|||
|
|||
if (button.wasPressedThisFrame) |
|||
Callable.Call(onPressed, null); |
|||
|
|||
if (button.wasReleasedThisFrame) |
|||
Callable.Call(onReleased, null); |
|||
} |
|||
ButtonControl GetButton(Device d) |
|||
{ |
|||
switch (d) |
|||
{ |
|||
case Device.Gamepad: |
|||
return InputSystemManager.GetButton(gamepadButton); |
|||
case Device.Keyboard: |
|||
return InputSystemManager.GetButton(keyboardKey); |
|||
case Device.Mouse: |
|||
return InputSystemManager.GetButton(mouseButton); |
|||
default: |
|||
throw new System.NotImplementedException(); |
|||
} |
|||
} |
|||
|
|||
#endif
|
|||
|
|||
|
|||
} |
|||
} |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 0c0fbeef9c1898b4db7f310ff70c014a |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue