public IEnumerator TestMultipleDifferentEvents()
        {
            int value1 = 0;
            int value2 = 0;

            Action <EvSimpleEvent>  callback  = x => { value1 += 1; };
            Action <EvSimpleEvent2> callback2 = x => { value2 += 2; };

            GlobalEventSystem.SubscribeUI(callback);
            GlobalEventSystem.SubscribeUI(callback2);

            GlobalEventSystem.SendEventUI(new EvSimpleEvent());

            yield return(null);

            Assert.IsTrue(value1 == 1);

            GlobalEventSystem.SendEventUI(new EvSimpleEvent2());
            yield return(null);

            Assert.IsTrue(value2 == 2);
            GlobalEventSystem.UnsubscribeUI(callback);
            GlobalEventSystem.UnsubscribeUI(callback2);

            EventManager.VerifyNoSubscribersAll();
        }
Exemple #2
0
        public IEnumerator TestMultipleEvents()
        {
            int value = 0;
            Action <EvSimpleEvent> callback = x => { value += 1; };

            GlobalEventSystem.Subscribe(callback);

            GlobalEventSystem.SendEvent(new EvSimpleEvent());
            GlobalEventSystem.SendEvent(new EvSimpleEvent());

            yield return(new WaitForFixedUpdate());

            Assert.IsTrue(value == 2);

            GlobalEventSystem.SendEvent(new EvSimpleEvent());
            yield return(new WaitForFixedUpdate());

            Assert.IsTrue(value == 3);

            GlobalEventSystem.SendEvent(new EvSimpleEvent());
            yield return(new WaitForFixedUpdate());

            Assert.IsTrue(value == 4);

            GlobalEventSystem.Unsubscribe(callback);

            EventManager.VerifyNoSubscribersAll();
        }
        public IEnumerator TestTwoSubscribesOneUnsubscribeEvent()
        {
            int value = 0;
            Action <EvSimpleEvent> callback  = x => { value += 1; };
            Action <EvSimpleEvent> callback2 = x => { value += 2; };

            GlobalEventSystem.SubscribeUI(callback);
            GlobalEventSystem.SubscribeUI(callback2);

            GlobalEventSystem.SendEventUI(new EvSimpleEvent());

            yield return(null);

            Assert.IsTrue(value == 3);

            GlobalEventSystem.SendEventUI(new EvSimpleEvent());
            GlobalEventSystem.UnsubscribeUI(callback);

            yield return(null);

            Assert.IsTrue(value == 5);
            GlobalEventSystem.UnsubscribeUI(callback2);

            EventManager.VerifyNoSubscribersAll();
        }
Exemple #4
0
 public override void Action(Field.Tile target)
 {
     base.Action(target);
     if (target.type == Field.Tile.TileTypes.STORK)
     {
         GlobalEventSystem.TalkToStork(target);
     }
 }
Exemple #5
0
        public void TestLingeringSubscriber()
        {
            Action <TestJob> callback = x => { Assert.IsTrue(x.result == 10); };

            GlobalEventSystem.SubscribeWithJob <TestJob, EvSimpleEvent>(new TestJob(), callback);

            Assert.Throws <SubscriberStillListeningException <TestJob, EvSimpleEvent> >(EventManager.VerifyNoSubscribersAll);
        }
Exemple #6
0
 public void MoveToPoint(Vector3 pos)
 {
     // transform.GetComponent<GyroController>().enabled = false;
     transform.DOMove(pos, 3).OnComplete(delegate() {
         // transform.GetComponent<GyroController>().enabled = true;
         GlobalEventSystem.Fire(new BaseEvent(EventName.MOVE_COMPLETE));
     });
 }
        public void SendEvents()
        {
            Debug.Log("SendEvents()");

            // Job listeners trigger on events like anything else. You can have job listeners and regular listeners to
            // a single event.
            GlobalEventSystem.SendEvent(new EvExampleEvent(10));
        }
