Space-Smash-Out/Assets/Scripts/Input/ShipInputHandler.cs
Jakob Feldmann 6d89d9d48e fix: introduced assetbundles, instead of reading from folder
Reading Assets from folders was only possible in Editor over  LoadAssetFromPath. Now I'm using asset bundles for ScriptedObjects and Audio Prefabs, when the project is built.
When in Editor the folders are still used for convenience (can make changes to assets without rebuilding asset bundles)
2024-04-18 20:23:17 +02:00

67 lines
1.7 KiB
C#

using System;
using Managers;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Users;
using static InputActionMaps;
namespace ShipHandling
{
public class ShipInputHandler : IDisposable, IPlayerActions
{
private ShipState state;
private readonly InputActionMaps inputActions = new();
private readonly string controlScheme;
private readonly InputDevice device;
public InputUser user;
public ShipInputHandler()
{
}
public ShipInputHandler(ShipState shipState, InputDevice device, string controlScheme)
{
state = shipState;
this.controlScheme = controlScheme;
this.device = device;
user = InputUser.PerformPairingWithDevice(device);
user.AssociateActionsWithUser(inputActions);
user.ActivateControlScheme(controlScheme);
inputActions.Player.SetCallbacks(this);
inputActions.Player.Enable();
}
public void ReActivateInput(Ship ship)
{
// user = InputUser.PerformPairingWithDevice(device);
// user.AssociateActionsWithUser(inputActions);
// user.ActivateControlScheme(controlScheme);
this.state = ship.state;
inputActions.Player.SetCallbacks(this);
inputActions.Player.Enable();
}
public void OnThrust(InputAction.CallbackContext context)
{
state.thrustInput = context.ReadValue<float>();
}
public void OnSteer(InputAction.CallbackContext context)
{
state.steerInput = context.ReadValue<float>();
}
public void OnBoost(InputAction.CallbackContext context)
{
state.boostInput = context.ReadValue<float>();
}
public void Dispose()
{
inputActions.Player.Disable();
inputActions.Player.RemoveCallbacks(this);
user.UnpairDevicesAndRemoveUser();
}
}
}