Exemplo n.º 1
0
        public void TestSendEvent()
        {
            int firstEventCount  = 0;
            int secondEventCount = 0;

            OnHearEvent onHearFirstEvent = (sender, e) =>
            {
                Assert.AreSame(sender, this);
                Assert.True(e is OneSimpleEventArgs);
                firstEventCount++;
            };

            OnHearEvent onHearSecondEvent = (sender, e) =>
            {
                Assert.AreSame(sender, this);
                Assert.True(e is AnotherSimpleEventArgs);
                secondEventCount++;
            };

            m_EventModule.AddEventListener(OneSimpleEventArgs.TheEventId, onHearFirstEvent);

            m_EventModule.SendEvent(this, new OneSimpleEventArgs());
            m_EventModule.SendEvent(this, new AnotherSimpleEventArgs());

            Assert.AreEqual(0, firstEventCount);
            Assert.AreEqual(0, secondEventCount);

            m_EventModule.Update(new TimeStruct(0f, 0f, 0f, 0f));

            Assert.AreEqual(1, firstEventCount);
            Assert.AreEqual(0, secondEventCount);

            m_EventModule.AddEventListener(AnotherSimpleEventArgs.TheEventId, onHearSecondEvent);

            m_EventModule.AddEventListener(OneSimpleEventArgs.TheEventId, onHearFirstEvent);

            m_EventModule.SendEvent(this, new OneSimpleEventArgs());
            m_EventModule.SendEvent(this, new AnotherSimpleEventArgs());

            Assert.AreEqual(1, firstEventCount);
            Assert.AreEqual(0, secondEventCount);

            m_EventModule.Update(new TimeStruct(0f, 0f, 0f, 0f));

            Assert.AreEqual(3, firstEventCount);
            Assert.AreEqual(1, secondEventCount);

            m_EventModule.RemoveEventListener(OneSimpleEventArgs.TheEventId, onHearFirstEvent);
            m_EventModule.RemoveEventListener(AnotherSimpleEventArgs.TheEventId, onHearSecondEvent);

            m_EventModule.SendEvent(this, new OneSimpleEventArgs());
            m_EventModule.SendEvent(this, new AnotherSimpleEventArgs());

            m_EventModule.Update(new TimeStruct(0f, 0f, 0f, 0f));

            Assert.AreEqual(4, firstEventCount);
            Assert.AreEqual(1, secondEventCount);
        }
Exemplo n.º 2
0
        public void TestSendEventNow()
        {
            int firstEventCount = 0;

            OnHearEvent onHearFirstEvent = (sender, e) =>
            {
                Assert.AreSame(sender, this);
                Assert.True(e is OneSimpleEventArgs);
                firstEventCount++;
            };

            m_EventModule.AddEventListener(OneSimpleEventArgs.TheEventId, onHearFirstEvent);
            m_EventModule.SendEventNow(this, new OneSimpleEventArgs());
            Assert.AreEqual(1, firstEventCount);
            m_EventModule.Update(new TimeStruct(0f, 0f, 0f, 0f));
            Assert.AreEqual(1, firstEventCount);
        }
Exemplo n.º 3
0
        public void TestRemoveUnaddedListener()
        {
            OnHearEvent onHearFirstEvent = (sender, e) => { };

            m_EventModule.RemoveEventListener(OneSimpleEventArgs.TheEventId, onHearFirstEvent);
        }