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

37 行
1.3 KiB

using UnityEngine;
using System.Collections;
using Unity.Collections;
using UnityEngine.UIElements;
namespace Unity.NetCode
{
public class NetcodeConnectionMonitor : MonoBehaviour
{
private Label m_ConsoleLabel;
private ScrollView m_ConsoleContainer;
private void OnEnable()
{
var root = GetComponent<UIDocument>().rootVisualElement;
m_ConsoleLabel = root.Q<Label>("monitor-console-label");
m_ConsoleContainer = root.Q<ScrollView>("content-scroll-view");
m_ConsoleLabel.RegisterValueChangedCallback(OnTextUpdated);
}
private void OnTextUpdated(ChangeEvent<string> evt)
{
StartCoroutine(ScrollToTheEnd());
}
private IEnumerator ScrollToTheEnd()
{
yield return new WaitForSeconds(0.1f);
m_ConsoleContainer.verticalScroller.value = m_ConsoleContainer.verticalScroller.highValue;
}
public void AddEntry(FixedString64Bytes playerName, ConnectionState.State connectionState)
{
var color = connectionState == ConnectionState.State.Connected ? "#76D36FFF" : "#FF80BFFF";
m_ConsoleLabel.text += $"\n{playerName} has <color={color}>{connectionState}</color>";
}
}
}