Inpût Àctións

This commit is contained in:
Simon Lübeß 2024-04-07 00:58:57 +02:00
parent 3bdf7231e3
commit 029ca69924
9 changed files with 490 additions and 34 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 14c132b43142c9a4abf349e97db5eb99
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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": "<Keyboard>/space",
"interactions": "",
"processors": "",
"groups": "Keyboard",
"action": "Jump",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "5a5c82be-ebfc-4d54-88ea-8e0541294317",
"path": "<Gamepad>/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": "<Keyboard>/w",
"interactions": "",
"processors": "",
"groups": "Keyboard",
"action": "Walk",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "e4c03423-9283-47d6-84e3-b274452eb3bf",
"path": "<Keyboard>/s",
"interactions": "",
"processors": "",
"groups": "Keyboard",
"action": "Walk",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "a8637839-ed37-477b-a969-7f9819ea4dc8",
"path": "<Keyboard>/a",
"interactions": "",
"processors": "",
"groups": "Keyboard",
"action": "Walk",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "f782be80-3097-4c01-a414-493f23baa3bc",
"path": "<Keyboard>/d",
"interactions": "",
"processors": "",
"groups": "Keyboard",
"action": "Walk",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "",
"id": "3c34c499-fa93-4fac-b658-28547b157987",
"path": "<Gamepad>/leftStick",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Walk",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "4f260138-248a-4b91-b2db-658991a4dd5c",
"path": "<Keyboard>/g",
"interactions": "",
"processors": "",
"groups": "Keyboard",
"action": "Drop Item",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "a43588a3-e03b-4566-8828-0ca6cfad356a",
"path": "<Gamepad>/buttonEast",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Drop Item",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "3ee22a24-9a3e-463f-9f54-cb3fe1ca29c2",
"path": "<Keyboard>/e",
"interactions": "",
"processors": "",
"groups": "Keyboard",
"action": "Interact",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "7cda39b4-5100-4dba-8719-76bc542184ac",
"path": "<Gamepad>/buttonWest",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Interact",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "4c8f2737-b44e-41cf-a31b-abc357203c2f",
"path": "<Keyboard>/leftArrow",
"interactions": "",
"processors": "",
"groups": "Keyboard",
"action": "Select Previous Action",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "f9417636-e924-4022-8e67-724959ad2565",
"path": "<Gamepad>/dpad/left",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Select Previous Action",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "b1ffe0d3-38b9-4221-8b1b-dbbb843593c3",
"path": "<Keyboard>/rightArrow",
"interactions": "",
"processors": "",
"groups": "Keyboard",
"action": "Select Next Action",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "c5464801-d160-44aa-bcee-5434e42c55b7",
"path": "<Gamepad>/dpad/right",
"interactions": "",
"processors": "",
"groups": "Gamepad",
"action": "Select Next Action",
"isComposite": false,
"isPartOfComposite": false
}
]
}
],
"controlSchemes": [
{
"name": "Keyboard",
"bindingGroup": "Keyboard",
"devices": [
{
"devicePath": "<Keyboard>",
"isOptional": false,
"isOR": false
}
]
},
{
"name": "Gamepad",
"bindingGroup": "Gamepad",
"devices": [
{
"devicePath": "<Gamepad>",
"isOptional": false,
"isOR": false
}
]
}
]
}

View File

@ -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:

View File

