您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
114 行
3.7 KiB
114 行
3.7 KiB
using System.Collections;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using Unity.Multiplayer.Samples.BossRoom.Server;
|
|
using Unity.Multiplayer.Samples.Utilities;
|
|
using Unity.Netcode;
|
|
using VContainer;
|
|
using static Unity.Multiplayer.Samples.BossRoom.ConnectionManager.ServerType;
|
|
|
|
namespace Unity.Multiplayer.Samples.BossRoom.Visual
|
|
{
|
|
/// <summary>
|
|
/// Provides backing logic for all of the UI that runs in the PostGame stage.
|
|
/// </summary>
|
|
public class PostGameUI : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Light m_SceneLight;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI m_WinEndMessage;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI m_LoseGameMessage;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI m_DedicatedServerCountdownText;
|
|
|
|
[SerializeField]
|
|
private GameObject m_ReplayButton;
|
|
|
|
[SerializeField]
|
|
private GameObject m_WaitOnHostMsg;
|
|
|
|
[SerializeField]
|
|
TransformVariable m_NetworkGameStateTransform;
|
|
|
|
[SerializeField]
|
|
private Color m_WinLightColor;
|
|
|
|
[SerializeField]
|
|
private Color m_LoseLightColor;
|
|
|
|
[Inject]
|
|
ConnectionManager m_ConnectionManager;
|
|
|
|
void Start()
|
|
{
|
|
// only hosts can restart the game, other players see a wait message
|
|
if (NetworkManager.Singleton.IsHost)
|
|
{
|
|
m_ReplayButton.SetActive(true);
|
|
m_WaitOnHostMsg.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
m_ReplayButton.SetActive(false);
|
|
m_WaitOnHostMsg.SetActive(true);
|
|
}
|
|
|
|
if (m_NetworkGameStateTransform && m_NetworkGameStateTransform.Value &&
|
|
m_NetworkGameStateTransform.Value.TryGetComponent(out NetworkGameState networkGameState))
|
|
{
|
|
SetPostGameUI(networkGameState.NetworkWinState.winState.Value);
|
|
}
|
|
|
|
if (m_ConnectionManager.IsConnectedToHost == DedicatedServer && !NetworkManager.Singleton.IsServer)
|
|
{
|
|
IEnumerator CountdownToNextGame()
|
|
{
|
|
var count = ServerPostGameState.SecondsToWaitForNewGame;
|
|
while (count > 0)
|
|
{
|
|
m_DedicatedServerCountdownText.text = count.ToString();
|
|
count--;
|
|
yield return new WaitForSeconds(1);
|
|
}
|
|
}
|
|
|
|
StartCoroutine(CountdownToNextGame());
|
|
}
|
|
}
|
|
|
|
void SetPostGameUI(WinState winState)
|
|
{
|
|
// Set end message and background color based last game outcome
|
|
if (winState == WinState.Win)
|
|
{
|
|
m_SceneLight.color = m_WinLightColor;
|
|
m_WinEndMessage.gameObject.SetActive(true);
|
|
m_LoseGameMessage.gameObject.SetActive(false);
|
|
}
|
|
else if (winState == WinState.Loss)
|
|
{
|
|
m_SceneLight.color = m_LoseLightColor;
|
|
m_WinEndMessage.gameObject.SetActive(false);
|
|
m_LoseGameMessage.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void OnPlayAgainClicked()
|
|
{
|
|
// this should only ever be called by the Host - so just go ahead and switch scenes
|
|
SceneLoaderWrapper.Instance.LoadScene(SceneNames.CharSelect, useNetworkSceneManager: true);
|
|
|
|
// FUTURE: could be improved to better support a dedicated server architecture
|
|
}
|
|
|
|
public void OnMainMenuClicked()
|
|
{
|
|
m_ConnectionManager.RequestShutdown();
|
|
}
|
|
}
|
|
}
|