Petition-to-the-Gods-V3/Assets/Scripts/Server/NetworkGameManager.cs
2025-11-18 14:54:11 +08:00

48 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using Mirror;
public class NetworkGameManager : NetworkManager
{
public static NetworkGameManager Instance;
//public static NetworkConnectionToClient CurrentClient;
void Awake()
{
if (Instance == null)
{
Instance = this;
//CurrentClient = null;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
public override void OnStartServer()
{
base.OnStartServer();
Debug.Log("Server 已啟動");
}
public override void OnServerConnect(NetworkConnectionToClient conn)
{
base.OnServerConnect(conn);
Debug.Log($"客戶端已連接: {conn.connectionId}");
}
public override void OnServerDisconnect(NetworkConnectionToClient conn)
{
base.OnServerDisconnect(conn);
Debug.Log($"客戶端已斷開: {conn.connectionId}");
}
// 覆寫這個方法來避免自動生成 Player
public override void OnServerAddPlayer(NetworkConnectionToClient conn)
{
// 不自動生成 Player只是記錄連接
Debug.Log($"客戶端請求加入,但 Server 模式不需要生成 Player: {conn.connectionId}");
}
}