using UnityEngine;
using Unity.Netcode;
public class SmartAutoHost : MonoBehaviour
{
#if UNITY_EDITOR
private void Start()
{
if (NetworkManager.Singleton == null)
{
Debug.LogError("[SmartAutoHost] NetworkManager not found!");
return;
}
if (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsClient)
{
return;
}
bool isMainEditor = IsMainEditor();
if (isMainEditor)
{
NetworkManager.Singleton.StartHost();
Debug.Log("[SmartAutoHost] MAIN EDITOR → Starting as HOST");
}
else
{
NetworkManager.Singleton.StartClient();
Debug.Log("[SmartAutoHost] SECONDARY EDITOR → Connecting as CLIENT");
}
}
private bool IsMainEditor()
{
string[] args = System.Environment.GetCommandLineArgs();
return System.Array.Exists(args, arg => arg == "-mainEditor");
}
#else
private void Start()
{
// 빌드된 버전은 항상 클라이언트
if (NetworkManager.Singleton != null &&
!NetworkManager.Singleton.IsServer &&
!NetworkManager.Singleton.IsClient)
{
NetworkManager.Singleton.StartClient();
Debug.Log("[SmartAutoHost] Build → Connecting as CLIENT");
}
}
#endif
}