using System; namespace Mirror { /// /// Provides profiling information from mirror /// A profiler can subscribe to these events and /// present the data in a friendly way to the user /// public static class NetworkDiagnostics { /// /// Describes an outgoing message /// public readonly struct MessageInfo { /// /// The message being sent /// public readonly NetworkMessage message; /// /// channel through which the message was sent /// public readonly int channel; /// /// how big was the message (does not include transport headers) /// public readonly int bytes; /// /// How many connections was the message sent to /// If an object has a lot of observers this count could be high /// public readonly int count; internal MessageInfo(NetworkMessage message, int channel, int bytes, int count) { this.message = message; this.channel = channel; this.bytes = bytes; this.count = count; } } #region Out messages /// /// Event that gets raised when Mirror sends a message /// Subscribe to this if you want to diagnose the network /// public static event Action OutMessageEvent; internal static void OnSend(T message, int channel, int bytes, int count) where T : NetworkMessage { if (count > 0 && OutMessageEvent != null) { MessageInfo outMessage = new MessageInfo(message, channel, bytes, count); OutMessageEvent?.Invoke(outMessage); } } #endregion #region In messages /// /// Event that gets raised when Mirror receives a message /// Subscribe to this if you want to profile the network /// public static event Action InMessageEvent; internal static void OnReceive(T message, int channel, int bytes) where T : NetworkMessage { if (InMessageEvent != null) { MessageInfo inMessage = new MessageInfo(message, channel, bytes, 1); InMessageEvent?.Invoke(inMessage); } } #endregion } }