浏览代码

Removed InputSystemManager, reworked actions. Start working on base behavior of UIEventManager

/feature-new-input-system
Thomas ICHÉ 4 年前
当前提交
6d421d01
共有 17 个文件被更改,包括 259 次插入620 次删除
  1. 99
      Resources/Default_UIEventManager.prefab
  2. 8
      Runtime/LevelScripting/Actions/FocusUIAction.cs
  3. 10
      Runtime/LevelScripting/Events/OnInputDirectEvent.cs
  4. 2
      Runtime/Managers/Implementations/ScreenshotManager.cs
  5. 37
      Runtime/Managers/Implementations/UIEventManager.cs
  6. 196
      Runtime/Input/InputSystemUtility.cs
  7. 20
      Runtime/LevelScripting/Events/OnInputActionEvent.cs
  8. 11
      Editor/PropertyDrawers/RegisteredInputActionsPropertyDrawer.cs.meta
  9. 167
      Editor/PropertyDrawers/RegisteredInputActionsPropertyDrawer.cs
  10. 46
      Resources/Default_InputSystemManager.prefab
  11. 7
      Resources/Default_InputSystemManager.prefab.meta
  12. 256
      Runtime/Input/InputSystemManager.cs
  13. 20
      Runtime/LevelScripting/Events/OnInputEvent.cs
  14. 0
      /Runtime/Input/InputSystemUtility.cs.meta
  15. 0
      /Runtime/LevelScripting/Events/OnInputDirectEvent.cs.meta
  16. 0
      /Runtime/LevelScripting/Events/OnInputActionEvent.cs.meta
  17. 0
      /Runtime/LevelScripting/Events/OnInputDirectEvent.cs

99
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_Layer: 0
m_Name: Default_UIEventManager
m_TagString: Untagged

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
--- !u!114 &6448262098318784319
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

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_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: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:

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

8
Runtime/LevelScripting/Actions/FocusUIAction.cs


public override void Execute(GameObject instigator = null)
{
if (UIObjectToFocus != null)
{
// Workaround : Before selecting, we ensure that there's no selection in the EventSystem
Manager.Get<UIEventManager>().eventSystem.SetSelectedGameObject(null);
UIObjectToFocus.Select();
}
Manager.Get<UIEventManager>().FocusUI(UIObjectToFocus);
public override string GetDefaultName()
{
return $"Focus UI : '{UIObjectToFocus?.name}'";

10
Runtime/LevelScripting/Events/OnInputDirectEvent.cs


#if !ENABLE_INPUT_SYSTEM
[WarnDisabledModule("New Input System")]
#endif
[AddComponentMenu(ComponentMenu.eventsPath + "On Direct Input Event (New Input System)")]
public class OnDirectInputEvent : EventBase
[AddComponentMenu(ComponentMenu.eventsPath + "On Input Direct Event (New Input System)")]
public class OnInputDirectEvent : EventBase
{
[SerializeField]
Device device = Device.Keyboard;

switch (d)
{
case Device.Gamepad:
return InputSystemManager.GetButton(gamepadButton);
return InputSystemUtility.GetButton(gamepadButton);
return InputSystemManager.GetButton(keyboardKey);
return InputSystemUtility.GetButton(keyboardKey);
return InputSystemManager.GetButton(mouseButton);
return InputSystemUtility.GetButton(mouseButton);
default:
throw new System.NotImplementedException();
}

2
Runtime/Managers/Implementations/ScreenshotManager.cs


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

37
Runtime/Managers/Implementations/UIEventManager.cs


using NaughtyAttributes;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.UI;
using UnityEngine.UI;
#endif
#if ENABLE_LEGACY_INPUT_MANAGER
#endif
#if ENABLE_INPUT_SYSTEM
[RequireComponent(typeof(InputSystemUIInputModule))]
#endif
public EventSystem eventSystem { get { return m_EventSystem; } }
[SerializeField]
private EventSystem m_EventSystem;

if (TryGetComponent(out StandaloneInputModule im))
#if !ENABLE_LEGACY_INPUT_MANAGER
im.enabled = false;
#else
im.enabled = true;
#endif
#if ENABLE_INPUT_SYSTEM
if (!TryGetComponent(out InputSystemUIInputModule ism))
Debug.LogWarning("You are using the new Input System but the UI Event Manager prefab is not configured to use input from this package. In order to fix the issue, please add and configure a InputSystemUIInputModule component to your Assets/Resources/UIEventManagerPrefab. If the prefab is not present, use the Gameplay Ingredients Wizard located at Window/Gameplay Ingredients/Setup Wizard");
#endif
}
}
public void FocusUI(Selectable selectable)
{
// Before selecting, we ensure that there's no selection in the EventSystem
m_EventSystem.SetSelectedGameObject(null);
if(selectable != null)
selectable.Select();
}
}
}

