네트워크 멀티플레이 환경 문제 수정
관련 문제가 다시 발생하면 이 커밋으로 돌아올 것
This commit is contained in:
50
Assets/Scripts/ShortcutNetworkStarter.cs
Normal file
50
Assets/Scripts/ShortcutNetworkStarter.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using Unity.Netcode;
|
||||
|
||||
namespace Northbound
|
||||
{
|
||||
public class ShortcutNetworkStarter : MonoBehaviour
|
||||
{
|
||||
[Header("Input Actions")]
|
||||
[SerializeField] private InputActionReference startAsClientAction;
|
||||
|
||||
private bool _isClientStarted = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (startAsClientAction != null && startAsClientAction.action != null)
|
||||
{
|
||||
startAsClientAction.action.performed += StartAsClient;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (startAsClientAction != null && startAsClientAction.action != null)
|
||||
{
|
||||
startAsClientAction.action.performed -= StartAsClient;
|
||||
}
|
||||
}
|
||||
|
||||
private void StartAsClient(InputAction.CallbackContext context)
|
||||
{
|
||||
if (NetworkManager.Singleton == null)
|
||||
{
|
||||
Debug.LogError("[ShortcutNetworkStarter] NetworkManager.Singleton이 null입니다!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (NetworkManager.Singleton.IsClient)
|
||||
{
|
||||
Debug.Log("[ShortcutNetworkStarter] 이미 클라이언트 모드입니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
_isClientStarted = true;
|
||||
|
||||
Debug.Log("[ShortcutNetworkStarter] 클라이언트 모드로 시작합니다...");
|
||||
NetworkManager.Singleton.StartClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user