bruh
This commit is contained in:
1 parent
0d5e6b6dec
commit
c12d653cbc
647 files changed
+194585
-117
No files matched your search
@@ -0,0 +1,9 @@
|
||||
namespace Code.Input
|
||||
{
|
||||
public enum ActionMapping
|
||||
{
|
||||
MainMenu,
|
||||
Gameplay,
|
||||
UI
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79cf117afe77443992636e32b29782ec
|
||||
timeCreated: 1771430942
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Code.Input
|
||||
{
|
||||
public interface IInputService
|
||||
{
|
||||
void EnableMap(ActionMapping actionMap);
|
||||
void DisableMap(ActionMapping actionMap);
|
||||
|
||||
Vector2 MainMenuParalax { get; }
|
||||
|
||||
Vector2 LookInput { get; }
|
||||
Vector2 MoveInput { get; }
|
||||
bool JumpPressed { get; }
|
||||
bool SprintHeld { get; }
|
||||
|
||||
|
||||
void DebugBindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action);
|
||||
void DebugUnbindAction(int mapId, int actionId, Action<InputAction.CallbackContext> action);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8acf7d28cc74a7fb5fca2a6ffb2dee3
|
||||
timeCreated: 1771430932
|
||||
@@ -0,0 +1,95 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Code.Input
|
||||
{
|
||||
public class InputService : IInputService
|
||||
{
|
||||
private readonly InputActionAsset _inputActionAsset;
|
||||
private InputAction _lmbInteractAction;
|
||||
|
||||
public Vector2 MainMenuParalax { get; private set; }
|
||||
|
||||
public Vector2 LookInput { get; private set; }
|
||||
public Vector2 MoveInput { get; private set; }
|
||||
public bool JumpPressed { get; private set; }
|
||||
public bool SprintHeld { get; private set; }
|
||||
public bool AttackPressed { get; private set; }
|
||||
|
||||
public InputService(InputActionAsset inputActionAsset)
|
||||
{
|
||||
_inputActionAsset = inputActionAsset;
|
||||
SetupInputCallbacks();
|
||||
}
|
||||
|
||||
private void SetupInputCallbacks()
|
||||
{
|
||||
SetupMainMenuInputCallbacks();
|
||||
SetupGameplayInputCallbacks();
|
||||
}
|
||||
|
||||
private void SetupGameplayInputCallbacks()
|
||||
{
|
||||
var map = _inputActionAsset.actionMaps[(int)ActionMapping.Gameplay];
|
||||
BindVector2(map, "Move", v => MoveInput = v);
|
||||
BindButton(map, "Jump", v => JumpPressed = v);
|
||||
BindButton(map, "Sprint", v => SprintHeld = v);
|
||||
BindButton(map, "Attack", v => AttackPressed = v);
|
||||
}
|
||||
|
||||
private void SetupMainMenuInputCallbacks()
|
||||
{
|
||||
var map = _inputActionAsset.actionMaps[(int)ActionMapping.MainMenu];
|
||||
BindVector2(map, "Parallax", v => MainMenuParalax = v);
|
||||
}
|
||||
|
||||
private void BindButton(InputActionMap map, string actionName, System.Action<bool> setter)
|
||||
{
|
||||
var action = map.FindAction(actionName);
|
||||
|
||||
if (action == null)
|
||||
return;
|
||||
|
||||
action.performed += _ => setter(true);
|
||||
action.canceled += _ => setter(false);
|
||||
}
|
||||
|
||||
private void BindVector2(InputActionMap map, string actionName, System.Action<Vector2> setter)
|
||||
{
|
||||
var action = map.FindAction(actionName);
|
||||
|
||||
if (action == null)
|
||||
return;
|
||||
|
||||
action.performed += ctx => setter(ctx.ReadValue<Vector2>());
|
||||
action.canceled += _ => setter(Vector2.zero);
|
||||
}
|
||||
|
||||
private void BindAxis(InputActionMap map, string actionName, System.Action<float> setter)
|
||||
{
|
||||
var action = map.FindAction(actionName);
|
||||
|
||||
if (action == null)
|
||||
return;
|
||||
|
||||
action.performed += ctx => setter(ctx.ReadValue<float>());
|
||||
action.canceled += _ => setter(0f);
|
||||
}
|
||||
|
||||
public void EnableMap(ActionMapping actionMap)
|
||||
{
|
||||
_inputActionAsset.actionMaps[(int)actionMap].Enable();
|
||||
}
|
||||
|
||||
public void DisableMap(ActionMapping actionMap)
|
||||
{
|
||||
_inputActionAsset.actionMaps[(int)actionMap].Disable();
|
||||
}
|
||||
|
||||
public void DebugBindAction(int mapId, int actionId, System.Action<InputAction.CallbackContext> action) =>
|
||||
_inputActionAsset.actionMaps[mapId].actions[actionId].performed += action;
|
||||
|
||||
public void DebugUnbindAction(int mapId, int actionId, System.Action<InputAction.CallbackContext> action) =>
|
||||
_inputActionAsset.actionMaps[mapId].actions[actionId].performed -= action;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a985f6fee1a476280bc4e54af892714
|
||||
timeCreated: 1771430923
|
||||
Reference in new issue
Block a user