41 lines
989 B
C#
41 lines
989 B
C#
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using Mirror;
|
|
using System.Collections;
|
|
|
|
public class ServerInitSceneController : MonoBehaviour
|
|
{
|
|
void Start()
|
|
{
|
|
InitializeServer();
|
|
}
|
|
|
|
void InitializeServer()
|
|
{
|
|
Debug.Log("初始化 Server...");
|
|
|
|
// 啟動 Server
|
|
if (NetworkGameManager.Instance != null)
|
|
{
|
|
NetworkGameManager.Instance.StartServer();
|
|
|
|
// 等待一秒後自動連接本地 Client
|
|
StartCoroutine(AutoConnectLocalClient());
|
|
}
|
|
}
|
|
|
|
IEnumerator AutoConnectLocalClient()
|
|
{
|
|
yield return new WaitForSeconds(1f);
|
|
|
|
if (NetworkGameManager.Instance != null)
|
|
{
|
|
NetworkGameManager.Instance.StartClient();
|
|
Debug.Log("本地 Client 已連接到 Server");
|
|
}
|
|
|
|
// 初始化完成,跳到 ServerHomeScene
|
|
yield return new WaitForSeconds(0.5f);
|
|
SceneManager.LoadScene("ServerHomeScene");
|
|
}
|
|
} |