개발자용 멀티플레이 기능 추가
This commit is contained in:
54
Assets/Scripts/QuickNetworkSetup.cs
Normal file
54
Assets/Scripts/QuickNetworkSetup.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Northbound
|
||||
{
|
||||
public class QuickNetworkSetup : MonoBehaviour
|
||||
{
|
||||
[Header("Quick Setup Options")]
|
||||
[Tooltip("Create a NetworkConnectionHelper component")]
|
||||
[SerializeField] private bool createConnectionHelper = true;
|
||||
|
||||
[Tooltip("Disable AutoHost to prevent auto-start")]
|
||||
[SerializeField] private bool disableAutoHost = true;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
SetupScene();
|
||||
}
|
||||
|
||||
private void SetupScene()
|
||||
{
|
||||
if (createConnectionHelper)
|
||||
{
|
||||
CreateConnectionHelper();
|
||||
}
|
||||
|
||||
if (disableAutoHost)
|
||||
{
|
||||
DisableAutoHost();
|
||||
}
|
||||
|
||||
Destroy(this);
|
||||
}
|
||||
|
||||
private void CreateConnectionHelper()
|
||||
{
|
||||
if (FindObjectOfType<NetworkConnectionHelper>() == null)
|
||||
{
|
||||
GameObject helperObj = new GameObject("NetworkConnectionHelper");
|
||||
helperObj.AddComponent<NetworkConnectionHelper>();
|
||||
Debug.Log("[QuickNetworkSetup] NetworkConnectionHelper created");
|
||||
}
|
||||
}
|
||||
|
||||
private void DisableAutoHost()
|
||||
{
|
||||
AutoHost[] autoHosts = FindObjectsByType<AutoHost>(FindObjectsSortMode.None);
|
||||
foreach (var autoHost in autoHosts)
|
||||
{
|
||||
autoHost.enabled = false;
|
||||
Debug.Log("[QuickNetworkSetup] AutoHost disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user