@ -5,6 +5,7 @@ using System.Linq;
using Interaction; using Interaction;
using JetBrains.Annotations; using JetBrains.Annotations;
using UnityEngine; using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Serialization; using UnityEngine.Serialization;
using Utility; using Utility;
@ -40,23 +41,29 @@ public class InteractionHandler : MonoBehaviour
} }
} }
void Update() public void DoSelectPreviousAction(InputAction.CallbackContext context)
{
if (Input.GetKeyDown(KeyCode.LeftArrow))
{ {
if (!context.performed)
return;
SelectPreviousAction(); SelectPreviousAction();
} }
if (Input.GetKeyDown(KeyCode.RightArrow)) public void DoSelectNextAction(InputAction.CallbackContext context)
{ {
if (!context.performed)
return;
SelectNextAction(); SelectNextAction();
} }
if (Input.GetKeyDown(KeyCode.E)) public void DoInteract(InputAction.CallbackContext context)
{ {
if (!context.performed)
return;
DoInteraction(); DoInteraction();
} }
}
private void DoInteraction() private void DoInteraction()
{ {

View File

@ -40602,6 +40602,8 @@ MonoBehaviour:
speakingSpeed: 1.1 speakingSpeed: 1.1
playSound: 0 playSound: 0
generate: 0 generate: 0
newVoiceAndGenerate: 0
Voice:
--- !u!4 &1298233948 stripped --- !u!4 &1298233948 stripped
Transform: Transform:
m_CorrespondingSourceObject: {fileID: 5737504958030667471, guid: 7c7f0805c6bdc4f41bd65ec128f6b658, type: 3} m_CorrespondingSourceObject: {fileID: 5737504958030667471, guid: 7c7f0805c6bdc4f41bd65ec128f6b658, type: 3}
@ -46559,6 +46561,8 @@ MonoBehaviour:
speakingSpeed: 1.1 speakingSpeed: 1.1
playSound: 0 playSound: 0
generate: 0 generate: 0
newVoiceAndGenerate: 0
Voice:
--- !u!1001 &1502597417 --- !u!1001 &1502597417
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -49966,12 +49970,12 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
moveSpeed: 30 moveSpeed: 30
groundDrag: 1 groundDrag: 4
speed: 5 speed: 5
turningRate: 600 turningRate: 600
_targetRotation: {x: 0, y: 0, z: 0, w: 1} _targetRotation: {x: 0, y: 0, z: 0, w: 1}
jumpKey: 32 jumpKey: 32
jumpForce: 4 jumpForce: 40
jumpCooldown: 0.5 jumpCooldown: 0.5
playerHeight: 2 playerHeight: 2
whatIsGround: whatIsGround:
@ -50169,6 +50173,132 @@ AudioSource:
m_PreInfinity: 2 m_PreInfinity: 2
m_PostInfinity: 2 m_PostInfinity: 2
m_RotationOrder: 4 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 --- !u!1 &1577864189
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -59979,6 +60109,8 @@ MonoBehaviour:
speakingSpeed: 1.1 speakingSpeed: 1.1
playSound: 0 playSound: 0
generate: 0 generate: 0
newVoiceAndGenerate: 0
Voice:
--- !u!82 &1891423493 --- !u!82 &1891423493
AudioSource: AudioSource:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -62298,6 +62430,8 @@ MonoBehaviour:
speakingSpeed: 1.1 speakingSpeed: 1.1
playSound: 0 playSound: 0
generate: 0 generate: 0
newVoiceAndGenerate: 0
Voice:
--- !u!1 &1961564159 --- !u!1 &1961564159
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -66309,6 +66443,8 @@ MonoBehaviour:
speakingSpeed: 1.1 speakingSpeed: 1.1
playSound: 0 playSound: 0
generate: 0 generate: 0
newVoiceAndGenerate: 0
Voice:
--- !u!1 &2101876026 --- !u!1 &2101876026
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -68195,6 +68331,9 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 9017657623670109072, guid: 7c7f0805c6bdc4f41bd65ec128f6b658, type: 3} - targetCorrespondingSourceObject: {fileID: 9017657623670109072, guid: 7c7f0805c6bdc4f41bd65ec128f6b658, type: 3}
insertIndex: -1 insertIndex: -1
addedObject: {fileID: 1573807353} addedObject: {fileID: 1573807353}
- targetCorrespondingSourceObject: {fileID: 9017657623670109072, guid: 7c7f0805c6bdc4f41bd65ec128f6b658, type: 3}
insertIndex: -1
addedObject: {fileID: 1573807356}
m_SourcePrefab: {fileID: 100100000, guid: 7c7f0805c6bdc4f41bd65ec128f6b658, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 7c7f0805c6bdc4f41bd65ec128f6b658, type: 3}
--- !u!23 &87716553343573121 --- !u!23 &87716553343573121
MeshRenderer: MeshRenderer:

View File

@ -5,6 +5,7 @@ using Interaction;
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.Serialization; using UnityEngine.Serialization;
using Utility; using Utility;
@ -64,7 +65,6 @@ public class Character : MonoBehaviour
{ {
grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.2f, whatIsGround); grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.2f, whatIsGround);
MyInput();
SpeedControl(); SpeedControl();
transform.rotation = Quaternion.RotateTowards(transform.rotation, _targetRotation, turningRate * Time.deltaTime); transform.rotation = Quaternion.RotateTowards(transform.rotation, _targetRotation, turningRate * Time.deltaTime);
@ -117,30 +117,36 @@ public class Character : MonoBehaviour
MovePlayer(); MovePlayer();
} }
private void MyInput() public void DoMove(InputAction.CallbackContext context)
{ {
horizontalInput = Input.GetAxisRaw("Horizontal"); Vector2 movement = context.ReadValue<Vector2>();
verticalInput = Input.GetAxisRaw("Vertical");
horizontalInput = movement.x;
verticalInput = movement.y;
if(horizontalInput != 0f || verticalInput != 0f) if(horizontalInput != 0f || verticalInput != 0f)
{ {
_targetRotation = Quaternion.Euler(new Vector3(0f, Mathf.Atan2(horizontalInput, verticalInput) * Mathf.Rad2Deg, 0f)); _targetRotation = Quaternion.Euler(new Vector3(0f, Mathf.Atan2(horizontalInput, verticalInput) * Mathf.Rad2Deg, 0f));
} }
}
if (Input.GetKey(jumpKey) && readyToJump && grounded) public void DoJump(InputAction.CallbackContext context)
{ {
readyToJump = false; if (!context.performed || !readyToJump || !grounded)
return;
Jump(); Jump();
Invoke(nameof(ResetJump), jumpCooldown); Invoke(nameof(ResetJump), jumpCooldown);
} }
if (Input.GetKeyDown(KeyCode.G)) public void DoDropItem(InputAction.CallbackContext context)
{ {
if (!context.performed)
return;
PickupItem(null); PickupItem(null);
} }
}
private void MovePlayer() private void MovePlayer()
{ {
@ -176,7 +182,11 @@ public class Character : MonoBehaviour
{ {
Debug.Log($"Gebe {_carriedInteractible.Name} an {developer.Name}"); Debug.Log($"Gebe {_carriedInteractible.Name} an {developer.Name}");
Interactible item = _carriedInteractible;
PickupItem(null); PickupItem(null);
Destroy(item.gameObject);
} }
public void SayItsImpossible() public void SayItsImpossible()

View File

@ -3,6 +3,7 @@
"com.github-glitchenzo.nugetforunity": "https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity", "com.github-glitchenzo.nugetforunity": "https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity",
"com.unity.collab-proxy": "2.3.1", "com.unity.collab-proxy": "2.3.1",
"com.unity.feature.development": "1.0.1", "com.unity.feature.development": "1.0.1",
"com.unity.inputsystem": "1.7.0",
"com.unity.textmeshpro": "3.0.6", "com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.7.6", "com.unity.timeline": "1.7.6",
"com.unity.ugui": "1.0.0", "com.unity.ugui": "1.0.0",

View File

@ -67,6 +67,15 @@
"dependencies": {}, "dependencies": {},
"url": "https://packages.unity.com" "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": { "com.unity.performance.profile-analyzer": {
"version": "1.2.2", "version": "1.2.2",
"depth": 1, "depth": 1,

View File

@ -160,7 +160,8 @@ PlayerSettings:
resetResolutionOnWindowResize: 0 resetResolutionOnWindowResize: 0
androidSupportedAspectRatio: 1 androidSupportedAspectRatio: 1
androidMaxAspectRatio: 2.1 androidMaxAspectRatio: 2.1
applicationIdentifier: {} applicationIdentifier:
Standalone: com.DefaultCompany.3d-Prototyp
buildNumber: buildNumber:
Standalone: 0 Standalone: 0
VisionOS: 0 VisionOS: 0
@ -750,7 +751,7 @@ PlayerSettings:
hmiLogStartupTiming: 0 hmiLogStartupTiming: 0
hmiCpuConfiguration: hmiCpuConfiguration:
apiCompatibilityLevel: 6 apiCompatibilityLevel: 6
activeInputHandler: 0 activeInputHandler: 2
windowsGamepadBackendHint: 0 windowsGamepadBackendHint: 0
cloudProjectId: 834e0be4-1151-45e6-a495-9479b7cec55e cloudProjectId: 834e0be4-1151-45e6-a495-9479b7cec55e
framebufferDepthMemorylessMode: 0 framebufferDepthMemorylessMode: 0