196
Runtime/Input/InputSystemUtility.cs


using System;
using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
namespace GameplayIngredients
{
public static class InputSystemUtility
{
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();
}
}
#endif
}
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,
}
}

20
Runtime/LevelScripting/Events/OnInputActionEvent.cs


using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace GameplayIngredients.Events
{
#if !ENABLE_INPUT_SYSTEM
[WarnDisabledModule("New Input System")]
#endif
[AddComponentMenu(ComponentMenu.eventsPath + "On Input Action Event (New Input System)")]
public class OnInputActionEvent : EventBase
{
#if ENABLE_INPUT_SYSTEM
public InputAction inputAction;
#endif
}
}

11
Editor/PropertyDrawers/RegisteredInputActionsPropertyDrawer.cs.meta


fileFormatVersion: 2
guid: c8ac85428885ec74f9a693cbb82c9f92
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

167
Editor/PropertyDrawers/RegisteredInputActionsPropertyDrawer.cs


using GameplayIngredients.Managers;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
namespace GameplayIngredients.Editor
{
[CustomPropertyDrawer(typeof(InputSystemManager.RegisteredInputAction))]
public class RegisteredInputActionsPropertyDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (GameplayIngredientsSettings.currentSettings.excludedeManagers.Contains(nameof(InputSystemManager)))
return EditorGUIUtility.singleLineHeight * 2.5f;
else
{
return 2 * base.GetPropertyHeight(property, label);
}
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
#if ENABLE_INPUT_SYSTEM
if (GameplayIngredientsSettings.currentSettings.excludedeManagers.Contains(typeof(InputSystemManager).Name))
{
EditorGUI.HelpBox(position, "Cannot check for Input Actions : \nInputSystemManager is excluded in your Assets/Resources/GameplayIngredientsSettings.asset", MessageType.Error);
return;
}
InputSystemManager ism = GetDefaultInputSystemManager();
if(ism == null)
{
GUI.color = Color.red;
EditorGUI.LabelField(position,"Error while getting the InputSystemManager prefab", EditorStyles.boldLabel);
GUI.color = Color.white;
return;
}
position.height = EditorGUIUtility.singleLineHeight;
int length = 1 + ism.inputActions.Length;
GUIContent[] displayedOptions = new GUIContent[length];
int[] optionValues = new int[length];
for(int i = 0; i<length; i++)
{
if (i == 0)
displayedOptions[i] = Contents.noPreset;
else
{
var action = ism.inputActions[i - 1].inputActionAsset;
displayedOptions[i] = action? new GUIContent(action.name) : Contents.nullEntry ;
}
optionValues[i] = i - 1;
}
int value = -1;
if(ism.inputActions.Any(o => o.inputActionAsset == GetInputAsset(property) ))
{
for(int i = 0; i < ism.inputActions.Length; i++)
{
if (ism.inputActions[i].inputActionAsset != null && ism.inputActions[i].inputActionAsset == property.FindPropertyRelative("asset").objectReferenceValue)
{
value = i;
break;
}
}
}
value = EditorGUI.IntPopup(position, Contents.preset, value, displayedOptions, optionValues);
if(GUI.changed)
{
if (value == -1)
property.FindPropertyRelative("asset").objectReferenceValue = null;
else
property.FindPropertyRelative("asset").objectReferenceValue = ism.inputActions[value].inputActionAsset;
}
position.yMin += EditorGUIUtility.singleLineHeight;
position.height = EditorGUIUtility.singleLineHeight;
if (GetInputAsset(property) != null)
{
InputActionAsset ia = property.FindPropertyRelative("asset").objectReferenceValue as InputActionAsset;
List<string> items = new List<string>();
foreach(var actionMap in ia.actionMaps)
{
foreach(var action in actionMap.actions)
{
items.Add($"{actionMap.name}/{action.name}");
}
}
string val = property.FindPropertyRelative("actionPath").stringValue;
int selected = -1;
GUIContent[] names = new GUIContent[items.Count];
int[] indices = new int[items.Count];
for(int i = 0; i < items.Count; i++)
{
names[i] = new GUIContent(items[i]);
indices[i] = i;
if (val == items[i])
selected = i;
}
selected = EditorGUI.IntPopup(position, new GUIContent(" - Action"), selected, names, indices);
if(GUI.changed)
{
property.FindPropertyRelative("actionPath").stringValue = items[selected];
}
}
#else
EditorGUI.HelpBox(position, "New Input System package is not installed", MessageType.Warning);
#endif
}
static InputAction GetAction(SerializedProperty property)
{
var inputAsset = GetInputAsset(property);
string path = property.FindPropertyRelative("actionPath").stringValue;
return InputSystemManager.RegisteredInputAction.GetAtPath(inputAsset, path);
}
static InputActionAsset GetInputAsset(SerializedProperty property)
{
return property.FindPropertyRelative("asset").objectReferenceValue as InputActionAsset;
}
InputSystemManager GetDefaultInputSystemManager()
{
string prefabName = typeof(InputSystemManager).GetCustomAttribute<ManagerDefaultPrefabAttribute>().prefab;
GameObject prefab = Resources.Load<GameObject>(prefabName);
if(prefab != null && prefab.TryGetComponent(out InputSystemManager ism))
{
return ism;
}
prefab = Resources.Load<GameObject>("Default_" + prefabName);
if (prefab != null && prefab.TryGetComponent(out InputSystemManager ism2))
{
return ism2;
}
return null;
}
static class Contents
{
public static GUIContent preset = new GUIContent("Preset", "Preset as defined in your InputSystemManager");
public static GUIContent noPreset = new GUIContent("(No Preset)");
public static GUIContent nullEntry = new GUIContent("Null Entry defined in InputSystemManager");
}
}
}

