55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
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");
|
|
}
|
|
}
|
|
}
|
|
}
|