몬스터와 크립에 네트워크 관련 컴포넌트가 없는 문제 수정 포탈/캠프와 몬스터/크립 간의 계층 구조 해제 - 네트워크 오브젝트끼리 계층 구조로 둘 수 없음
116 lines
4.1 KiB
C#
116 lines
4.1 KiB
C#
using UnityEngine;
|
|
using Unity.Netcode;
|
|
|
|
namespace Northbound
|
|
{
|
|
/// <summary>
|
|
/// Simple monitor for network restarts
|
|
/// Detects if Unity Netcode is shutting down repeatedly
|
|
/// </summary>
|
|
public class SimpleNetworkMonitor : MonoBehaviour
|
|
{
|
|
[Header("Settings")]
|
|
[SerializeField] private bool enableOnStart = true;
|
|
[SerializeField] private float checkInterval = 2f;
|
|
|
|
private NetworkManager _networkManager;
|
|
private float _lastCheckTime;
|
|
private int _serverStopCount = 0;
|
|
private int _serverStartCount = 0;
|
|
private float _lastServerStartTime = 0f;
|
|
private int _eventsLogged = 0;
|
|
|
|
private void Start()
|
|
{
|
|
if (enableOnStart)
|
|
{
|
|
_networkManager = NetworkManager.Singleton;
|
|
Debug.Log("[SimpleMonitor] Simple Network Monitor started");
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_networkManager == null)
|
|
{
|
|
_networkManager = NetworkManager.Singleton;
|
|
}
|
|
|
|
if (Time.time - _lastCheckTime >= checkInterval)
|
|
{
|
|
_lastCheckTime = Time.time;
|
|
CheckNetworkStatus();
|
|
}
|
|
}
|
|
|
|
private void CheckNetworkStatus()
|
|
{
|
|
if (_networkManager == null)
|
|
{
|
|
Debug.LogWarning("[SimpleMonitor] NetworkManager not found");
|
|
return;
|
|
}
|
|
|
|
bool isServer = _networkManager.IsServer;
|
|
bool isClient = _networkManager.IsClient;
|
|
bool isHost = _networkManager.IsHost;
|
|
|
|
if (isServer && !isClient && _eventsLogged < 3)
|
|
{
|
|
_serverStartCount++;
|
|
_lastServerStartTime = Time.time;
|
|
Debug.Log("[SimpleMonitor] Server started (Count: " + _serverStartCount + ")");
|
|
_eventsLogged++;
|
|
}
|
|
|
|
if (!isServer && !isClient && _lastServerStartTime > 0f && _eventsLogged < 50)
|
|
{
|
|
float uptime = Time.time - _lastServerStartTime;
|
|
_serverStopCount++;
|
|
Debug.LogWarning("[SimpleMonitor] Server stopped (Count: " + _serverStopCount + ", Uptime: " + uptime.ToString("F1") + "s)");
|
|
_eventsLogged++;
|
|
|
|
if (_serverStopCount >= 3)
|
|
{
|
|
Debug.LogError("[SimpleMonitor] SERVER STOPPED " + _serverStopCount + " TIMES!");
|
|
Debug.LogError("[SimpleMonitor] This is why port closes!");
|
|
Debug.LogError("[SimpleMonitor] Something is calling NetworkManager.Shutdown()");
|
|
}
|
|
}
|
|
|
|
if (isServer && _serverStartCount > 0)
|
|
{
|
|
if (_eventsLogged % 10 == 0)
|
|
{
|
|
float uptime = Time.time - _lastServerStartTime;
|
|
Debug.Log("[SimpleMonitor] Server uptime: " + uptime.ToString("F1") + "s");
|
|
_eventsLogged++;
|
|
}
|
|
}
|
|
}
|
|
|
|
[ContextMenu("Reset Counters")]
|
|
public void ResetCounters()
|
|
{
|
|
_serverStopCount = 0;
|
|
_serverStartCount = 0;
|
|
_lastServerStartTime = 0f;
|
|
_eventsLogged = 0;
|
|
Debug.Log("[SimpleMonitor] Counters reset");
|
|
}
|
|
|
|
[ContextMenu("Show Stats")]
|
|
public void ShowStats()
|
|
{
|
|
Debug.Log("=== SIMPLE MONITOR STATS ===");
|
|
Debug.Log("Server Stops: " + _serverStopCount);
|
|
Debug.Log("Server Starts: " + _serverStartCount);
|
|
Debug.Log("NetworkManager:");
|
|
Debug.Log(" IsServer: " + (_networkManager != null ? _networkManager.IsServer.ToString() : "null"));
|
|
Debug.Log(" IsClient: " + (_networkManager != null ? _networkManager.IsClient.ToString() : "null"));
|
|
Debug.Log(" IsHost: " + (_networkManager != null ? _networkManager.IsHost.ToString() : "null"));
|
|
Debug.Log("============================");
|
|
}
|
|
}
|
|
}
|