From 029ca69924ad96a074b08f8d14dbfee3d842d84e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sun, 7 Apr 2024 00:58:57 +0200 Subject: [PATCH] =?UTF-8?q?Inp=C3=BBt=20=C3=80cti=C3=B3ns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3d Prototyp/Assets/InputSystem.meta | 8 + .../PlayerInputActions.inputactions | 267 ++++++++++++++++++ .../PlayerInputActions.inputactions.meta | 14 + 3d Prototyp/Assets/InteractionHandler.cs | 35 ++- 3d Prototyp/Assets/Scenes/GameJamScene.unity | 143 +++++++++- 3d Prototyp/Assets/Scripts/Character.cs | 42 +-- 3d Prototyp/Packages/manifest.json | 1 + 3d Prototyp/Packages/packages-lock.json | 9 + .../ProjectSettings/ProjectSettings.asset | 5 +- 9 files changed, 490 insertions(+), 34 deletions(-) create mode 100644 3d Prototyp/Assets/InputSystem.meta create mode 100644 3d Prototyp/Assets/InputSystem/PlayerInputActions.inputactions create mode 100644 3d Prototyp/Assets/InputSystem/PlayerInputActions.inputactions.meta diff --git a/3d Prototyp/Assets/InputSystem.meta b/3d Prototyp/Assets/InputSystem.meta new file mode 100644 index 00000000..9ccb0c64 --- /dev/null +++ b/3d Prototyp/Assets/InputSystem.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 14c132b43142c9a4abf349e97db5eb99 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/3d Prototyp/Assets/InputSystem/PlayerInputActions.inputactions b/3d Prototyp/Assets/InputSystem/PlayerInputActions.inputactions new file mode 100644 index 00000000..c094fca9 --- /dev/null +++ b/3d Prototyp/Assets/InputSystem/PlayerInputActions.inputactions @@ -0,0 +1,267 @@ +{ + "name": "PlayerInputActions", + "maps": [ + { + "name": "Player", + "id": "caa505cc-7bcc-444a-a01d-86fc246ea515", + "actions": [ + { + "name": "Jump", + "type": "Button", + "id": "7f3b63a1-be87-41ca-ad1b-19f55d303089", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, + { + "name": "Walk", + "type": "Value", + "id": "a8b6b0ff-5561-4ddc-b2bd-66e2fef329a0", + "expectedControlType": "Vector2", + "processors": "", + "interactions": "", + "initialStateCheck": true + }, + { + "name": "Drop Item", + "type": "Button", + "id": "1fbac6ab-15a0-4a9c-ab41-f1657cfe70f6", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, + { + "name": "Interact", + "type": "Button", + "id": "48a90872-b876-4bfd-b3fb-e9d66df8b6a4", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, + { + "name": "Select Previous Action", + "type": "Button", + "id": "82379c74-be3b-419a-8663-4d6235bf1585", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, + { + "name": "Select Next Action", + "type": "Button", + "id": "a8df853a-df28-4087-8356-bb64a7a81c51", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false + } + ], + "bindings": [ + { + "name": "", + "id": "f2ea4d5a-60c4-4606-800b-ec6f73598185", + "path": "/space", + "interactions": "", + "processors": "", + "groups": "Keyboard", + "action": "Jump", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "5a5c82be-ebfc-4d54-88ea-8e0541294317", + "path": "/buttonSouth", + "interactions": "", + "processors": "", + "groups": "Gamepad", + "action": "Jump", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "2D Vector", + "id": "cb950e36-674f-43e5-9cbc-c2e3a8504c45", + "path": "2DVector", + "interactions": "", + "processors": "", + "groups": "", + "action": "Walk", + "isComposite": true, + "isPartOfComposite": false + }, + { + "name": "up", + "id": "fe3710d2-6f62-4664-bcbc-6d65e0d9195e", + "path": "/w", + "interactions": "", + "processors": "", + "groups": "Keyboard", + "action": "Walk", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "down", + "id": "e4c03423-9283-47d6-84e3-b274452eb3bf", + "path": "/s", + "interactions": "", + "processors": "", + "groups": "Keyboard", + "action": "Walk", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "left", + "id": "a8637839-ed37-477b-a969-7f9819ea4dc8", + "path": "/a", + "interactions": "", + "processors": "", + "groups": "Keyboard", + "action": "Walk", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "right", + "id": "f782be80-3097-4c01-a414-493f23baa3bc", + "path": "/d", + "interactions": "", + "processors": "", + "groups": "Keyboard", + "action": "Walk", + "isComposite": false, + "isPartOfComposite": true + }, + { + "name": "", + "id": "3c34c499-fa93-4fac-b658-28547b157987", + "path": "/leftStick", + "interactions": "", + "processors": "", + "groups": "Gamepad", + "action": "Walk", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "4f260138-248a-4b91-b2db-658991a4dd5c", + "path": "/g", + "interactions": "", + "processors": "", + "groups": "Keyboard", + "action": "Drop Item", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "a43588a3-e03b-4566-8828-0ca6cfad356a", + "path": "/buttonEast", + "interactions": "", + "processors": "", + "groups": "Gamepad", + "action": "Drop Item", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "3ee22a24-9a3e-463f-9f54-cb3fe1ca29c2", + "path": "/e", + "interactions": "", + "processors": "", + "groups": "Keyboard", + "action": "Interact", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "7cda39b4-5100-4dba-8719-76bc542184ac", + "path": "/buttonWest", + "interactions": "", + "processors": "", + "groups": "Gamepad", + "action": "Interact", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "4c8f2737-b44e-41cf-a31b-abc357203c2f", + "path": "/leftArrow", + "interactions": "", + "processors": "", + "groups": "Keyboard", + "action": "Select Previous Action", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "f9417636-e924-4022-8e67-724959ad2565", + "path": "/dpad/left", + "interactions": "", + "processors": "", + "groups": "Gamepad", + "action": "Select Previous Action", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "b1ffe0d3-38b9-4221-8b1b-dbbb843593c3", + "path": "/rightArrow", + "interactions": "", + "processors": "", + "groups": "Keyboard", + "action": "Select Next Action", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "c5464801-d160-44aa-bcee-5434e42c55b7", + "path": "/dpad/right", + "interactions": "", + "processors": "", + "groups": "Gamepad", + "action": "Select Next Action", + "isComposite": false, + "isPartOfComposite": false + } + ] + } + ], + "controlSchemes": [ + { + "name": "Keyboard", + "bindingGroup": "Keyboard", + "devices": [ + { + "devicePath": "", + "isOptional": false, + "isOR": false + } + ] + }, + { + "name": "Gamepad", + "bindingGroup": "Gamepad", + "devices": [ + { + "devicePath": "", + "isOptional": false, + "isOR": false + } + ] + } + ] +} \ No newline at end of file diff --git a/3d Prototyp/Assets/InputSystem/PlayerInputActions.inputactions.meta b/3d Prototyp/Assets/InputSystem/PlayerInputActions.inputactions.meta new file mode 100644 index 00000000..2b808a5f --- /dev/null +++ b/3d Prototyp/Assets/InputSystem/PlayerInputActions.inputactions.meta @@ -0,0 +1,14 @@ +fileFormatVersion: 2 +guid: fb2e9958e9ec8d24c836f615c25410f8 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3} + generateWrapperCode: 0 + wrapperCodePath: + wrapperClassName: + wrapperCodeNamespace: diff --git a/3d Prototyp/Assets/InteractionHandler.cs b/3d Prototyp/Assets/InteractionHandler.cs index 123efa62..9990344d 100644 --- a/3d Prototyp/Assets/InteractionHandler.cs +++ b/3d Prototyp/Assets/InteractionHandler.cs @@ -5,6 +5,7 @@ using System.Linq; using Interaction; using JetBrains.Annotations; using UnityEngine; +using UnityEngine.InputSystem; using UnityEngine.Serialization; using Utility; @@ -40,22 +41,28 @@ public class InteractionHandler : MonoBehaviour } } - void Update() + public void DoSelectPreviousAction(InputAction.CallbackContext context) { - if (Input.GetKeyDown(KeyCode.LeftArrow)) - { - SelectPreviousAction(); - } + if (!context.performed) + return; - if (Input.GetKeyDown(KeyCode.RightArrow)) - { - SelectNextAction(); - } - - if (Input.GetKeyDown(KeyCode.E)) - { - DoInteraction(); - } + SelectPreviousAction(); + } + + public void DoSelectNextAction(InputAction.CallbackContext context) + { + if (!context.performed) + return; + + SelectNextAction(); + } + + public void DoInteract(InputAction.CallbackContext context) + { + if (!context.performed) + return; + + DoInteraction(); } private void DoInteraction() diff --git a/3d Prototyp/Assets/Scenes/GameJamScene.unity b/3d Prototyp/Assets/Scenes/GameJamScene.unity index b668604b..f1824d4b 100644 --- a/3d Prototyp/Assets/Scenes/GameJamScene.unity +++ b/3d Prototyp/Assets/Scenes/GameJamScene.unity @@ -40602,6 +40602,8 @@ MonoBehaviour: speakingSpeed: 1.1 playSound: 0 generate: 0 + newVoiceAndGenerate: 0 + Voice: --- !u!4 &1298233948 stripped Transform: m_CorrespondingSourceObject: {fileID: 5737504958030667471, guid: 7c7f0805c6bdc4f41bd65ec128f6b658, type: 3} @@ -46559,6 +46561,8 @@ MonoBehaviour: speakingSpeed: 1.1 playSound: 0 generate: 0 + newVoiceAndGenerate: 0 + Voice: --- !u!1001 &1502597417 PrefabInstance: m_ObjectHideFlags: 0 @@ -49966,12 +49970,12 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: moveSpeed: 30 - groundDrag: 1 + groundDrag: 4 speed: 5 turningRate: 600 _targetRotation: {x: 0, y: 0, z: 0, w: 1} jumpKey: 32 - jumpForce: 4 + jumpForce: 40 jumpCooldown: 0.5 playerHeight: 2 whatIsGround: @@ -50169,6 +50173,132 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 +--- !u!114 &1573807356 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1573807341} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Actions: {fileID: -944628639613478452, guid: fb2e9958e9ec8d24c836f615c25410f8, type: 3} + m_NotificationBehavior: 2 + m_UIInputModule: {fileID: 0} + m_DeviceLostEvent: + m_PersistentCalls: + m_Calls: [] + m_DeviceRegainedEvent: + m_PersistentCalls: + m_Calls: [] + m_ControlsChangedEvent: + m_PersistentCalls: + m_Calls: [] + m_ActionEvents: + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1573807344} + m_TargetAssemblyTypeName: Character, Assembly-CSharp + m_MethodName: DoJump + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_ActionId: 7f3b63a1-be87-41ca-ad1b-19f55d303089 + m_ActionName: Player/Jump + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1573807344} + m_TargetAssemblyTypeName: Character, Assembly-CSharp + m_MethodName: DoMove + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_ActionId: a8b6b0ff-5561-4ddc-b2bd-66e2fef329a0 + m_ActionName: Player/Walk + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1573807344} + m_TargetAssemblyTypeName: Character, Assembly-CSharp + m_MethodName: DoDropItem + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_ActionId: 1fbac6ab-15a0-4a9c-ab41-f1657cfe70f6 + m_ActionName: Player/Drop Item + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1573807350} + m_TargetAssemblyTypeName: InteractionHandler, Assembly-CSharp + m_MethodName: DoInteract + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_ActionId: 48a90872-b876-4bfd-b3fb-e9d66df8b6a4 + m_ActionName: Player/Interact[/Keyboard/e,/XInputControllerWindows/buttonWest] + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1573807350} + m_TargetAssemblyTypeName: InteractionHandler, Assembly-CSharp + m_MethodName: DoSelectPreviousAction + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_ActionId: 82379c74-be3b-419a-8663-4d6235bf1585 + m_ActionName: Player/Select Previous Action[/Keyboard/leftArrow,/XInputControllerWindows/dpad/left] + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1573807350} + m_TargetAssemblyTypeName: InteractionHandler, Assembly-CSharp + m_MethodName: DoSelectNextAction + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_ActionId: a8df853a-df28-4087-8356-bb64a7a81c51 + m_ActionName: Player/Select Next Action[/Keyboard/rightArrow,/XInputControllerWindows/dpad/right] + m_NeverAutoSwitchControlSchemes: 0 + m_DefaultControlScheme: + m_DefaultActionMap: Player + m_SplitScreenIndex: -1 + m_Camera: {fileID: 0} --- !u!1 &1577864189 GameObject: m_ObjectHideFlags: 0 @@ -59979,6 +60109,8 @@ MonoBehaviour: speakingSpeed: 1.1 playSound: 0 generate: 0 + newVoiceAndGenerate: 0 + Voice: --- !u!82 &1891423493 AudioSource: m_ObjectHideFlags: 0 @@ -62298,6 +62430,8 @@ MonoBehaviour: speakingSpeed: 1.1 playSound: 0 generate: 0 + newVoiceAndGenerate: 0 + Voice: --- !u!1 &1961564159 GameObject: m_ObjectHideFlags: 0 @@ -66309,6 +66443,8 @@ MonoBehaviour: speakingSpeed: 1.1 playSound: 0 generate: 0 + newVoiceAndGenerate: 0 + Voice: --- !u!1 &2101876026 GameObject: m_ObjectHideFlags: 0 @@ -68195,6 +68331,9 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 9017657623670109072, guid: 7c7f0805c6bdc4f41bd65ec128f6b658, type: 3} insertIndex: -1 addedObject: {fileID: 1573807353} + - targetCorrespondingSourceObject: {fileID: 9017657623670109072, guid: 7c7f0805c6bdc4f41bd65ec128f6b658, type: 3} + insertIndex: -1 + addedObject: {fileID: 1573807356} m_SourcePrefab: {fileID: 100100000, guid: 7c7f0805c6bdc4f41bd65ec128f6b658, type: 3} --- !u!23 &87716553343573121 MeshRenderer: diff --git a/3d Prototyp/Assets/Scripts/Character.cs b/3d Prototyp/Assets/Scripts/Character.cs index 513ddad7..4c131540 100644 --- a/3d Prototyp/Assets/Scripts/Character.cs +++ b/3d Prototyp/Assets/Scripts/Character.cs @@ -5,6 +5,7 @@ using Interaction; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; +using UnityEngine.InputSystem; using UnityEngine.Serialization; using Utility; @@ -64,7 +65,6 @@ public class Character : MonoBehaviour { grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.2f, whatIsGround); - MyInput(); SpeedControl(); transform.rotation = Quaternion.RotateTowards(transform.rotation, _targetRotation, turningRate * Time.deltaTime); @@ -117,35 +117,41 @@ public class Character : MonoBehaviour MovePlayer(); } - private void MyInput() + public void DoMove(InputAction.CallbackContext context) { - horizontalInput = Input.GetAxisRaw("Horizontal"); - verticalInput = Input.GetAxisRaw("Vertical"); + Vector2 movement = context.ReadValue(); + horizontalInput = movement.x; + verticalInput = movement.y; + if(horizontalInput != 0f || verticalInput != 0f) { _targetRotation = Quaternion.Euler(new Vector3(0f, Mathf.Atan2(horizontalInput, verticalInput) * Mathf.Rad2Deg, 0f)); } + } + + public void DoJump(InputAction.CallbackContext context) + { + if (!context.performed || !readyToJump || !grounded) + return; - if (Input.GetKey(jumpKey) && readyToJump && grounded) - { - readyToJump = false; + Jump(); - Jump(); + Invoke(nameof(ResetJump), jumpCooldown); + } - Invoke(nameof(ResetJump), jumpCooldown); - } - - if (Input.GetKeyDown(KeyCode.G)) - { - PickupItem(null); - } + public void DoDropItem(InputAction.CallbackContext context) + { + if (!context.performed) + return; + + PickupItem(null); } private void MovePlayer() { moveDirection = new Vector3(0, 0, verticalInput) + new Vector3(horizontalInput, 0, 0); - + rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force); } @@ -175,8 +181,12 @@ public class Character : MonoBehaviour public void GiveItemTo(Developer developer) { Debug.Log($"Gebe {_carriedInteractible.Name} an {developer.Name}"); + + Interactible item = _carriedInteractible; PickupItem(null); + + Destroy(item.gameObject); } public void SayItsImpossible() diff --git a/3d Prototyp/Packages/manifest.json b/3d Prototyp/Packages/manifest.json index bb323eb8..a8fd1129 100644 --- a/3d Prototyp/Packages/manifest.json +++ b/3d Prototyp/Packages/manifest.json @@ -3,6 +3,7 @@ "com.github-glitchenzo.nugetforunity": "https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity", "com.unity.collab-proxy": "2.3.1", "com.unity.feature.development": "1.0.1", + "com.unity.inputsystem": "1.7.0", "com.unity.textmeshpro": "3.0.6", "com.unity.timeline": "1.7.6", "com.unity.ugui": "1.0.0", diff --git a/3d Prototyp/Packages/packages-lock.json b/3d Prototyp/Packages/packages-lock.json index 1478f05c..95fe7c39 100644 --- a/3d Prototyp/Packages/packages-lock.json +++ b/3d Prototyp/Packages/packages-lock.json @@ -67,6 +67,15 @@ "dependencies": {}, "url": "https://packages.unity.com" }, + "com.unity.inputsystem": { + "version": "1.7.0", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.modules.uielements": "1.0.0" + }, + "url": "https://packages.unity.com" + }, "com.unity.performance.profile-analyzer": { "version": "1.2.2", "depth": 1, diff --git a/3d Prototyp/ProjectSettings/ProjectSettings.asset b/3d Prototyp/ProjectSettings/ProjectSettings.asset index 0f0f3f95..955a4f03 100644 --- a/3d Prototyp/ProjectSettings/ProjectSettings.asset +++ b/3d Prototyp/ProjectSettings/ProjectSettings.asset @@ -160,7 +160,8 @@ PlayerSettings: resetResolutionOnWindowResize: 0 androidSupportedAspectRatio: 1 androidMaxAspectRatio: 2.1 - applicationIdentifier: {} + applicationIdentifier: + Standalone: com.DefaultCompany.3d-Prototyp buildNumber: Standalone: 0 VisionOS: 0 @@ -750,7 +751,7 @@ PlayerSettings: hmiLogStartupTiming: 0 hmiCpuConfiguration: apiCompatibilityLevel: 6 - activeInputHandler: 0 + activeInputHandler: 2 windowsGamepadBackendHint: 0 cloudProjectId: 834e0be4-1151-45e6-a495-9479b7cec55e framebufferDepthMemorylessMode: 0