當前位置: 首頁>>代碼示例>>C#>>正文


C# EventHandler.Trigger方法代碼示例

本文整理匯總了C#中EventHandler.Trigger方法的典型用法代碼示例。如果您正苦於以下問題:C# EventHandler.Trigger方法的具體用法?C# EventHandler.Trigger怎麽用?C# EventHandler.Trigger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在EventHandler的用法示例。


在下文中一共展示了EventHandler.Trigger方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: test_single_event

 public void test_single_event()
 {
     var instance = new EventHandler();
     var count = 0;
     instance.AddEventHandler<TestEventA>((ep) => { count += 1; }, true);
     instance.Trigger(new TestEventA());
     instance.Trigger(new TestEventA());
     Assert(count == 1);
 }
開發者ID:shadowmint,項目名稱:unity-n-events,代碼行數:9,代碼來源:EventHandlerTests.cs

示例2: test_deferred_event

    public void test_deferred_event()
    {
        var instance = new EventHandler();
        var count = 0;
        instance.AddEventHandler<TestEventA>((ep) => { count += 1; }, 1f);

        instance.Trigger(new TestEventA());
        Assert(count == 0);

        instance.Step(1f);
        instance.Trigger(new TestEventA());
        Assert(count == 1);
    }
開發者ID:shadowmint,項目名稱:unity-n-events,代碼行數:13,代碼來源:EventHandlerTests.cs

示例3: test_persisted_single_event

 public void test_persisted_single_event()
 {
     var instance = new EventHandler();
     var count = 0;
     var done = false;
     var self = this;
     instance.AddEventHandler<TestEventC>((ep) =>
     {
         if (ep.Is<EventHandlerTest, TestEventC>(self, ep.value))
         {
             done = true;
         }
         count += 1;
     }, true);
     instance.Trigger(new TestEventC() { value = null }); // Persist on not Is()
     instance.Trigger(new TestEventC() { value = this }); // Match, drop event handler
     instance.Trigger(new TestEventC() { value = this });
     Assert(count == 2);
     Assert(done == true);
 }
開發者ID:shadowmint,項目名稱:unity-n-events,代碼行數:20,代碼來源:EventHandlerTests.cs

示例4: test_trigger_deferred_event

    public void test_trigger_deferred_event()
    {
        var instance = new EventHandler();
        var count = 0;
        instance.AddEventHandler<TestEventA>((ep) =>
        {
            instance.AddEventHandler<TestEventB>((ep2) => { count += 100; }, 1f);
            count += 1;
        });
        instance.Trigger(new TestEventA());
        instance.Trigger(new TestEventA());
        Assert(count == 2);

        instance.Trigger(new TestEventB());
        Assert(count == 2);

        instance.Step(1f);
        instance.Trigger(new TestEventB());
        Assert(count == 202);

        // All are expired now, doesn't Trigger again
        instance.Trigger(new TestEventB());
        Assert(count == 202);
    }
開發者ID:shadowmint,項目名稱:unity-n-events,代碼行數:24,代碼來源:EventHandlerTests.cs

示例5: Update

        /** Update the ball state */
        public void Update(float seconds, EventHandler events)
        {
            /* Move */
              Position [0] += Velocity [0] * seconds;
              Position [1] += Velocity [1] * seconds;

              /* Check for bouncing */
              if (Position [0] < _parent.Field.Bounds [0]) {
            Position [0] = _parent.Field.Bounds [0];
            Velocity [0] = -Velocity [0];
            var e = new WallHit(_parent, WallHitTarget.WALL_LEFT, Velocity, Position);
            events.Trigger(e);
              }
              if (Position [0] > _parent.Field.Bounds [2]) {
            Position [0] = _parent.Field.Bounds [2];
            Velocity [0] = -Velocity [0];
            var e = new WallHit(_parent, WallHitTarget.WALL_RIGHT, Velocity, Position);
            events.Trigger(e);
              }
              if (Position [1] < _parent.Field.Bounds [1]) {
            Position [1] = _parent.Field.Bounds [1];
            Velocity [1] = -Velocity [1];
            var e = new WallHit(_parent, WallHitTarget.WALL_BOTTOM, Velocity, Position);
            events.Trigger(e);
              }
              if (Position [1] > _parent.Field.Bounds [3]) {
            Position [1] = _parent.Field.Bounds [3];
            Velocity [1] = -Velocity [1];
            var e = new WallHit(_parent, WallHitTarget.WALL_TOP, Velocity, Position);
            events.Trigger(e);
              }

              if (_parent.AiPaddle.Intersects(this)) {
            var e = new PaddleHit(_parent, _parent.AiPaddle, Velocity, Position);
            events.Trigger(e);
            HandlePaddleHit(_parent.AiPaddle);
              }
              if (_parent.PlayerPaddle.Intersects(this)) {
            var e = new PaddleHit(_parent, _parent.PlayerPaddle, Velocity, Position);
            events.Trigger(e);
            HandlePaddleHit(_parent.PlayerPaddle);
              }

              if (_ball != null) {
            _ball.Data.Position.Set(Position);
            _ball.Data.Rotation += 0.5f;
              }
        }
開發者ID:shadowmint,項目名稱:pongstar,代碼行數:49,代碼來源:Ball.cs

示例6: test_trigger_event_removal

    public void test_trigger_event_removal()
    {
        var instance = new EventHandler();
        var count = 0;
        EventHandler<TestEventA> handler = null;
        handler = (ep) =>
        {
            instance.RemoveEventHandler(handler);
            count += 1;
        };
        instance.AddEventHandler(handler);

        instance.Trigger(new TestEventA());
        Assert(count == 1);

        instance.Trigger(new TestEventA());
        Assert(count == 1);
    }
開發者ID:shadowmint,項目名稱:unity-n-events,代碼行數:18,代碼來源:EventHandlerTests.cs


注:本文中的EventHandler.Trigger方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。