Exemple #8
0
    private void InitEvents()
    {
        GlobalEventSystem.Bind(EventName.MONS_DEATH, OnMonsDeath);
        GlobalEventSystem.Bind(EventName.PLAYER_BE_HIT, OnPlayerBeHit);
        GlobalEventSystem.Bind(EventName.GAME_START, OnGameStart);

        KeyInputManager.Instance.Bind(EventName.BTN_A_DOWN, OnBtnADown);
        KeyInputManager.Instance.Bind(EventName.BTN_A_UP, OnBtnAUp);
    }
Exemple #9
0
 public void UseMedicine()
 {
     if (GlobalDataHolder.medicine > 0)
     {
         GlobalDataHolder.medicine--;
         health += GlobalDataHolder.health_for_medicine;
         GlobalEventSystem.PlayerMedicineUsed();
     }
 }
Exemple #10
0
 public void Done(Item item)
 {
     if (item == this.item)
     {
         _done = true;
         GlobalEventSystem.OnItemPickedUp -= Done;
         GlobalEventSystem.TaskDone(this);
     }
 }
Exemple #11
0
    void Update()
    {
        if (!canShoot)
        {
            return;
        }
        shootTimer -= Time.deltaTime;

        if (isChangeBullet)
        {
            if (changeBulletTimer > 0)
            {
                changeBulletTimer -= Time.deltaTime;
                return;
            }
            else
            {
                reloadView.gameObject.SetActive(false);
                BulletData data = bullets[curGun];
                data.curNum = data.maxNum;
                GlobalEventSystem.Fire(new BaseEvent(EventName.BULLET_NUM_CHANGE, new object[] { data.curNum, data.maxNum }));
                isChangeBullet = false;
                return;
            }
        }

        if ((Input.GetMouseButton(0) || isShoot) && shootTimer <= 0)
        {
            shootTimer = 0.2f;
            BulletData data = bullets[curGun];

            if (data.curNum >= 1)
            {
                data.curNum -= data.num;

                // 生成子弹
                //SkillManager.Instance.Fire(this, gun.position + gun.up, camera.transform.forward, bullets[curGun]);
                SkillManager.Instance.Fire(this, null, gun.position, camera.transform.forward, bullets[curGun]);
                GlobalEventSystem.Fire(new BaseEvent(EventName.BULLET_NUM_CHANGE, new object[] { data.curNum, data.maxNum }));
            }
            else
            {
                reloadView.gameObject.SetActive(!reloadView.gameObject.activeSelf);
            }
            // 射线检测法
            //RaycastHit rayHit;

            //bool hit = Physics.Raycast(gun.position, camera.transform.TransformDirection(Vector3.forward), out rayHit, 100, 1 << 8);
            //if (hit) {
            //    Enemy enemy = rayHit.transform.GetComponent<Enemy>();
            //    if (enemy != null) {
            //        enemy.BeHit(10);
            //    }
            //}
        }
    }
Exemple #12
0
 private void ProgressChecker(FieldUnit unit)
 {
     if (unit == unit_to_interact)
     {
         unit.Die();
         _done = true;
         GlobalEventSystem.TaskDone(this);
         GlobalEventSystem.OnUnitActivate -= ProgressChecker;
     }
 }
Exemple #13
0
 private void OnEnable()
 {
     // Jobs work with the global simulation and global UI event systems as well as the GameObject system. This
     // will just show examples with the global simulation system.
     //
     // When an event is fired jobs will processed in parallel using the burst compiler. Can make otherwise
     // long tasks very short. Afterwards the callback functions are invoked so the listener can use the results
     // of the job.
     GlobalEventSystem.SubscribeWithJob <ExampleJob, EvExampleEvent>(new ExampleJob(), OnJobFinished);
 }
Exemple #14
0
 private IEnumerator BeginCountDown()
 {
     for (int i = 0; i < 4; ++i)
     {
         txt.sprite = txts[i];
         txt.SetNativeSize();
         yield return(new WaitForSeconds(1));
     }
     GlobalEventSystem.Fire(new BaseEvent(EventName.GAME_START));
     gameObject.SetActive(false);
 }
