From a07b295a8613345a7acd385c4fd805da26e8eda9 Mon Sep 17 00:00:00 2001 From: erheine <erheine@nps.edu> Date: Fri, 6 Mar 2020 13:41:51 -0800 Subject: [PATCH] Added a class that maps Unity Input Actions to Game Events. The shared package is now dependent on the Unity Input system package until it's permanently part of the engine. --- Scriptable Variables/Senders.meta | 8 +++++ .../Senders/InputActionToEvent.cs | 29 +++++++++++++++++++ .../Senders/InputActionToEvent.cs.meta | 11 +++++++ .../Shared.ScriptableVariables.asmdef | 9 ++++-- package.json | 5 ++-- 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 Scriptable Variables/Senders.meta create mode 100644 Scriptable Variables/Senders/InputActionToEvent.cs create mode 100644 Scriptable Variables/Senders/InputActionToEvent.cs.meta diff --git a/Scriptable Variables/Senders.meta b/Scriptable Variables/Senders.meta new file mode 100644 index 0000000..61f1d54 --- /dev/null +++ b/Scriptable Variables/Senders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3db7cd7fe135f9d488f16e3a909444a1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scriptable Variables/Senders/InputActionToEvent.cs b/Scriptable Variables/Senders/InputActionToEvent.cs new file mode 100644 index 0000000..3a87a4b --- /dev/null +++ b/Scriptable Variables/Senders/InputActionToEvent.cs @@ -0,0 +1,29 @@ +using UnityEngine; +using UnityEngine.InputSystem; + +namespace Shared.ScriptableVariables { + // Mapper between Unity's new Input action system and the Game Event system + public class InputActionToEvent : MonoBehaviour { + [Tooltip("Event to use for inputs that don't have values associated with them")] + public GameEvent actionFired; + + [Tooltip("Event to use for inputs with values associated with them")] + public FloatGameEvent valueActionFired; + + // -------------------------------------------------------------------------- + public void ActionFired(InputAction.CallbackContext context) { + if (isActiveAndEnabled) { + if (context.performed) { + actionFired?.Raise(); + } + } + } + + // -------------------------------------------------------------------------- + public void ValueActionFired(InputAction.CallbackContext context) { + if (isActiveAndEnabled) { + valueActionFired?.Raise(context.ReadValue<float>()); + } + } + } +} diff --git a/Scriptable Variables/Senders/InputActionToEvent.cs.meta b/Scriptable Variables/Senders/InputActionToEvent.cs.meta new file mode 100644 index 0000000..c537604 --- /dev/null +++ b/Scriptable Variables/Senders/InputActionToEvent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f9df856b7c621e447bec7dd3d5a5c3e9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scriptable Variables/Shared.ScriptableVariables.asmdef b/Scriptable Variables/Shared.ScriptableVariables.asmdef index ebdf6e7..35d7f0a 100644 --- a/Scriptable Variables/Shared.ScriptableVariables.asmdef +++ b/Scriptable Variables/Shared.ScriptableVariables.asmdef @@ -1,12 +1,15 @@ { "name": "Shared.ScriptableVariables", - "references": [], - "optionalUnityReferences": [], + "references": [ + "GUID:75469ad4d38634e559750d17036d5f7c" + ], "includePlatforms": [], "excludePlatforms": [], "allowUnsafeCode": false, "overrideReferences": false, "precompiledReferences": [], "autoReferenced": true, - "defineConstraints": [] + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false } \ No newline at end of file diff --git a/package.json b/package.json index 8b76371..8f386ad 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "com.futuretech.shared", "displayName": "FutureTech Shared", "description": "Contains shared items such as the Scriptable Variables.", - "version": "0.1.22", - "unity": "2019.1", + "version": "0.1.23", + "unity": "2019.2", "license": "MIT", "repository": { "type": "git", @@ -12,5 +12,6 @@ "src": "Assets/FutureTechShared", "author": "mg <mjguerre@nps.edu>", "dependencies": { + "com.unity.inputsystem": "1.0.0-preview.5" } } \ No newline at end of file -- GitLab