浏览代码
New InputSystem package support. (#50)
New InputSystem package support. (#50)
* Base Work * Added RegiteredInputActions Selector * Added Direct Input Event, Fixes in Screenshot Manger / UIEventManager Prefab * Action Mapping from Input System Manager * Removed InputSystemManager, reworked actions. Start working on base behavior of UIEventManager * Added Warnings to UI Event Manager editor * Added UIEventManager page in the wizard * Added entry for startup wizard * Fixes when New Input System is not present * OnPlayerInputAction * Factorized Various Input Events (Direct, InputAction, InputAssetAction) * Factorized Player Input for both systems * Removed InputActionReference PropertyAttribute / Added OnPlayerInputActionEvent * Cleanup/Rename * Updated Changelog * Property Drawer for InputPlayerAction * Fix Package.json * Input Player Action property drawer/main
GitHub
4 年前
当前提交
34ee154f
共有 47 个文件被更改,包括 1235 次插入 和 38 次删除
-
14CHANGELOG.md
-
2Editor/CustomInspectors/PingableEditor.cs
-
3Editor/GameplayIngredients-Editor.asmdef
-
25Editor/WelcomeScreen/WelcomeScreen.Setup.cs
-
7Editor/WelcomeScreen/WelcomeScreen.cs
-
6Resources/Default_UIEventManager.prefab
-
4Runtime/Attributes/WarnDisabledModuleAttribute.cs
-
4Runtime/Controllers/KeyboardGamepadPlayerInput.cs
-
36Runtime/Controllers/PlayerInput.cs
-
98Runtime/Controllers/SimplePlayerInput.cs
-
3Runtime/GameplayIngredients.asmdef
-
1Runtime/GameplayIngredients.cs
-
1Runtime/LevelScripting/Actions/CinemachineCameraShakeAction.cs
-
2Runtime/LevelScripting/Actions/CinemachineSetCameraNoiseAction.cs
-
1Runtime/LevelScripting/Actions/CinemachineSetCustomBlendsAction.cs
-
8Runtime/LevelScripting/Actions/FocusUIAction.cs
-
7Runtime/LevelScripting/Events/OnButtonDownEvent.cs
-
8Runtime/LevelScripting/Events/OnKeyDownEvent.cs
-
17Runtime/Managers/Implementations/ScreenshotManager.cs
-
55Runtime/Managers/Implementations/UIEventManager.cs
-
19Runtime/Managers/Manager.cs
-
54Editor/CustomInspectors/UIEventManagerEditor.cs
-
11Editor/CustomInspectors/UIEventManagerEditor.cs.meta
-
76Editor/PropertyDrawers/InputAssetActionPropertyDrawer.cs
-
11Editor/PropertyDrawers/InputAssetActionPropertyDrawer.cs.meta
-
64Editor/PropertyDrawers/InputPlayerActionPropertyDrawer.cs
-
11Editor/PropertyDrawers/InputPlayerActionPropertyDrawer.cs.meta
-
2Runtime/AssemblyInfo.cs
-
11Runtime/AssemblyInfo.cs.meta
-
8Runtime/Input.meta
-
37Runtime/LevelScripting/Events/OnInputActionEvent.cs
-
11Runtime/LevelScripting/Events/OnInputActionEvent.cs.meta
-
91Runtime/LevelScripting/Events/OnInputAssetActionEvent.cs
-
11Runtime/LevelScripting/Events/OnInputAssetActionEvent.cs.meta
-
81Runtime/LevelScripting/Events/OnInputDirectEvent.cs
-
11Runtime/LevelScripting/Events/OnInputDirectEvent.cs.meta
-
91Runtime/LevelScripting/Events/OnPlayerInputActionEvent.cs
-
11Runtime/LevelScripting/Events/OnPlayerInputActionEvent.cs.meta
-
37Runtime/LevelScripting/Logic/InputSystemLogic.cs
-
11Runtime/LevelScripting/Logic/InputSystemLogic.cs.meta
-
7Runtime/Managers/DoNotCreateManagerAttribute.cs
-
11Runtime/Managers/DoNotCreateManagerAttribute.cs.meta
-
74Runtime/Input/InputActionManager.cs
-
11Runtime/Input/InputActionManager.cs.meta
-
198Runtime/Input/InputSystemUtility.cs
-
11Runtime/Input/InputSystemUtility.cs.meta
|
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
|
|||
namespace GameplayIngredients.Editor |
|||
{ |
|||
[CustomEditor(typeof(UIEventManager), true)] |
|||
public class UIEventManagerEditor : ManagerEditor |
|||
{ |
|||
public override void OnInspectorGUI_PingArea() |
|||
{ |
|||
base.OnInspectorGUI_PingArea(); |
|||
|
|||
#if ENABLE_INPUT_SYSTEM
|
|||
if(!(serializedObject.targetObject as UIEventManager).gameObject.TryGetComponent(out UnityEngine.InputSystem.UI.InputSystemUIInputModule issim)) |
|||
{ |
|||
using(new EditorGUI.IndentLevelScope(1)) |
|||
{ |
|||
EditorGUILayout.Space(); |
|||
EditorGUILayout.LabelField("Bad Configuration : New Input System Standalone Input", EditorStyles.boldLabel); |
|||
using (new EditorGUILayout.HorizontalScope()) |
|||
{ |
|||
EditorGUILayout.HelpBox("You are using the new Input System, but the current game object is missing a InputSystemUIInputModule", MessageType.Warning); |
|||
if (GUILayout.Button("Fix", GUILayout.ExpandHeight(true), GUILayout.Width(80))) |
|||
{ |
|||
(serializedObject.targetObject as UIEventManager).gameObject.AddComponent<UnityEngine.InputSystem.UI.InputSystemUIInputModule>(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|||
|
|||
#if !ENABLE_LEGACY_INPUT_MANAGER
|
|||
if ((serializedObject.targetObject as UIEventManager).gameObject.TryGetComponent(out UnityEngine.EventSystems.StandaloneInputModule sim)) |
|||
{ |
|||
using (new EditorGUI.IndentLevelScope(1)) |
|||
{ |
|||
EditorGUILayout.Space(); |
|||
EditorGUILayout.LabelField("Bad Configuration : Legacy Input System", EditorStyles.boldLabel); |
|||
using (new EditorGUILayout.HorizontalScope()) |
|||
{ |
|||
EditorGUILayout.HelpBox("You are not using the Legacy Input System, but the current game object is hosting a StandaloneInputModule", MessageType.Warning); |
|||
if (GUILayout.Button("Remove", GUILayout.ExpandHeight(true), GUILayout.Width(80))) |
|||
{ |
|||
DestroyImmediate((serializedObject.targetObject as UIEventManager).gameObject.GetComponent<UnityEngine.EventSystems.StandaloneInputModule>()); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
static readonly Color color = new Color(.8f, .6f, .1f, 1f); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ae3d7937d49de9d43ac7d52cc9728c22 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#if ENABLE_INPUT_SYSTEM
|
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEngine.InputSystem; |
|||
using System.Linq; |
|||
using System.Collections.Generic; |
|||
using GameplayIngredients.Events; |
|||
|
|||
namespace GameplayIngredients.Editor |
|||
{ |
|||
[CustomPropertyDrawer(typeof(InputAssetAction))] |
|||
public class InputAssetActionPropertyDrawer: PropertyDrawer |
|||
{ |
|||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight * 2 + 8; |
|||
} |
|||
|
|||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) |
|||
{ |
|||
var asset = property.FindPropertyRelative("asset"); |
|||
var path = property.FindPropertyRelative("path"); |
|||
|
|||
position.height = EditorGUIUtility.singleLineHeight; |
|||
EditorGUI.PropertyField(position, asset, new GUIContent("Input Action Asset")); |
|||
EditorGUI.indentLevel++; |
|||
position.y += EditorGUIUtility.singleLineHeight + 2; |
|||
|
|||
var paths = GetPaths(asset.objectReferenceValue as InputActionAsset); |
|||
int selected = paths.IndexOf(path.stringValue); |
|||
selected = EditorGUI.Popup(position, "Action", selected, paths); |
|||
if(GUI.changed) |
|||
{ |
|||
if (selected >= 0) |
|||
path.stringValue = paths[selected]; |
|||
else |
|||
path.stringValue = string.Empty; |
|||
} |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
string[] GetPaths(InputActionAsset asset) |
|||
{ |
|||
if (asset == null) |
|||
return new string[0]; |
|||
|
|||
List<string> paths = new List<string>(); |
|||
|
|||
foreach(var map in asset.actionMaps) |
|||
{ |
|||
if (map == null) continue; |
|||
foreach(var action in map.actions) |
|||
{ |
|||
if (action == null) continue; |
|||
|
|||
paths.Add($"{map.name}{InputAssetAction.pathSeparator}{action.name}"); |
|||
} |
|||
} |
|||
|
|||
return paths.ToArray(); |
|||
} |
|||
} |
|||
public static class Extensions |
|||
{ |
|||
public static int IndexOf(this string[] array, string value) |
|||
{ |
|||
for (int i = 0; i < array.Length; i++) |
|||
{ |
|||
if (array[i] == value) |
|||
return i; |
|||
} |
|||
return -1; |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|
|||
fileFormatVersion: 2 |
|||
guid: 857cf4d1897170945a9897f28a323452 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#if ENABLE_INPUT_SYSTEM
|
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEngine.InputSystem; |
|||
using System.Linq; |
|||
using System.Collections.Generic; |
|||
using GameplayIngredients.Events; |
|||
|
|||
namespace GameplayIngredients.Editor |
|||
{ |
|||
[CustomPropertyDrawer(typeof(PlayerInputAction))] |
|||
public class InputPlayerActionPropertyDrawer: PropertyDrawer |
|||
{ |
|||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) |
|||
{ |
|||
return EditorGUIUtility.singleLineHeight * 2 + 8; |
|||
} |
|||
|
|||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) |
|||
{ |
|||
var playerInput = property.FindPropertyRelative("playerInput"); |
|||
var path = property.FindPropertyRelative("path"); |
|||
|
|||
position.height = EditorGUIUtility.singleLineHeight; |
|||
EditorGUI.PropertyField(position, playerInput, new GUIContent("Player Input")); |
|||
EditorGUI.indentLevel++; |
|||
position.y += EditorGUIUtility.singleLineHeight + 2; |
|||
|
|||
var paths = GetPaths(playerInput.objectReferenceValue as PlayerInput); |
|||
int selected = paths.IndexOf(path.stringValue); |
|||
selected = EditorGUI.Popup(position, "Action", selected, paths); |
|||
if(GUI.changed) |
|||
{ |
|||
if (selected >= 0) |
|||
path.stringValue = paths[selected]; |
|||
else |
|||
path.stringValue = string.Empty; |
|||
} |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
string[] GetPaths(PlayerInput playerInput) |
|||
{ |
|||
if (playerInput == null || playerInput.actions == null) |
|||
return new string[0]; |
|||
|
|||
List<string> paths = new List<string>(); |
|||
|
|||
foreach(var map in playerInput.actions.actionMaps) |
|||
{ |
|||
if (map == null) continue; |
|||
foreach(var action in map.actions) |
|||
{ |
|||
if (action == null) continue; |
|||
|
|||
paths.Add($"{map.name}{InputAssetAction.pathSeparator}{action.name}"); |
|||
} |
|||
} |
|||
|
|||
return paths.ToArray(); |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|
|||
fileFormatVersion: 2 |
|||
guid: d4b5368aae1726047bd77d96d0112350 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Runtime.CompilerServices; |
|||
[assembly: InternalsVisibleTo("GameplayIngredients-Editor")] |
|
|||
fileFormatVersion: 2 |
|||
guid: 5c86294b577ff95408da6bfe4ef53415 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 672bda0d6f34a7746be00d708786bbb2 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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
|
|||
[SerializeField] |
|||
InputAction inputAction; |
|||
|
|||
public Callable[] onButtonDown; |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
InputActionManager.Request(inputAction, InputAction_performed); |
|||
} |
|||
private void OnDisable() |
|||
{ |
|||
InputActionManager.Release(inputAction, InputAction_performed); |
|||
} |
|||
|
|||
private void InputAction_performed(InputAction.CallbackContext obj) |
|||
{ |
|||
Callable.Call(onButtonDown, gameObject); |
|||
} |
|||
#endif
|
|||
} |
|||
} |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 97ebdd020f382b24d91e934683a756de |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
using UnityEngine.InputSystem; |
|||
#endif
|
|||
|
|||
namespace GameplayIngredients.Events |
|||
{ |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
[Serializable] |
|||
public struct InputAssetAction |
|||
{ |
|||
public InputActionAsset asset; |
|||
public string path; |
|||
|
|||
public InputAction action |
|||
{ |
|||
get |
|||
{ |
|||
if (asset == null) |
|||
return null; |
|||
else |
|||
{ |
|||
if(m_CachedPath != path || m_CachedInputAction == null) |
|||
{ |
|||
string[] split = path.Split(pathSeparator); |
|||
if(split.Length != 2) |
|||
{ |
|||
Debug.LogWarning($"Invalid Path '{path}'", asset); |
|||
return null; |
|||
} |
|||
int mapIdx = asset.actionMaps.IndexOf(o => o.name == split[0]); |
|||
|
|||
if(mapIdx == -1) // not found
|
|||
{ |
|||
Debug.LogWarning($"Could not find action map '{split[0]}' in asset {asset.name}", asset); |
|||
return null; |
|||
} |
|||
var map = asset.actionMaps[mapIdx]; |
|||
int actionIdx = map.actions.IndexOf(o => o.name == split[1]); |
|||
if(actionIdx == -1) // not found
|
|||
{ |
|||
Debug.LogWarning($"Could not find action '{split[1]}' of map '{map.name}' in asset {asset.name}", asset); |
|||
return null; |
|||
} |
|||
m_CachedInputAction = map.actions[actionIdx]; |
|||
m_CachedPath = path; |
|||
} |
|||
return m_CachedInputAction; |
|||
} |
|||
} |
|||
} |
|||
public const char pathSeparator = '/'; |
|||
string m_CachedPath; |
|||
InputAction m_CachedInputAction; |
|||
} |
|||
|
|||
|
|||
#endif
|
|||
#if !ENABLE_INPUT_SYSTEM
|
|||
[WarnDisabledModule("New Input System")] |
|||
#endif
|
|||
[AddComponentMenu(ComponentMenu.eventsPath + "On Input Asset Action Event (New Input System)")] |
|||
public class OnInputAssetActionEvent : EventBase |
|||
{ |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
[SerializeField] |
|||
InputAssetAction inputAction; |
|||
|
|||
[Header("Action")] |
|||
public Callable[] onButtonDown; |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
InputActionManager.Request(inputAction.action, InputAction_performed); |
|||
} |
|||
|
|||
private void OnDisable() |
|||
{ |
|||
InputActionManager.Release(inputAction.action, InputAction_performed); |
|||
} |
|||
|
|||
private void InputAction_performed(InputAction.CallbackContext obj) |
|||
{ |
|||
Callable.Call(onButtonDown, gameObject); |
|||
} |
|||
#endif
|
|||
} |
|||
} |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 8e4443e2a5662e440999cb1f3de312a8 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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
|
|||
[AddComponentMenu(ComponentMenu.eventsPath + "On Input Direct Event (New Input System)")] |
|||
public class OnInputDirectEvent : EventBase |
|||
{ |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
[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; |
|||
|
|||
bool IsMouse() => device == Device.Mouse; |
|||
bool IsGamepad() => device == Device.Gamepad; |
|||
bool IsKeyboard() => device == Device.Keyboard; |
|||
#endif
|
|||
public Callable[] onPressed; |
|||
public Callable[] onReleased; |
|||
|
|||
|
|||
|
|||
#if ENABLE_INPUT_SYSTEM
|
|||
ButtonControl button; |
|||
|
|||
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 InputSystemUtility.GetButton(gamepadButton); |
|||
case Device.Keyboard: |
|||
return InputSystemUtility.GetButton(keyboardKey); |
|||
case Device.Mouse: |
|||
return InputSystemUtility.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: |
|
|||
using System; |
|||
using UnityEngine; |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
using UnityEngine.InputSystem; |
|||
#endif
|
|||
|
|||
namespace GameplayIngredients.Events |
|||
{ |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
[Serializable] |
|||
public struct PlayerInputAction |
|||
{ |
|||
public PlayerInput playerInput; |
|||
public string path; |
|||
|
|||
public InputAction action |
|||
{ |
|||
get |
|||
{ |
|||
if (playerInput == null) |
|||
return null; |
|||
else |
|||
{ |
|||
if(m_CachedPath != path || m_CachedInputAction == null) |
|||
{ |
|||
string[] split = path.Split(pathSeparator); |
|||
if(split.Length != 2) |
|||
{ |
|||
Debug.LogWarning($"Invalid Path '{path}'", playerInput); |
|||
return null; |
|||
} |
|||
int mapIdx = playerInput.actions.actionMaps.IndexOf(o => o.name == split[0]); |
|||
|
|||
if(mapIdx == -1) // not found
|
|||
{ |
|||
Debug.LogWarning($"Could not find action map '{split[0]}' in asset {playerInput.name}", playerInput); |
|||
return null; |
|||
} |
|||
var map = playerInput.actions.actionMaps[mapIdx]; |
|||
int actionIdx = map.actions.IndexOf(o => o.name == split[1]); |
|||
if(actionIdx == -1) // not found
|
|||
{ |
|||
Debug.LogWarning($"Could not find action '{split[1]}' of map '{map.name}' in asset {playerInput.name}", playerInput); |
|||
return null; |
|||
} |
|||
m_CachedInputAction = map.actions[actionIdx]; |
|||
m_CachedPath = path; |
|||
} |
|||
return m_CachedInputAction; |
|||
} |
|||
} |
|||
} |
|||
public const char pathSeparator = '/'; |
|||
string m_CachedPath; |
|||
InputAction m_CachedInputAction; |
|||
} |
|||
|
|||
|
|||
#endif
|
|||
#if !ENABLE_INPUT_SYSTEM
|
|||
[WarnDisabledModule("New Input System")] |
|||
#endif
|
|||
[AddComponentMenu(ComponentMenu.eventsPath + "On Player Input Action Event (New Input System)")] |
|||
public class OnPlayerInputActionEvent : EventBase |
|||
{ |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
[SerializeField] |
|||
PlayerInputAction inputAction; |
|||
|
|||
[Header("Action")] |
|||
public Callable[] onButtonDown; |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
InputActionManager.Request(inputAction.action, InputAction_performed); |
|||
} |
|||
|
|||
private void OnDisable() |
|||
{ |
|||
InputActionManager.Release(inputAction.action, InputAction_performed); |
|||
} |
|||
|
|||
private void InputAction_performed(InputAction.CallbackContext obj) |
|||
{ |
|||
Callable.Call(onButtonDown, gameObject); |
|||
} |
|||
#endif
|
|||
} |
|||
} |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 537b04352cb86e447aa922e8d6b2561e |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using NaughtyAttributes; |
|||
using UnityEngine; |
|||
|
|||
namespace GameplayIngredients.Logic |
|||
{ |
|||
[AddComponentMenu(ComponentMenu.logicPath + "Input System Logic")] |
|||
[Callable("Application", "Logic/ic-generic-logic.png")] |
|||
public class InputSystemLogic : LogicBase |
|||
{ |
|||
[ShowIf("checkForLegacyInput")] |
|||
public Callable[] OnLegacyInputPresent; |
|||
[ShowIf("checkForLegacyInput")] |
|||
public Callable[] OnLegacyInputNotPresent; |
|||
|
|||
[ShowIf("checkForNewInput")] |
|||
public Callable[] OnNewInputPresent; |
|||
[ShowIf("checkForNewInput")] |
|||
|
|||
public Callable[] OnNewInputNotPresent; |
|||
|
|||
public override void Execute(GameObject instigator = null) |
|||
{ |
|||
#if ENABLE_LEGACY_INPUT_MANAGER
|
|||
Call(OnLegacyInputPresent, instigator); |
|||
#else
|
|||
Call(OnLegacyInputNotPresent, instigator); |
|||
#endif
|
|||
|
|||
#if ENABLE_INPUT_SYSTEM
|
|||
Call(OnNewInputPresent, instigator); |
|||
#else
|
|||
Call(OnLegacyInputNotPresent, instigator); |
|||
#endif
|
|||
} |
|||
} |
|||
} |
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: a579c054a1017f84e9e093fad80ad6cb |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {fileID: 2800000, guid: 6d0a734cdedf48d478f3fcc7612af66f, type: 3} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
|
|||
namespace GameplayIngredients |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Class)] |
|||
public class DoNotCreateManagerAttribute : Attribute { } |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 52ebbad63c8873c489c057ca3e7ac15e |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#if ENABLE_INPUT_SYSTEM
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.InputSystem; |
|||
|
|||
namespace GameplayIngredients |
|||
{ |
|||
public static class InputActionManager |
|||
{ |
|||
static Dictionary<InputAction, List<Action<InputAction.CallbackContext>>> m_Mappings = new Dictionary<InputAction, List<Action<InputAction.CallbackContext>>>(); |
|||
|
|||
public static void Request(InputAction action, Action<InputAction.CallbackContext> onPerformed) |
|||
{ |
|||
if(action == null || onPerformed == null) |
|||
{ |
|||
Debug.LogWarning($"Cannot request InputAction, either action or callback is null"); |
|||
return; |
|||
} |
|||
|
|||
if(!m_Mappings.ContainsKey(action)) |
|||
{ |
|||
m_Mappings.Add(action, new List<Action<InputAction.CallbackContext>>()); |
|||
} |
|||
|
|||
if (m_Mappings[action].Contains(onPerformed)) |
|||
{ |
|||
Debug.LogWarning($"InputAction already Registered : {action.name} : {onPerformed}"); |
|||
return; |
|||
} |
|||
else |
|||
{ |
|||
m_Mappings[action].Add(onPerformed); |
|||
|
|||
if(!action.enabled) |
|||
action.Enable(); |
|||
|
|||
action.performed += onPerformed; |
|||
} |
|||
} |
|||
|
|||
public static void Release(InputAction action, Action<InputAction.CallbackContext> onPerformed) |
|||
{ |
|||
if (action == null || onPerformed == null) |
|||
{ |
|||
Debug.LogWarning($"Cannot release InputAction, either action or callback is null"); |
|||
return; |
|||
} |
|||
|
|||
if (!m_Mappings.ContainsKey(action)) |
|||
{ |
|||
Debug.LogWarning($"Tried to release action {action.name} that was not already registered"); |
|||
} |
|||
else |
|||
{ |
|||
// Remove entry if present
|
|||
if(m_Mappings[action].Contains(onPerformed)) |
|||
{ |
|||
action.performed -= onPerformed; |
|||
m_Mappings[action].Remove(onPerformed); |
|||
} |
|||
|
|||
// If no more callbacks registered, remove entry and disable action.
|
|||
if(m_Mappings[action].Count == 0) |
|||
{ |
|||
action.Disable(); |
|||
m_Mappings.Remove(action); |
|||
} |
|||
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|
|||
fileFormatVersion: 2 |
|||
guid: e15a6e8bcae6a00428ea0f885dd28d15 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEngine; |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
using UnityEngine.InputSystem; |
|||
using UnityEngine.InputSystem.Controls; |
|||
#endif
|
|||
|
|||
namespace GameplayIngredients |
|||
{ |
|||
public static class InputSystemUtility |
|||
{ |
|||
#if ENABLE_INPUT_SYSTEM
|
|||
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; |
|||