Nilton Constantino f31e642009
added action belt
2026-06-09 17:07:43 +01:00

74 lines
2.7 KiB
C#

using Intrepid.Diagnostics;
using Intrepid.Gameplay.Entities.Player.Sentinel;
using Intrepid.Utilities;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Intrepid.Integration.Input
{
[CreateAssetMenu(fileName = "Input Action Service", menuName = "GON/Input Actions Service")]
public class InputService : SingletonScriptableObject<InputService>
{
private InputActions InputActions { get; set; }
public InputSchema CurrentInputSchema { get; private set; }
public InputLocking Locking { get; private set; }
protected override void WhenInstantiate(InputService singleton)
{
singleton.InputActions = new InputActions();
singleton.Locking = new InputLocking();
singleton.CurrentInputSchema = InputSchema.None;
}
public void OnlyGamepad(bool onlyGamepad)
{
if (onlyGamepad)
{
InputSystem.DisableDevice(Keyboard.current);
InputSystem.DisableDevice(Mouse.current);
}
else
{
InputSystem.EnableDevice(Keyboard.current);
InputSystem.EnableDevice(Mouse.current);
}
}
public void ChangeInputSchema(InputSchema schema)
{
if (schema == CurrentInputSchema) return;
CurrentInputSchema = schema;
switch (schema)
{
case InputSchema.None:
InputActions.Disable();
break;
case InputSchema.Sentinel:
InputActions.sentinel.Enable();
break;
default:
InputActions.Disable();
CurrentInputSchema = InputSchema.None;
DLogger.LogError($"Unknown input schema: {schema}");
break;
}
}
public SentinelInputs BuildSentinelInputs()
{
return new SentinelInputs
{
Movement = () => Locking.IsNotLocked
? InputActions.sentinel.Movement.ReadValue<Vector2>()
: Vector2.zero,
Interact = () => Locking.IsNotLocked && InputActions.sentinel.Interact.WasPressedThisFrame(),
DPadLeft = () => Locking.IsNotLocked && InputActions.sentinel.DPadLeft.WasPressedThisFrame(),
DPadRight = () => Locking.IsNotLocked && InputActions.sentinel.DPadRight.WasPressedThisFrame(),
Dash = () => Locking.IsNotLocked && InputActions.sentinel.Dash.WasPressedThisFrame(),
// debug
Reset = () => Locking.IsNotLocked && InputActions.sentinel.Reset.WasPressedThisFrame(),
};
}
}
}