Ejemplo n.º 1
0
        protected void AddHandler <ChangeEvent>(
            StateChangeHandlerDelegate <ChangeEvent> handler,
            EventComparator <ChangeEvent> comparator,
            Events.Event <ChangeEvent> changeEvent
            )
        {
            UnityAction <ChangeEvent> ephemeralHandler = (ChangeEvent pEv) =>
            {
                handler(pEv);
            };

            changeEvent.Listen(ephemeralHandler);

            // Cleanup
            cleanupActions.Add(() =>
            {
                changeEvent.Remove(ephemeralHandler);
            });
        }
Ejemplo n.º 2
0
        protected void AddHandler <PressEvent>(
            PressHandlerDelegate <PressEvent> handler,
            PressEventComparator <PressEvent> comparator,
            Events.Event <PressEvent> pressEvent,
            Events.Event <PressEvent> unpressEvent
            )
        {
            UnityAction <PressEvent> ephemeralHandler = (PressEvent pEv) =>
            {
                var unpressHandler = handler(pEv);
                UnityAction <PressEvent> ephemeralUnpressHandler = null;
                void cleanupEphemeralUnpressHandler()
                {
                    unpressEvent.Remove(ephemeralUnpressHandler);
                }

                ephemeralUnpressHandler = (PressEvent uEv) =>
                {
                    if (!comparator(pEv, uEv))
                    {
                        return;
                    }

                    unpressHandler(uEv);
                    cleanupEphemeralUnpressHandler();
                    cleanupActions.Remove(cleanupEphemeralUnpressHandler);
                };
                unpressEvent.Listen(ephemeralUnpressHandler);
                cleanupActions.Add(cleanupEphemeralUnpressHandler);
            };

            pressEvent.Listen(ephemeralHandler);

            // Cleanup
            cleanupActions.Add(() =>
            {
                pressEvent.Remove(ephemeralHandler);
            });
        }