245 lines
10 KiB
C#
245 lines
10 KiB
C#
using UnityEngine;
|
|
using Unity.Netcode;
|
|
|
|
namespace Northbound
|
|
{
|
|
/// <summary>
|
|
/// Quick test to verify NetworkManager is working and accessible
|
|
/// </summary>
|
|
public class NetworkManagerQuickTest : MonoBehaviour
|
|
{
|
|
[Header("Test Settings")]
|
|
[SerializeField] private bool runTestOnStart = true;
|
|
[SerializeField] private bool showDetailedLogs = true;
|
|
|
|
private void Start()
|
|
{
|
|
if (runTestOnStart)
|
|
{
|
|
RunQuickTest();
|
|
}
|
|
}
|
|
|
|
[ContextMenu("Run Quick NetworkManager Test")]
|
|
public void RunQuickTest()
|
|
{
|
|
Debug.Log("<color=cyan>=== NETWORKMANAGER QUICK TEST ===</color>");
|
|
|
|
TestNetworkManagerExists();
|
|
TestPlayerPrefab();
|
|
TestTransport();
|
|
TestConnectionHandlers();
|
|
|
|
Debug.Log("<color=green>=== TEST COMPLETE ===</color>");
|
|
}
|
|
|
|
private void TestNetworkManagerExists()
|
|
{
|
|
Debug.Log("<color=yellow>[1/4] Testing NetworkManager Existence...</color>");
|
|
|
|
NetworkManager nm = NetworkManager.Singleton;
|
|
|
|
if (nm == null)
|
|
{
|
|
Debug.LogError("<color=red>✗ NetworkManager.Singleton is NULL!</color>");
|
|
Debug.LogError("This means:");
|
|
Debug.LogError("1. NetworkManager GameObject is not in scene");
|
|
Debug.LogError("2. NetworkManager component is missing");
|
|
Debug.LogError("3. NetworkManager hasn't been initialized yet");
|
|
return;
|
|
}
|
|
|
|
Debug.Log("<color=green>✓ NetworkManager found!</color>");
|
|
Debug.Log(" IsServer: " + nm.IsServer);
|
|
Debug.Log(" IsClient: " + nm.IsClient);
|
|
Debug.Log(" IsHost: " + nm.IsHost);
|
|
Debug.Log(" IsConnectedClient: " + nm.IsConnectedClient);
|
|
Debug.Log(" LocalClientId: " + nm.LocalClientId);
|
|
}
|
|
|
|
private void TestPlayerPrefab()
|
|
{
|
|
Debug.Log("<color=yellow>[2/4] Testing Player Prefab...</color>");
|
|
|
|
NetworkManager nm = NetworkManager.Singleton;
|
|
if (nm == null)
|
|
{
|
|
Debug.LogError("<color=red>✗ Can't test - NetworkManager is null</color>");
|
|
return;
|
|
}
|
|
|
|
if (nm.NetworkConfig == null)
|
|
{
|
|
Debug.LogError("<color=red>✗ NetworkConfig is null!</color>");
|
|
return;
|
|
}
|
|
|
|
GameObject playerPrefab = nm.NetworkConfig.PlayerPrefab;
|
|
|
|
if (playerPrefab == null)
|
|
{
|
|
Debug.LogError("<color=red>✗ Player Prefab is NOT assigned!</color>");
|
|
Debug.LogError("→ This is the #1 reason servers don't start!");
|
|
Debug.LogError("→ FIX: Select NetworkManager → Network Config → Player Prefab");
|
|
Debug.LogError("→ Drag your Player Prefab from Project to that field");
|
|
return;
|
|
}
|
|
|
|
Debug.Log("<color=green>✓ Player Prefab assigned: " + playerPrefab.name + "</color>");
|
|
|
|
var networkObject = playerPrefab.GetComponent<Unity.Netcode.NetworkObject>();
|
|
if (networkObject == null)
|
|
{
|
|
Debug.LogWarning("<color=yellow>⚠ Player Prefab has NO NetworkObject!</color>");
|
|
Debug.LogWarning("→ Add NetworkObject component to Player Prefab");
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("<color=green>✓ Player Prefab has NetworkObject</color>");
|
|
}
|
|
}
|
|
|
|
private void TestTransport()
|
|
{
|
|
Debug.Log("<color=yellow>[3/4] Testing Unity Transport...</color>");
|
|
|
|
NetworkManager nm = NetworkManager.Singleton;
|
|
if (nm == null)
|
|
{
|
|
Debug.LogError("<color=red>✗ Can't test - NetworkManager is null</color>");
|
|
return;
|
|
}
|
|
|
|
var transport = nm.GetComponent<Unity.Netcode.Transports.UTP.UnityTransport>();
|
|
|
|
if (transport == null)
|
|
{
|
|
Debug.LogError("<color=red>✗ Unity Transport not found on NetworkManager!</color>");
|
|
Debug.LogError("→ FIX: Add Unity Transport component to NetworkManager GameObject");
|
|
return;
|
|
}
|
|
|
|
Debug.Log("<color=green>✓ Unity Transport found!</color>");
|
|
Debug.Log(" Port: " + transport.ConnectionData.Port);
|
|
Debug.Log(" Address: " + transport.ConnectionData.Address);
|
|
Debug.Log(" ServerListenAddress: " + transport.ConnectionData.ServerListenAddress);
|
|
|
|
if (transport.ConnectionData.Port <= 0)
|
|
{
|
|
Debug.LogWarning("<color=yellow>⚠ Transport Port is not set (0)!</color>");
|
|
Debug.LogWarning("→ FIX: Set Port to 40445 in Unity Transport component");
|
|
}
|
|
|
|
if (transport.ConnectionData.Address == "127.0.0.1")
|
|
{
|
|
Debug.LogError("<color=red>✗ Transport Address is 127.0.0.1!</color>");
|
|
Debug.LogError("→ This BLOCKS all remote connections!");
|
|
Debug.LogError("→ FIX: Change Address to 0.0.0.0");
|
|
}
|
|
else if (transport.ConnectionData.Address == "0.0.0.0")
|
|
{
|
|
Debug.Log("<color=green>✓ Transport Address is 0.0.0.0 (accepts all connections)</color>");
|
|
}
|
|
}
|
|
|
|
private void TestConnectionHandlers()
|
|
{
|
|
Debug.Log("<color=yellow>[4/4] Testing Connection Handlers...</color>");
|
|
|
|
NetworkConnectionHandler handler = FindObjectOfType<NetworkConnectionHandler>();
|
|
|
|
if (handler == null)
|
|
{
|
|
Debug.LogWarning("<color=yellow>⚠ NetworkConnectionHandler not found!</color>");
|
|
Debug.LogWarning("→ Manual player spawning may not work");
|
|
Debug.LogWarning("→ FIX: Add NetworkConnectionHandler component to scene");
|
|
return;
|
|
}
|
|
|
|
Debug.Log("<color=green>✓ NetworkConnectionHandler found!</color>");
|
|
Debug.Log("→ Manual player spawning should work");
|
|
|
|
PlayerSpawnPoint[] spawnPoints = FindObjectsByType<PlayerSpawnPoint>(FindObjectsSortMode.None);
|
|
if (spawnPoints.Length > 0)
|
|
{
|
|
Debug.Log("<color=green>✓ Found " + spawnPoints.Length + " Player Spawn Point(s)</color>");
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("<color=yellow>⚠ No Player Spawn Points found!</color>");
|
|
Debug.LogWarning("→ Players may spawn at default position");
|
|
}
|
|
}
|
|
|
|
[ContextMenu("Generate Setup Report")]
|
|
public void GenerateSetupReport()
|
|
{
|
|
Debug.Log("=== NETWORKMANAGER SETUP REPORT ===");
|
|
Debug.Log("");
|
|
Debug.Log("CURRENT STATUS:");
|
|
NetworkManager nm = NetworkManager.Singleton;
|
|
|
|
if (nm == null)
|
|
{
|
|
Debug.LogError("NetworkManager: NOT FOUND (NULL)");
|
|
Debug.LogError("");
|
|
Debug.LogError("CRITICAL ISSUE:");
|
|
Debug.LogError("1. NetworkManager GameObject not in scene");
|
|
Debug.LogError("2. NetworkManager component missing");
|
|
Debug.LogError("3. NetworkManager not initialized");
|
|
Debug.LogError("");
|
|
Debug.LogError("QUICK FIX:");
|
|
Debug.LogError("1. Check your scene for NetworkManager GameObject");
|
|
Debug.LogError("2. Add NetworkManager component if missing");
|
|
Debug.LogError("3. Check Console for initialization errors");
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("NetworkManager: FOUND");
|
|
Debug.Log("IsServer: " + nm.IsServer);
|
|
Debug.Log("IsClient: " + nm.IsClient);
|
|
Debug.Log("IsHost: " + nm.IsHost);
|
|
|
|
if (nm.NetworkConfig != null)
|
|
{
|
|
GameObject playerPrefab = nm.NetworkConfig.PlayerPrefab;
|
|
if (playerPrefab == null)
|
|
{
|
|
Debug.LogError("");
|
|
Debug.LogError("⚠ CRITICAL: Player Prefab NOT assigned!");
|
|
Debug.LogError("This is the #1 cause of servers not starting!");
|
|
Debug.LogError("");
|
|
Debug.LogError("FIX IMMEDIATELY:");
|
|
Debug.LogError("1. Select NetworkManager in scene");
|
|
Debug.LogError("2. Inspector → Network Config → Player Prefab");
|
|
Debug.LogError("3. Drag Player Prefab from Project to that field");
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Player Prefab: ASSIGNED (" + playerPrefab.name + ")");
|
|
}
|
|
}
|
|
|
|
var transport = nm.GetComponent<Unity.Netcode.Transports.UTP.UnityTransport>();
|
|
if (transport != null)
|
|
{
|
|
Debug.Log("Transport Port: " + transport.ConnectionData.Port);
|
|
Debug.Log("Transport Address: " + transport.ConnectionData.Address);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("Unity Transport: NOT FOUND");
|
|
}
|
|
}
|
|
|
|
Debug.Log("");
|
|
Debug.Log("NEXT STEPS:");
|
|
Debug.Log("1. If Player Prefab is NULL: Assign it immediately!");
|
|
Debug.Log("2. Check NetworkManagerValidator → Validate");
|
|
Debug.Log("3. Use ForceTransportBinding → Force Then Start Host");
|
|
Debug.Log("4. Test on yougetsignal");
|
|
Debug.Log("===============================");
|
|
}
|
|
}
|
|
}
|