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

33 行
1.1 KiB

using Unity.Burst;
using Unity.Entities;
namespace Unity.NetCode.Extensions
{
[UpdateAfter(typeof(UpdateFPSData))]
[UpdateInGroup(typeof(NetCodePanelStats))]
public partial struct UpdatePingData : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<PlayerStats>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var playerStats = SystemAPI.GetSingletonRW<PlayerStats>().ValueRW;
if (!playerStats.ShouldUpdate)
return;
foreach (var (networkId, networkSnapshotAck) in SystemAPI.Query<RefRO<NetworkId>, RefRO<NetworkSnapshotAck>>())
{
if (playerStats.NetworkId == networkId.ValueRO.Value)
{
playerStats.EstimatedRTT = (int)networkSnapshotAck.ValueRO.EstimatedRTT;
playerStats.DeviationRTT = (int)networkSnapshotAck.ValueRO.DeviationRTT;
}
}
SystemAPI.SetSingleton(playerStats);
}
}
}