Ejemplo n.º 1
0
            internal void Add <T>(FlarePayloadCallback <T> callback) where T : INetworkPayload
            {
                int key = callback.GetHashCode();

                if (!Values.ContainsKey(key))
                {
                    // This cast needs benchmarking
                    Values.Add(key, x =>
                    {
                        if (x is T p)
                        {
                            callback(p);
                        }
                    });

                    if (Type.IsVisible)
                    {
                        NetworkLogger.Log($"Added delegate [{callback.Method.Name}] for payload type [{Name}]", LogCategory.PayloadCallbacks);
                    }
                }
                else
                {
                    NetworkLogger.Log($"Delegate [{callback.Method.Name}] is already added to listen for payload type [{Name}]", LogCategory.PayloadCallbacks, LogLevel.Warning);
                }
            }
Ejemplo n.º 2
0
            internal void Remove <T>(FlarePayloadCallback <T> callback) where T : INetworkPayload
            {
                int key = callback.GetHashCode();

                if (Values.ContainsKey(key))
                {
                    Values.Remove(key);

                    if (Type.IsVisible)
                    {
                        NetworkLogger.Log($"Removed delegate [{callback.Method.Name}] for payload type [{Name}]", LogCategory.PayloadCallbacks);
                    }
                }
                else
                {
                    NetworkLogger.Log($"Delegate [{callback.Method.Name}] is not listening for payload type [{Name}]", LogCategory.PayloadCallbacks, LogLevel.Warning);
                }
            }