/// <inheritdoc /> public void DoLogicWork <TCallBackValue, TEventHub>(EventHubCallback <TCallBackValue, TEventHub> .IView view, Type typeHub) where TEventHub : EventHubCallback <TCallBackValue, TEventHub> { var commandList = GetCommandList(typeHub, _handlerStorage); if (!commandList.Any()) { Debug.LogError("No action for this Hub: " + typeHub); return; } var lateCommandList = GetCommandList(typeHub, _callbackCommandStorage); foreach (var weakReference in commandList) { var handler = (EventHubCallback <TCallBackValue, TEventHub> .IHandler)weakReference.Target; var callBackValue = handler.Handle(); view.SetCallbackValue(callBackValue); foreach (var lateWeakReference in lateCommandList) { var action = (Action <TCallBackValue>)lateWeakReference.Target; action.Invoke(callBackValue); } } }
//====================================================== /// <inheritdoc /> public void Add <TCallBackValue, TEventHub>(EventHubCallback <TCallBackValue, TEventHub> .IHandler handler) where TEventHub : EventHubCallback <TCallBackValue, TEventHub> { var commandList = GetCommandList(typeof(TEventHub), _handlerStorage); commandList.Add(new WeakReference(handler)); }
/// <inheritdoc /> public void Remove <TCallBackValue, TEventHub>(EventHubCallback <TCallBackValue, TEventHub> .IHandler handler) where TEventHub : EventHubCallback <TCallBackValue, TEventHub> { var commandList = GetCommandList(typeof(TEventHub), _handlerStorage); commandList.RemoveAll(c => c.Target == handler); }