네트워크 멀티플레이 대응
This commit is contained in:
54
Assets/Scripts/InputActionManager.cs
Normal file
54
Assets/Scripts/InputActionManager.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user