using System.Collections.Generic; using FishNet.Managing.Statistic; using FishNet.Transporting; using GameKit.Dependencies.Utilities; using UnityEngine; namespace FishNet.Editing.NetworkProfiler { /// /// Container for multiple Packets of the same type. /// public class PacketGroup : IResettable { /// /// PacketId of this metric. /// public PacketId PacketId { get; private set; } = PacketId.Unset; /// /// Bytes of all packets using PacketId. /// public ulong Bytes { get; private set; } /// /// Percent Bytes is when compared against Bytes of other PacketMetrics. /// /// This can only be completed after all Packet entries for each PacketId are added. public float Percent { get; private set; } /// /// True if PacketId is for unspecified packets. /// public bool IsUnspecifiedPacketId => PacketId == NetworkTrafficStatistics.UNSPECIFIED_PACKETID; /// /// Currently added packets. /// private List _packets = new(); public void Initialize(PacketId packetId) { PacketId = packetId; } /// /// Adds traffic from a specified packetId. /// public void AddPacket(string details, ulong bytes, GameObject gameObject) { Bytes += bytes; _packets.Add(new(details, bytes, gameObject)); } /// /// Sets Percent using Bytes against allPacketGroupBytes. /// public void SetPercent(ulong allPacketGroupBytes) { //Prevent divide by 0. if (Bytes == 0) Percent = 0; else Percent = (float)Bytes / allPacketGroupBytes; } public void ResetState() { PacketId = PacketId.Unset; Bytes = 0; Percent = 0f; _packets.Clear(); } public void InitializeState() { } } }