您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
54 行
1.6 KiB
54 行
1.6 KiB
using System.Collections;
|
|
using Unity.Multiplayer.Samples.Utilities;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
|
|
namespace Unity.Multiplayer.Samples.BossRoom.Server
|
|
{
|
|
[RequireComponent(typeof(NetcodeHooks))]
|
|
public class ServerPostGameState : GameStateBehaviour
|
|
{
|
|
[SerializeField]
|
|
NetcodeHooks m_NetcodeHooks;
|
|
|
|
public const int SecondsToWaitForNewGame = 5;
|
|
|
|
public override GameState ActiveState => GameState.PostGame;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
m_NetcodeHooks.OnNetworkSpawnHook += OnNetworkSpawn;
|
|
}
|
|
|
|
void OnNetworkSpawn()
|
|
{
|
|
if (!NetworkManager.Singleton.IsServer)
|
|
{
|
|
enabled = false;
|
|
}
|
|
else
|
|
{
|
|
if (DedicatedServerUtilities.IsServerBuildTarget)
|
|
{
|
|
IEnumerator WaitAndStartNewGame()
|
|
{
|
|
DedicatedServerUtilities.Log($"Waiting a {SecondsToWaitForNewGame} seconds until new game");
|
|
yield return new WaitForSeconds(SecondsToWaitForNewGame);
|
|
SceneLoaderWrapper.Instance.LoadScene(SceneNames.CharSelect, useNetworkSceneManager: true);
|
|
}
|
|
|
|
StartCoroutine(WaitAndStartNewGame());
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
|
|
m_NetcodeHooks.OnNetworkSpawnHook -= OnNetworkSpawn;
|
|
}
|
|
}
|
|
}
|