浏览代码

Added Direct Input Event, Fixes in Screenshot Manger / UIEventManager Prefab

/feature-new-input-system
Thomas ICHÉ 4 年前
当前提交
2ae47452
共有 6 个文件被更改,包括 382 次插入8 次删除
  1. 105
      Resources/Default_UIEventManager.prefab
  2. 183
      Runtime/Input/InputSystemManager.cs
  3. 2
      Runtime/LevelScripting/Events/OnKeyDownEvent.cs
  4. 11
      Runtime/Managers/Implementations/ScreenshotManager.cs
  5. 78
      Runtime/LevelScripting/Events/OnInputSystemDirectInputEvent.cs
  6. 11
      Runtime/LevelScripting/Events/OnInputSystemDirectInputEvent.cs.meta

105
Resources/Default_UIEventManager.prefab


- component: {fileID: 6448262098318784312}
- component: {fileID: 6448262098318784313}
- component: {fileID: 6448262098318784318}
- component: {fileID: 3503333848817670599}
- component: {fileID: 1487830702371190246}
- component: {fileID: 3510890780544069616}
- component: {fileID: 9185997359459746325}
- component: {fileID: 9014956111711983296}
m_Name: UIEventManager
m_Name: Default_UIEventManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_GameObject: {fileID: 6448262098318784316}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -619905303, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}

m_Name:
m_EditorClassIdentifier:
m_EventSystem: {fileID: 6448262098318784313}
--- !u!114 &3503333848817670599
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6448262098318784316}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 718c1945292acbd4497cd28bcaa94f8d, type: 3}
m_Name:
m_EditorClassIdentifier:
OnStart:
- {fileID: 1487830702371190246}
--- !u!114 &1487830702371190246
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6448262098318784316}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a579c054a1017f84e9e093fad80ad6cb, type: 3}
m_Name:
m_EditorClassIdentifier:
Name: Check Input Logic
OnLegacyInputPresent:
- {fileID: 3510890780544069616}
OnLegacyInputNotPresent: []
OnNewInputPresent:
- {fileID: 9185997359459746325}
OnNewInputNotPresent: []
--- !u!114 &3510890780544069616
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6448262098318784316}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 756d008da58a19e4dbc02fa1e3c84852, type: 3}
m_Name:
m_EditorClassIdentifier:
Name: 'Enable Legacy Standalone Input '
Targets:
- Behaviour: {fileID: 6448262098318784319}
State: 1
--- !u!114 &6448262098318784319
MonoBehaviour:
m_ObjectHideFlags: 0

