Mirror Networking
NetworkDiagnostics.cs
1using System;
2
3namespace Mirror
4{
6 public static class NetworkDiagnostics
7 {
9 public readonly struct MessageInfo
10 {
12 public readonly NetworkMessage message;
14 public readonly int channel;
16 public readonly int bytes;
18 public readonly int count;
19
20 internal MessageInfo(NetworkMessage message, int channel, int bytes, int count)
21 {
22 this.message = message;
23 this.channel = channel;
24 this.bytes = bytes;
25 this.count = count;
26 }
27 }
28
30 public static event Action<MessageInfo> OutMessageEvent;
31
33 public static event Action<MessageInfo> InMessageEvent;
34
35 // RuntimeInitializeOnLoadMethod -> fast playmode without domain reload
36 [UnityEngine.RuntimeInitializeOnLoadMethod]
37 static void ResetStatics()
38 {
39 InMessageEvent = null;
40 OutMessageEvent = null;
41 }
42
43 internal static void OnSend<T>(T message, int channel, int bytes, int count)
44 where T : struct, NetworkMessage
45 {
46 if (count > 0 && OutMessageEvent != null)
47 {
48 MessageInfo outMessage = new MessageInfo(message, channel, bytes, count);
49 OutMessageEvent?.Invoke(outMessage);
50 }
51 }
52
53 internal static void OnReceive<T>(T message, int channel, int bytes)
54 where T : struct, NetworkMessage
55 {
56 if (InMessageEvent != null)
57 {
58 MessageInfo inMessage = new MessageInfo(message, channel, bytes, 1);
59 InMessageEvent?.Invoke(inMessage);
60 }
61 }
62 }
63}
Profiling statistics for tool to subscribe to (profiler etc.)
static Action< MessageInfo > InMessageEvent
Event for when Mirror receives a message. Can be subscribed to.
static Action< MessageInfo > OutMessageEvent
Event for when Mirror sends a message. Can be subscribed to.
Describes an outgoing message
readonly int channel
channel through which the message was sent
readonly int bytes
how big was the message (does not include transport headers)
readonly int count
How many connections was the message sent to.
readonly NetworkMessage message
The message being sent