Exemple #1
0
        public void test_global_events_fire()
        {
            GlobalEventStream.Reset();
            var listener  = new ListensToEvents();
            var listener2 = new ListensToEventsWithContext();

            GlobalEventStream.Trigger(new GlobalEvent());
            GlobalEventStream.Trigger(new GlobalEvent());

            Assert(listener.EventsHandled == 2);
            Assert(listener2.EventsHandled == 2);
            Assert(GlobalEventStream.EventsDispatched == 4);
        }
Exemple #2
0
        public void test_when_gameobject_expires_it_no_longer_receives_events()
        {
            GlobalEventStream.Reset();

            var instance = this.SpawnComponent <ListensToEventsBehaviour>();

            instance.Start();

            GlobalEventStream.Trigger(new GlobalEvent());
            Assert(instance.EventsHandled == 1);
            Assert(GlobalEventStream.EventsDispatched == 1);

            Object.DestroyImmediate(instance.gameObject);

            GlobalEventStream.Trigger(new GlobalEvent());
            Assert(GlobalEventStream.EventsDispatched == 1);
        }
Exemple #3
0
        public void test_when_object_expires_it_no_longer_receives_events()
        {
            GlobalEventStream.Reset();
            using (var listener = new ListensToEvents())
            {
                using (var listener2 = new ListensToEventsWithContext())
                {
                    GlobalEventStream.Trigger(new GlobalEvent());

                    Assert(listener2.EventsHandled == 1);
                    Assert(GlobalEventStream.EventsDispatched == 2);
                }

                GlobalEventStream.Trigger(new GlobalEvent());
                Assert(listener.EventsHandled == 2);
                Assert(GlobalEventStream.EventsDispatched == 3);
            }

            GlobalEventStream.Trigger(new GlobalEvent());
            Assert(GlobalEventStream.EventsDispatched == 3);
        }