added main menu
This commit is contained in:
1 parent
b94c6e87c9
commit
12ec4f72f5
686 files changed
+128307
-817
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: 4d4c6fff3fc3400383bf26fb7e794adb
|
||||
timeCreated: 1769783705
|
||||
@@ -0,0 +1,22 @@
|
||||
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 SwitchCameraPressed { 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: c6e38cb038374afcb252feccd9a67d96
|
||||
timeCreated: 1769783664
|
||||
@@ -0,0 +1,81 @@
|
||||
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 SwitchCameraPressed { 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, "Look", v => LookInput = v);
|
||||
BindVector2(map, "Move", v => MoveInput = v);
|
||||
BindButton(map, "SwitchCamera", v => SwitchCameraPressed = 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);
|
||||
}
|
||||
|
||||
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: a0247f3e157a49e4a5fba94586bf7ac6
|
||||
timeCreated: 1769783734
|
||||
Reference in new issue
Block a user