From 56b73634c522c12d9bcdc68537290729baa27c92 Mon Sep 17 00:00:00 2001 From: Joshua Reason Date: Sat, 1 Feb 2020 14:02:32 +1100 Subject: [PATCH] Added input system --- Assets/Input.meta | 8 ++ Assets/Input/HerdInput.inputactions | 143 +++++++++++++++++++++++ Assets/Input/HerdInput.inputactions.meta | 14 +++ Assets/Scripts/Input/HerdController.cs | 8 +- Assets/WorldAssets/Prefabs/Cube.prefab | 3 +- 5 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 Assets/Input.meta create mode 100644 Assets/Input/HerdInput.inputactions create mode 100644 Assets/Input/HerdInput.inputactions.meta diff --git a/Assets/Input.meta b/Assets/Input.meta new file mode 100644 index 0000000..f955025 --- /dev/null +++ b/Assets/Input.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3c0607c9e4b18ba4bb69211d5d5e5a3b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Input/HerdInput.inputactions b/Assets/Input/HerdInput.inputactions new file mode 100644 index 0000000..7f49970 --- /dev/null +++ b/Assets/Input/HerdInput.inputactions @@ -0,0 +1,143 @@ +{ + "name": "HerdInput", + "maps": [ + { + "name": "Overworld", + "id": "c89e2228-b7f5-4b32-ac4e-fbea6cb10475", + "actions": [ + { + "name": "Movement", + "type": "Value", + "id": "99cdc6da-5df1-4136-b79d-1c3760ff7733", + "expectedControlType": "Vector2", + "processors": "", + "interactions": "" + } + ], + "bindings": [ + { + "name": "WASD", + "id": "585768f2-f8f3-49a1-92ce-749719640d21", + "path": "2DVector", + "interactions": "", + "processors": "", + "groups": "", + "action": "Movement", + "isComposite": true, + "isPartOfComposite": false + }, + { + "name": "up", + "id": "4ffbcb13-b94c-4f7f-9ede-adc65315d423", + "path": "/w", + "interactions": "", + "processors": "", + "groups": "", + "action": "Movement", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "down", + "id": "f0c4e586-5052-40ea-8727-6ffbcf1906f4", + "path": "/s", + "interactions": "", + "processors": "", + "groups": "", + "action": "Movement", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "left", + "id": "cb18a7d8-37af-489c-a9e8-f10a7d549297", + "path": "/a", + "interactions": "", + "processors": "", + "groups": "", + "action": "Movement", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "right", + "id": "79ea85ef-a2c7-4a70-8a62-c915f57351e7", + "path": "/d", + "interactions": "", + "processors": "", + "groups": "", + "action": "Movement", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "Arrow", + "id": "be124a39-a025-4851-8072-acf105391a89", + "path": "2DVector", + "interactions": "", + "processors": "", + "groups": "", + "action": "Movement", + "isComposite": true, + "isPartOfComposite": false + }, + { + "name": "up", + "id": "6c34a5fc-b8b1-4004-ac64-8b0d90f7ecd1", + "path": "/upArrow", + "interactions": "", + "processors": "", + "groups": "", + "action": "Movement", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "down", + "id": "542d8dc4-c0a9-484f-aac9-da4d5feda688", + "path": "/downArrow", + "interactions": "", + "processors": "", + "groups": "", + "action": "Movement", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "left", + "id": "acf7c952-58bd-480f-9f8a-06af08a6d5bb", + "path": "/leftArrow", + "interactions": "", + "processors": "", + "groups": "", + "action": "Movement", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "right", + "id": "3940709f-2905-4a5d-be3e-588e416ba132", + "path": "/rightArrow", + "interactions": "", + "processors": "", + "groups": "", + "action": "Movement", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "", + "id": "df6fcd3e-9fe7-4f14-8b39-5db8f9ec190a", + "path": "/leftStick", + "interactions": "", + "processors": "", + "groups": "", + "action": "Movement", + "isComposite": false, + "isPartOfComposite": false + } + ] + } + ], + "controlSchemes": [] +} \ No newline at end of file diff --git a/Assets/Input/HerdInput.inputactions.meta b/Assets/Input/HerdInput.inputactions.meta new file mode 100644 index 0000000..e03f8f3 --- /dev/null +++ b/Assets/Input/HerdInput.inputactions.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: 1950e6d3a3a526541aed6b542303792b +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3} + generateWrapperCode: 0 + wrapperCodePath: + wrapperClassName: + wrapperCodeNamespace: diff --git a/Assets/Scripts/Input/HerdController.cs b/Assets/Scripts/Input/HerdController.cs index f74ab32..a03bd15 100644 --- a/Assets/Scripts/Input/HerdController.cs +++ b/Assets/Scripts/Input/HerdController.cs @@ -16,7 +16,7 @@ public class HerdController : MonoBehaviour [SerializeField] private Transform SpawnPoint; - private List Herd; + private List Herd; @@ -24,7 +24,7 @@ public class HerdController : MonoBehaviour private void OnMovement(InputValue value) { Vector2 input = value.Get(); - + Herd.ForEach(p => p.SetMovement(input)); } @@ -39,7 +39,7 @@ public class HerdController : MonoBehaviour if (Herd != null) Herd.ForEach(p => Destroy(p)); - Herd = new List(); + Herd = new List(); for (int i = 0; i < HerdCount; i++) { @@ -59,7 +59,7 @@ public class HerdController : MonoBehaviour { GameObject newObject = Instantiate(Prefab, position, rotation, transform); - Herd.Add(newObject); + Herd.Add(newObject.GetComponent()); break; diff --git a/Assets/WorldAssets/Prefabs/Cube.prefab b/Assets/WorldAssets/Prefabs/Cube.prefab index f9fe4c3..a742442 100644 --- a/Assets/WorldAssets/Prefabs/Cube.prefab +++ b/Assets/WorldAssets/Prefabs/Cube.prefab @@ -66,9 +66,10 @@ MonoBehaviour: m_GameObject: {fileID: 588491153375435794} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 58f8f74b224d33d458c143811ba0a32a, type: 3} + m_Script: {fileID: 11500000, guid: 3a0ed68fb4a52474dbfbbcfb40e2f68d, type: 3} m_Name: m_EditorClassIdentifier: + walkSpeed: 10 --- !u!1 &4098178456956087476 GameObject: m_ObjectHideFlags: 0