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