您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

53 行
1.4 KiB

using System;
using TMPro;
using UnityEngine;
namespace LobbyRelaySample.UI
{
/// <summary>
/// Watches a lobby or relay code for updates, displaying the current code to lobby members.
/// </summary>
public class DisplayCodeUI : UIPanelBase
{
public enum CodeType { Lobby = 0, Relay = 1 }
[SerializeField]
TMP_InputField m_outputText;
[SerializeField]
CodeType m_codeType;
void LobbyCodeChanged(string newCode)
{
if (!string.IsNullOrEmpty(newCode))
{
m_outputText.text = newCode;
Show();
}
else
{
Hide();
}
}
public override void Start()
{
base.Start();
if(m_codeType==CodeType.Lobby)
Manager.LocalLobby.LobbyCode.onChanged += LobbyCodeChanged;
if(m_codeType==CodeType.Relay)
Manager.LocalLobby.RelayCode.onChanged += LobbyCodeChanged;
}
void OnDestroy()
{
if (Manager == null)
return;
if(m_codeType==CodeType.Lobby)
Manager.LocalLobby.LobbyCode.onChanged -= LobbyCodeChanged;
if(m_codeType==CodeType.Relay)
Manager.LocalLobby.RelayCode.onChanged -= LobbyCodeChanged;
}
}
}