46
Resources/Default_InputSystemManager.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &9173868411675018652
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1529753585102584546}
- component: {fileID: -2206566852769537897}
m_Layer: 0
m_Name: Default_InputSystemManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1529753585102584546
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9173868411675018652}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &-2206566852769537897
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9173868411675018652}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 44bbe53f07c77d14da3555d7d06ba904, type: 3}
m_Name:
m_EditorClassIdentifier:
m_InputActions: []

7
Resources/Default_InputSystemManager.prefab.meta


fileFormatVersion: 2
guid: 63a0d71fc5ba40644b03c49f0e64a0a9
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

256
Runtime/Input/InputSystemManager.cs


using System;
using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
#endif
namespace GameplayIngredients.Managers
{
#if !ENABLE_INPUT_SYSTEM
[DoNotCreateManager]
[WarnDisabledModule("New Input System","Player Settings")]
#endif
[AddComponentMenu(ComponentMenu.managersPath + "Input System Manager (New Input System)")]
[ManagerDefaultPrefab("InputSystemManager")]
public class InputSystemManager : Manager
{
#if ENABLE_INPUT_SYSTEM
public InputActionDefinition[] inputActions { get => m_InputActions; }
[SerializeField]
InputActionDefinition[] m_InputActions;
[Serializable]
public struct InputActionDefinition
{
public InputActionAsset inputActionAsset;
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();
}
}
[System.Serializable]
public struct RegisteredInputAction
{
public InputActionAsset asset;
public string actionPath;
public InputAction action => GetAtPath(this.asset, this.actionPath);
public static InputAction GetAtPath(InputActionAsset asset, string path)
{
if (asset == null)
return null;
if (string.IsNullOrEmpty(path))
return null;
string[] split = path.Split('/');
foreach(var map in asset.actionMaps)
{
if (!map.name.Equals(split[0]))
continue;
foreach(var action in map.actions)
{
if (action.name.Equals(split[1]))
return action;
}
}
return null;
}
}
#endif
}
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,
}
}

20
Runtime/LevelScripting/Events/OnInputEvent.cs


using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using GameplayIngredients.Managers;
#endif
namespace GameplayIngredients.Events
{
#if !ENABLE_INPUT_SYSTEM
[WarnDisabledModule("New Input System")]
#endif
[AddComponentMenu(ComponentMenu.eventsPath + "On Input Event (New Input System)")]
public class OnInputEvent : EventBase
{
#if ENABLE_INPUT_SYSTEM
public InputSystemManager.RegisteredInputAction inputAction;
#endif
}
}

/Runtime/Input/InputSystemManager.cs.meta → /Runtime/Input/InputSystemUtility.cs.meta

/Runtime/LevelScripting/Events/OnDirectInputEvent.cs.meta → /Runtime/LevelScripting/Events/OnInputDirectEvent.cs.meta

/Runtime/LevelScripting/Events/OnInputEvent.cs.meta → /Runtime/LevelScripting/Events/OnInputActionEvent.cs.meta

/Runtime/LevelScripting/Events/OnDirectInputEvent.cs → /Runtime/LevelScripting/Events/OnInputDirectEvent.cs

正在加载...
取消
保存