Files
tcg-client/Assets/TcgEngine/Scripts/Menu/MatchmakingPanel.cs
2025-10-16 11:12:30 +08:00

73 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using TcgEngine.Client;
using TcgEngine;
namespace TcgEngine.UI
{
/// <summary>
/// Matchmaking panel is just a loading panel that displays how many players are found yet
/// </summary>
public class MatchmakingPanel : UIPanel
{
public Text text;
public Text players_txt;
public Text code_txt;
private static MatchmakingPanel instance;
protected override void Awake()
{
base.Awake();
instance = this;
}
protected override void Start()
{
base.Start();
code_txt.text = "";
}
protected override void Update()
{
base.Update();
if (GameClientMatchmaker.Get().IsConnected())
text.text = "正在寻找对手...";
else
text.text = "正在连接到服务器...";
code_txt.text = "";
string group = GameClientMatchmaker.Get().GetGroup();
if (group != null && group.StartsWith("code_"))
code_txt.text = group.Replace("code_", "");
}
public void SetCount(int players)
{
if (players_txt != null)
players_txt.text = players.ToString() + "/" + GameClientMatchmaker.Get().GetNbPlayers();
}
public void OnClickCancel()
{
GameClientMatchmaker.Get().StopMatchmaking();
Hide();
}
public override void Show(bool instant = false)
{
base.Show(instant);
if (players_txt != null)
players_txt.text = "";
}
public static MatchmakingPanel Get()
{
return instance;
}
}
}