55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
using Unity.Netcode;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
namespace Northbound
|
|
{
|
|
public abstract class InputActionManager : NetworkBehaviour
|
|
{
|
|
protected PlayerInputActions _inputActions;
|
|
|
|
public override void OnNetworkSpawn()
|
|
{
|
|
base.OnNetworkSpawn();
|
|
|
|
if (!IsOwner) return;
|
|
|
|
InitializeInputActions();
|
|
}
|
|
|
|
public override void OnNetworkDespawn()
|
|
{
|
|
if (IsOwner && _inputActions != null)
|
|
{
|
|
UnbindInputActions();
|
|
_inputActions.Disable();
|
|
_inputActions.Dispose();
|
|
_inputActions = null;
|
|
}
|
|
|
|
base.OnNetworkDespawn();
|
|
}
|
|
|
|
public override void OnDestroy()
|
|
{
|
|
if (_inputActions != null)
|
|
{
|
|
_inputActions.Dispose();
|
|
_inputActions = null;
|
|
}
|
|
base.OnDestroy();
|
|
}
|
|
|
|
protected virtual void InitializeInputActions()
|
|
{
|
|
_inputActions = new PlayerInputActions();
|
|
_inputActions.Enable();
|
|
BindInputActions();
|
|
}
|
|
|
|
protected abstract void BindInputActions();
|
|
|
|
protected abstract void UnbindInputActions();
|
|
}
|
|
}
|