我正在尝试使用 DOTsSample Unity 项目并希望使用此 NetworkStatistics 类(https://github.com/Unity-Technologies/DOTSSample/blob/master/Assets/Scripts/Game/Main/NetworkStatisticsClient.cs)并尝试编写一个脚本来显示我游戏中的网络统计信息,但问题是它总是返回 0。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NetStats : MonoBehaviour
{
// Start is called before the first frame update
NetworkStatisticsClient networkStatisticsClient;
private SocketTransport m_Transport;
private NetworkClient m_NetworkClient;
void Start()
{
m_Transport = new SocketTransport();
m_Transport.Connect("127.0.0.1",80);
m_NetworkClient = new NetworkClient(m_Transport);
if (Application.isEditor || Game.game.buildId == "AutoBuild")
NetworkClient.clientVerifyProtocol.Value = "0";
m_NetworkClient.UpdateClientConfig();
networkStatisticsClient = new NetworkStatisticsClient(m_NetworkClient);
}
// Update is called once per frame
void Update()
{
//Client isConnected is False thus, the connection is not establishment is not correct
Debug.Log("Rtt: " + m_NetworkClient.isConnected + networkStatisticsClient.rtt.average);
}
}
有人可以帮我吗?