示例#1
0
        public void RegisterCallback <TEventType, TCallbackArgs>(EventCallback <TEventType, TCallbackArgs> callback, TCallbackArgs userArgs, TrickleDown useTrickleDown = TrickleDown.NoTrickleDown) where TEventType : EventBase <TEventType>, new()
        {
            if (callback == null)
            {
                throw new ArgumentException("callback parameter is null");
            }

            long eventTypeId = EventBase <TEventType> .TypeId();

            var callbackPhase = useTrickleDown == TrickleDown.TrickleDown ? CallbackPhase.TrickleDownAndTarget : CallbackPhase.TargetAndBubbleUp;

            EventCallbackList callbackList = GetCallbackListForReading();

            if (callbackList != null)
            {
                var functor = callbackList.Find(eventTypeId, callback, callbackPhase) as EventCallbackFunctor <TEventType, TCallbackArgs>;
                if (functor != null)
                {
                    functor.userArgs = userArgs;
                    return;
                }
            }
            callbackList = GetCallbackListForWriting();
            callbackList.Add(new EventCallbackFunctor <TEventType, TCallbackArgs>(callback, userArgs, callbackPhase));
        }
示例#2
0
        internal bool TryGetUserArgs <TEventType, TCallbackArgs>(EventCallback <TEventType, TCallbackArgs> callback, TrickleDown useTrickleDown, out TCallbackArgs userArgs) where TEventType : EventBase <TEventType>, new()
        {
            userArgs = default(TCallbackArgs);

            if (callback == null)
            {
                return(false);
            }

            EventCallbackList list = GetCallbackListForReading();
            long eventTypeId       = EventBase <TEventType> .TypeId();

            var callbackPhase = useTrickleDown == TrickleDown.TrickleDown ? CallbackPhase.TrickleDownAndTarget : CallbackPhase.TargetAndBubbleUp;
            var functor       = list.Find(eventTypeId, callback, callbackPhase) as EventCallbackFunctor <TEventType, TCallbackArgs>;

            if (functor == null)
            {
                return(false);
            }

            userArgs = functor.userArgs;

            return(true);
        }