예제 #1
0
        protected override Action Prepare(EntitySignals es, Func <Recorder> receiverPrepare)
        {
            var receiver = receiverPrepare.Invoke();

            es.On(Entity).Add(receiver);
            return(() => { es.On(Entity).Send(1); });
        }
        public void ProcessGlobalSignal()
        {
            var es       = new EntitySignals();
            var recorder = new Recorder();
            var handler  = (ESHandler <int>)((a1) => { recorder.Record("First", a1); });

            es.On().Add(handler);
            Assert.AreEqual(1, es.On().Count);

            es.On().Send(1);
            es.On().Dispose();

            Assert.AreEqual(0, es.On().Count);
            recorder.Verify("First", 1);
        }
        public void ProcessSimpleSignal()
        {
            var es       = new EntitySignals();
            var entity   = Object.Instantiate(new GameObject());
            var recorder = new Recorder();
            var handler  = (ESHandler <GameObject, int>)((a1, a2) => { recorder.Record("First", a1, a2); });

            es.On(entity).Add(handler);
            Assert.AreEqual(1, es.On(entity).Count);

            es.On(entity).Send(1);
            es.On(entity).Dispose();

            Assert.AreEqual(0, es.On(entity).Count);
            recorder.Verify("First", entity, 1);
        }
        public void ProcessReceiverClassMethods()
        {
            var es       = new EntitySignals();
            var entity   = Object.Instantiate(new GameObject());
            var receiver = new TestReceiver();

            es.On(entity).Add((ESHandler <GameObject, int>)receiver.OnGameObjectSignal);
            es.On(entity).Add((ESHandler <char>)receiver.OnGameObjectSignal);
            Assert.AreEqual(2, es.On(entity).Count);

            es.On(entity).Send(1);
            es.On(entity).Send('t');
            es.On(entity).Dispose();

            Assert.AreEqual(0, es.On(entity).Count);
            receiver.Verify("First", entity, 1);
            receiver.Verify("Second", 't');
        }
        public void ProcessReceiverClass()
        {
            var es       = new EntitySignals();
            var entity   = Object.Instantiate(new GameObject());
            var receiver = new TestReceiver();

            es.On(entity).Add(receiver);
            Assert.AreEqual(2, es.On(entity).Count);

            es.On(entity).Send(1);
            es.On(entity).Send('t');
            es.On(entity).Remove(receiver);

            Assert.AreEqual(0, es.On(entity).Count);
            receiver.Verify("First", entity, 1);
            receiver.Verify("Second", 't');
        }
예제 #6
0
 public static IContext <TEntity> On <TEntity>(TEntity entity)
 {
     return(Default.On(entity));
 }