public static void ConnectEvent(this GameObject listener, string eventName, EventWithData func) { if (eventName.IsEmpty()) { return; } if (eventHandlers.ContainsKey(eventName)) { if (eventHandlers[eventName].ContainsKey(listener)) { if (eventHandlers[eventName][listener].Contains(func) == false) { eventHandlers[eventName][listener].Add(func); } } else { eventHandlers[eventName].Add(listener, new List <EventWithData>() { func }); } } else { eventHandlers.Add(eventName, new Dictionary <GameObject, List <EventWithData> >()); eventHandlers[eventName].Add(listener, new List <EventWithData>() { func }); } }
public void ObservableFromEventPatternDerivedEventArgs() { var observable = Observable.FromEventPattern <DerivedEventArgs>( x => EventWithData += x, x => EventWithData -= x); var subscriber = observable.Subscribe( x => Trace.WriteLine($"Sender: {x.Sender}, EventArgs: {x.EventArgs.Data}"), () => Trace.WriteLine("Never completed?")); EventWithData?.Invoke(this, new DerivedEventArgs { Data = "Some data" }); subscriber.Dispose(); }