Exemple #15
0
    public override bool MoveByDirection(Field.Directions direction)
    {
        var isValid = base.MoveByDirection(direction);

        if (uses_curtain && tile.type != Field.Tile.TileTypes.CURTAIN)
        {
            GlobalEventSystem.RaiseCurtainLeave(tile);
        }

        return(isValid);
    }
Exemple #16
0
 public void UseSkill()
 {
     tile[direction].Attacked(damage * 2);
     if (tile[direction].type == Field.Tile.TileTypes.STRUCTURE)
     {
         tile[direction].type = Field.Tile.TileTypes.ROAD;
         tile[direction].tileView.UpdateView(Field.Tile.TileTypes.STRUCTURE);
         FieldUpdate();
         GlobalEventSystem.StructureDestroyed(tile[direction]);
     }
 }
Exemple #17
0
        private void OnDisable()
        {
            // Should always unsubscribe

            // Unsubscribe from the global system
            GlobalEventSystem.Unsubscribe <EvExampleEvent>(OnExampleEvent);
            gameObject.Unsubscribe <EvExampleEvent>(OnExampleEvent);

            GlobalEventSystem.UnsubscribeUI <EvExampleEvent>(OnExampleEvent);
            gameObject.UnsubscribeUI <EvExampleEvent>(OnExampleEvent);
        }
Exemple #18
0
    private void InitEvents()
    {
        GlobalEventSystem.Bind(EventName.MONS_DEATH, OnMonsDeath);
        GlobalEventSystem.Bind(EventName.BULLET_NUM_CHANGE, OnBulletNumChange);
        GlobalEventSystem.Bind(EventName.PLAYER_BE_HIT, OnPlayerBeHit);
        GlobalEventSystem.Bind(EventName.GAME_START, OnGameStart);

        KeyInputManager.Instance.Bind(EventName.BTN_A_DOWN, OnBtnADown);
        KeyInputManager.Instance.Bind(EventName.BTN_A_UP, OnBtnAUp);
        KeyInputManager.Instance.Bind(EventName.BTN_B_DOWN, OnBtnBDown);
        KeyInputManager.Instance.Bind(EventName.BTN_C_DOWN, OnBtnCDown);
    }
Exemple #19
0
 private void Timer()
 {
     time_left -= Time.deltaTime;
     if (time_left <= 0)
     {
         time_left = 0;
         GlobalEventSystem.OnLevelStart -= TimerStart;
         GlobalEventSystem.OnLevelEnd   -= TimerStop;
         TimerStop();
         GlobalEventSystem.TimerElapsed();
     }
 }
Exemple #20
0
 public void Activate()
 {
     GlobalEventSystem.ActivateTile(this);
     if (unit != null)
     {
         GlobalEventSystem.ActivateUnit(unit);
         return;
     }
     if (item != null)
     {
         item.PickUp();
     }
 }
Exemple #21
0
 public override void BeHit(int val)
 {
     if (!data.isBeHit)
     {
         return;
     }
     data.curHP -= val;
     if (data.curHP < 0)
     {
         data.curHP = 0;
     }
     GlobalEventSystem.Fire(new BaseEvent(EventName.PLAYER_BE_HIT, new object[] { data.curHP, data.maxHP }));
 }