m_GameObject: {fileID: 6448262098318784316}
m_Enabled: 1
m_Enabled: 0
m_Script: {fileID: 1077351063, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal

m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 1
--- !u!114 &9185997359459746325
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6448262098318784316}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 756d008da58a19e4dbc02fa1e3c84852, type: 3}
m_Name:
m_EditorClassIdentifier:
Name: 'Enable New Standalone Input '
Targets:
- Behaviour: {fileID: 9014956111711983296}
State: 1
--- !u!114 &9014956111711983296
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6448262098318784316}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 01614664b831546d2ae94a42149d80ac, type: 3}
m_Name:
m_EditorClassIdentifier:
m_MoveRepeatDelay: 0.5
m_MoveRepeatRate: 0.1
m_ActionsAsset: {fileID: -944628639613478452, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
m_PointAction: {fileID: 1054132383583890850, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
m_MoveAction: {fileID: 3710738434707379630, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
m_SubmitAction: {fileID: 2064916234097673511, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
m_CancelAction: {fileID: -1967631576421560919, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
m_LeftClickAction: {fileID: 8056856818456041789, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
m_MiddleClickAction: {fileID: 3279352641294131588, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
m_RightClickAction: {fileID: 3837173908680883260, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
m_ScrollWheelAction: {fileID: 4502412055082496612, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
m_TrackedDevicePositionAction: {fileID: 4754684134866288074, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
m_TrackedDeviceOrientationAction: {fileID: 1025543830046995696, guid: ca9f5fa95ffab41fb9a615ab714db018, type: 3}
m_DeselectOnBackgroundClick: 1
m_PointerBehavior: 0

183
Runtime/Input/InputSystemManager.cs


using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
#endif
namespace GameplayIngredients.Managers

[ManagerDefaultPrefab("InputSystemManager")]
public class InputSystemManager : Manager
{
#if ENABLE_INPUT_SYSTEM
#if ENABLE_INPUT_SYSTEM
public InputActionDefinition[] inputActions { get => m_InputActions; }
[SerializeField]

public bool createUIActions;
}
public static ButtonControl GetButton(MouseButton b)
{
Mouse m = Mouse.current;
switch (b)
{
case MouseButton.Left: return m.leftButton;
case MouseButton.Right: return m.rightButton;
case MouseButton.Middle: return m.middleButton;
case MouseButton.Back: return m.backButton;
case MouseButton.Forward: return m.forwardButton;
default:
throw new System.NotImplementedException();
}
}
public static ButtonControl GetButton(GamepadButton b)
{
Gamepad p = Gamepad.current;
switch (b)
{
case GamepadButton.A: return p.aButton;
case GamepadButton.B: return p.bButton;
case GamepadButton.X: return p.xButton;
case GamepadButton.Y: return p.yButton;
case GamepadButton.LeftShoulder: return p.leftShoulder;
case GamepadButton.LeftTrigger: return p.leftTrigger;
case GamepadButton.RightShoulder: return p.rightShoulder;
case GamepadButton.RightTrigger: return p.rightTrigger;
case GamepadButton.LeftThumbStick: return p.leftStickButton;
case GamepadButton.RightThumbStick: return p.rightStickButton;
case GamepadButton.Start: return p.startButton;
case GamepadButton.Select: return p.selectButton;
default:
throw new System.NotImplementedException();
}
}
public static ButtonControl GetButton(Key k)
{
Keyboard kb = Keyboard.current;
switch (k)
{
case Key.Space: return kb.spaceKey;
case Key.Enter: return kb.enterKey;
case Key.Tab: return kb.tabKey;
case Key.Backquote: return kb.backquoteKey;
case Key.Quote: return kb.quoteKey;
case Key.Semicolon: return kb.semicolonKey;
case Key.Comma: return kb.commaKey;
case Key.Period: return kb.periodKey;
case Key.Slash: return kb.slashKey;
case Key.Backslash: return kb.backslashKey;
case Key.LeftBracket: return kb.leftBracketKey;
case Key.RightBracket: return kb.rightBracketKey;
case Key.Minus: return kb.minusKey;
case Key.Equals: return kb.equalsKey;
case Key.A: return kb.aKey;
case Key.B: return kb.bKey;
case Key.C: return kb.cKey;
case Key.D: return kb.dKey;
case Key.E: return kb.eKey;
case Key.F: return kb.fKey;
case Key.G: return kb.gKey;
case Key.H: return kb.hKey;
case Key.I: return kb.iKey;
case Key.J: return kb.jKey;
case Key.K: return kb.kKey;
case Key.L: return kb.lKey;
case Key.M: return kb.mKey;
case Key.N: return kb.nKey;
case Key.O: return kb.oKey;
case Key.P: return kb.pKey;
case Key.Q: return kb.qKey;
case Key.R: return kb.rKey;
case Key.S: return kb.sKey;
case Key.T: return kb.tKey;
case Key.U: return kb.uKey;
case Key.V: return kb.vKey;
case Key.W: return kb.wKey;
case Key.X: return kb.xKey;
case Key.Y: return kb.yKey;
case Key.Z: return kb.zKey;
case Key.Digit1: return kb.digit1Key;
case Key.Digit2: return kb.digit2Key;
case Key.Digit3: return kb.digit3Key;
case Key.Digit4: return kb.digit4Key;
case Key.Digit5: return kb.digit5Key;
case Key.Digit6: return kb.digit6Key;
case Key.Digit7: return kb.digit7Key;
case Key.Digit8: return kb.digit8Key;
case Key.Digit9: return kb.digit9Key;
case Key.Digit0: return kb.digit0Key;
case Key.LeftShift: return kb.leftShiftKey;
case Key.RightShift: return kb.rightShiftKey;
case Key.LeftAlt: return kb.leftAltKey;
case Key.RightAlt: return kb.rightAltKey;
case Key.LeftCtrl: return kb.leftCtrlKey;
case Key.RightCtrl: return kb.rightCtrlKey;
case Key.LeftMeta: return kb.leftMetaKey;
case Key.RightMeta: return kb.rightMetaKey;
case Key.ContextMenu: return kb.contextMenuKey;
case Key.Escape: return kb.escapeKey;
case Key.LeftArrow: return kb.leftArrowKey;
case Key.RightArrow: return kb.rightArrowKey;
case Key.UpArrow: return kb.upArrowKey;
case Key.DownArrow: return kb.downArrowKey;
case Key.Backspace: return kb.backspaceKey;
case Key.PageDown: return kb.pageDownKey;
case Key.PageUp: return kb.pageUpKey;
case Key.Home: return kb.homeKey;
case Key.End: return kb.endKey;
case Key.Insert: return kb.insertKey;
case Key.Delete: return kb.deleteKey;
case Key.CapsLock: return kb.capsLockKey;
case Key.NumLock: return kb.numLockKey;
case Key.PrintScreen: return kb.printScreenKey;
case Key.ScrollLock: return kb.scrollLockKey;
case Key.Pause: return kb.pauseKey;
case Key.NumpadEnter: return kb.numpadEnterKey;
case Key.NumpadDivide: return kb.numpadDivideKey;
case Key.NumpadMultiply: return kb.numpadMultiplyKey;
case Key.NumpadPlus: return kb.numpadPlusKey;
case Key.NumpadMinus: return kb.numpadMinusKey;
case Key.NumpadPeriod: return kb.numpadPeriodKey;
case Key.NumpadEquals: return kb.equalsKey;
case Key.Numpad0: return kb.numpad0Key;
case Key.Numpad1: return kb.numpad1Key;
case Key.Numpad2: return kb.numpad2Key;
case Key.Numpad3: return kb.numpad3Key;
case Key.Numpad4: return kb.numpad4Key;
case Key.Numpad5: return kb.numpad5Key;
case Key.Numpad6: return kb.numpad6Key;
case Key.Numpad7: return kb.numpad7Key;
case Key.Numpad8: return kb.numpad8Key;
case Key.Numpad9: return kb.numpad9Key;
case Key.F1: return kb.f1Key;
case Key.F2: return kb.f2Key;
case Key.F3: return kb.f3Key;
case Key.F4: return kb.f4Key;
case Key.F5: return kb.f5Key;
case Key.F6: return kb.f6Key;
case Key.F7: return kb.f7Key;
case Key.F8: return kb.f8Key;
case Key.F9: return kb.f9Key;
case Key.F10: return kb.f10Key;
case Key.F11: return kb.f11Key;
case Key.F12: return kb.f12Key;
case Key.OEM1: return kb.oem1Key;
case Key.OEM2: return kb.oem2Key;
case Key.OEM3: return kb.oem3Key;
case Key.OEM4: return kb.oem4Key;
case Key.OEM5: return kb.oem5Key;
case Key.IMESelected: return kb.imeSelected;
default:
throw new System.NotImplementedException();
}
}
}
public enum Device
{
Gamepad,
Keyboard,
Mouse
}
public enum MouseButton
{
Left,
Right,
Middle,
Back,
Forward
}
public enum GamepadButton
{
A, B, X, Y,
LeftShoulder, LeftTrigger, RightShoulder, RightTrigger,
LeftThumbStick, RightThumbStick,
Start, Select,
}
}

2
Runtime/LevelScripting/Events/OnKeyDownEvent.cs


public Callable[] OnKeyDown;
public Callable[] OnKeyUp;
#if !ENABLE_LEGACY_INPUT_MANAGER
#if ENABLE_LEGACY_INPUT_MANAGER
void Update()
{

11
Runtime/Managers/Implementations/ScreenshotManager.cs


using GameplayIngredients.Managers;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace GameplayIngredients
{
#if !MODULE_SCREENCAPTURE

#if ENABLE_LEGACY_INPUT_MANAGER
public KeyCode ScreenshotKeyCode = KeyCode.F11;
#endif
#if ENABLE_INPUT_SYSTEM
public Key ScreenshotKey = Key.F11;
#endif
[Range(1, 5)]
public int SuperSize = 1;

#if ENABLE_LEGACY_INPUT_MANAGER
if (Input.GetKeyDown(ScreenshotKeyCode))
#elif ENABLE_INPUT_SYSTEM
if (true)
if (InputSystemManager.GetButton(ScreenshotKey).wasPressedThisFrame)
#else
if(false)
#endif

78
Runtime/LevelScripting/Events/OnInputSystemDirectInputEvent.cs


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
}
}

11
Runtime/LevelScripting/Events/OnInputSystemDirectInputEvent.cs.meta


fileFormatVersion: 2
guid: 0c0fbeef9c1898b4db7f310ff70c014a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存