Exemple #22
0
        static int _m_UnBindAll_xlua_st_(RealStatePtr L)
        {
            try {
                {
                    GlobalEventSystem.UnBindAll(  );



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Exemple #23
0
        public IEnumerator TestSimpleSubscribeAndEvent()
        {
            Action <TestJob> callback = x => { Assert.IsTrue(x.result == 10); };

            GlobalEventSystem.SubscribeWithJob <TestJob, EvSimpleEvent>(new TestJob(), callback);

            GlobalEventSystem.SendEvent(new EvSimpleEvent(10));

            yield return(new WaitForFixedUpdate());

            GlobalEventSystem.UnsubscribeWithJob <TestJob, EvSimpleEvent>(callback);

            EventManager.VerifyNoSubscribersAll();
        }
Exemple #24
0
    public void Start()
    {
        Debug.Log("Start level: " + ScenesManager.GetLevelNumber());

        _fieldController.Initialize();
        GlobalDataHolder.SetField(_fieldController.field);
        _fieldController.field.SpawnPlayer();

        GlobalEventSystem.ListenPlayerDeath();
        GlobalEventSystem.RaiseLevelStart();

        GlobalDataHolder.player.ui.onGameOverNext += _OnLevelEnd;
        GlobalDataHolder.player.ui.onGameWin      += _OnGameWin;
    }
Exemple #25
0
 public void OnBtnGunClick()
 {
     if (btnGunA.activeSelf)
     {
         btnGunA.SetActive(false);
         btnGunB.SetActive(true);
         GlobalEventSystem.Fire(new BaseEvent(EventName.CHANGE_GUN, 1));
     }
     else if (btnGunB.activeSelf)
     {
         btnGunA.SetActive(true);
         btnGunB.SetActive(false);
         GlobalEventSystem.Fire(new BaseEvent(EventName.CHANGE_GUN, 0));
     }
 }
Exemple #26
0
        private void OnEnable()
        {
            // Subscribes to the global event system, handles events in FixedUpdate
            GlobalEventSystem.Subscribe <EvExampleEvent>(OnExampleEvent);

            // Subscribes to THIS GameObject's event system! Also Fixed Update
            gameObject.Subscribe <EvExampleEvent>(OnExampleEvent);

            // Is the game paused but still need events for UI? There's a global UI system. Handles events in
            // LateUpdate
            GlobalEventSystem.SubscribeUI <EvExampleEvent>(OnExampleEvent);

            // There's also local event system for each GameObject that run in LateUpdate.
            gameObject.SubscribeUI <EvExampleEvent>(OnExampleEvent);
        }
Exemple #27
0
        static int _m_Fire_xlua_st_(RealStatePtr L)
        {
            try {
                {
                    string _type = LuaAPI.lua_tostring(L, 1);

                    GlobalEventSystem.Fire(_type);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Exemple #28
0
        public void SendEvents()
        {
            // Send an event to the global event system, will be processed in the next FixedUpdate
            GlobalEventSystem.SendEvent(new EvExampleEvent(10));

            // Send an event to a specific GameObject, only listeners subscribed to that gameobject will get
            // this event. Also will be processed in the next FixedUpdate
            gameObject.SendEvent(new EvExampleEvent(99));

            // Can send events to the global UI event system. These will be processed in LateUpdate which allows the
            // game to paused.
            GlobalEventSystem.SendEventUI(new EvExampleEvent(-1));

            // Similarly can send to a specific GameObject to be processed in LateUpdate
            gameObject.SendEventUI(new EvExampleEvent(999999));
        }
        public IEnumerator TestMultipleSubscribersAndEvent()
        {
            Action <TestJob> callback  = x => { Assert.IsTrue(x.result == 10); };
            Action <TestJob> callback2 = x => { Assert.IsTrue(x.result == 10); };

            GlobalEventSystem.SubscribeUIWithJob <TestJob, EvSimpleEvent>(new TestJob(), callback);
            GlobalEventSystem.SubscribeUIWithJob <TestJob, EvSimpleEvent>(new TestJob(), callback2);

            GlobalEventSystem.SendEventUI(new EvSimpleEvent(10));

            yield return(null);

            GlobalEventSystem.UnsubscribeUIWithJob <TestJob, EvSimpleEvent>(callback);
            GlobalEventSystem.UnsubscribeUIWithJob <TestJob, EvSimpleEvent>(callback2);

            EventManager.VerifyNoSubscribersAll();
        }
Exemple #30
0
    public void ChangeGun(int index)
    {
        curGun = index;
        if (index == 0)
        {
            transform.FindChild("Camera/GunA").gameObject.SetActive(true);
            transform.FindChild("Camera/GunB").gameObject.SetActive(false);
        }
        else
        {
            transform.FindChild("Camera/GunA").gameObject.SetActive(false);
            transform.FindChild("Camera/GunB").gameObject.SetActive(true);
        }
        BulletData data = bullets[curGun];

        GlobalEventSystem.Fire(new BaseEvent(EventName.BULLET_NUM_CHANGE, new object[] { data.curNum, data.maxNum }));
    }