static void test()
        {
            var e = new EventEmitter();

            e.On("event", (bool args1, string args2) =>
            {
                Console.WriteLine(args1);
            });

            e.Emit("event", true, "test1");
            e.Emit("event", false, "test2");
        }
Ejemplo n.º 2
0
 void OnMouseDown()
 {
     m_isDragging  = true;
     m_screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
     m_offset      = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, m_screenPoint.z));
     EventEmitter.Emit(GameEvent.NerversDraging, new BoolEvent(true));
 }
Ejemplo n.º 3
0
    IEnumerator ResetLevelViewSequence(bool isSmooth)
    {
        if (isSmooth)
        {
            var scrollTime = m_smoothScrollTime;

            if (m_levelCanvas.transform.position == Vector3.zero)
            {
                scrollTime = 0f;
            }

            m_levelCanvas.transform.DOMove(Vector3.zero, scrollTime);

            if (scrollTime != 0f)
            {
                yield return(new WaitForSeconds(scrollTime + 0.2f));
            }
        }
        else
        {
            m_levelCanvas.localPosition = Vector3.zero;
        }

        EventEmitter.Emit(GameEvent.LevelStart);

        yield return(null);
    }
Ejemplo n.º 4
0
        private void OnPlayButtonClicked()
        {
            var randomMeowSound = UnityEngine.Random.Range(8, 15);

            EventEmitter.Emit(GameEvent.PlaySound, new SoundEvent((SoundType)randomMeowSound, 9));
            sceneMask.Show(() => SceneManager.LoadScene(ProjectInfo.SceneInfos.Main.BuildIndex));
        }
Ejemplo n.º 5
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "Player")
     {
         EventEmitter.Emit(GameEvent.Killed);
     }
 }
    private IEnumerator StageClearPerform()
    {
        yield return(new WaitForSeconds(1.0f));

        EventEmitter.Emit(GameEvent.Complete);
        yield return(null);
    }
 private void OnTriggerEnter2D(Collider2D collision)
 {
     switch (collision.gameObject.tag)
     {
     case "InstantKill":
         EventEmitter.Emit(GameEvent.Killed);
         break;
     }
 }
Ejemplo n.º 8
0
        public void DoesNotEmitIfEventDoesntExist()
        {
            var e = new EventEmitter();

            Assert.That(() => e.Emit("test_event", "test data"),
                        Throws.Exception
                        .TypeOf <DoesNotExistException>()
                        .With.Message.EqualTo("Event [test_event] does not exist in the emitter. Consider calling EventEmitter.On"));
        }
Ejemplo n.º 9
0
        public void EmitCallsAllAttachedFunctions()
        {
            var e = new EventEmitter();

            numberToTest = 0;
            e.On("data", IncrementNumber);
            e.On("data", IncrementNumberBy2);
            e.Emit("data", numberToTest);
            Assert.AreEqual(3, numberToTest);
        }
        public void OnWithArgs()
        {
            var e = new EventEmitter();

            e.On("event", (bool value) =>
            {
                Assert.IsTrue(value);
            });
            e.Emit("event", true);
        }
Ejemplo n.º 11
0
        public void ParallelsSimpleTest()
        {
            var emitter = new EventEmitter(_observers, new ParallelsObserverInvoker());

            var evnt = new HelloWorldEvent();

            emitter.Emit(evnt);

            Assert.IsTrue(Constants.ExpectedResultForHelloWorldEvent.IsMatch(evnt.Data));
        }
Ejemplo n.º 12
0
        public void SimpleTest()
        {
            var emitter = new EventEmitter(_observers);

            var evnt = new HelloWorldEvent();

            emitter.Emit(evnt);

            Assert.AreEqual("January, February, March", evnt.Data);

        }
Ejemplo n.º 13
0
        public void CachedTest()
        {
            var cache = new MemoryCache("MyObservers");
            var emitter = new EventEmitter(new CachedObserverStorage(cache, _observers));
            var evnt = new HelloWorldEvent();

            var noncachedStartTicks = DateTime.Now.Ticks;
            emitter.Emit(evnt);
            var nonCachedTicks = DateTime.Now.Ticks - noncachedStartTicks;

            var cachedStartTicks = DateTime.Now.Ticks;
            emitter.Emit(evnt);
            var cachedTicks = DateTime.Now.Ticks - cachedStartTicks;

            Console.WriteLine("Difference in miliseconds between cached and noncached: {0}", (nonCachedTicks - cachedTicks) / TimeSpan.TicksPerMillisecond);

            Assert.AreNotEqual(cachedTicks, nonCachedTicks);
            Assert.IsTrue(cachedTicks < nonCachedTicks);

        }
    public void GetCaught()
    {
        if (CurPlayerState == PlayerState.Dig)
        {
            return;
        }

        //TODO: perform

        EventEmitter.Emit(GameEvent.LevelFail);
    }
Ejemplo n.º 15
0
        public void RemoveListenerRemovesFunction()
        {
            var e = new EventEmitter();

            numberToTest = 0;
            e.On("data", IncrementNumber);
            e.On("data", IncrementNumberBy2);
            e.RemoveListener("data", IncrementNumberBy2);
            e.Emit("data", numberToTest);
            Assert.AreEqual(1, numberToTest);
        }
Ejemplo n.º 16
0
        public void TestEmitNull()
        {
            var success = false;

            EventEmitter.Add(GameEvent.None, Action1);
            EventEmitter.Emit(GameEvent.None);
            Assert.IsTrue(success);

            void Action1(IEvent val)
            {
                success = true;
            }
        }
    public void RequestAttack()
    {
        if (m_isAttacking == true)
        {
            return;
        }

        m_weaponAnimator.SetTrigger("Attack");

        m_isAttacking = true;

        EventEmitter.Emit(GameEvent.PlaySound, new SoundEvent(SoundType.swing_sword, 6));
    }
Ejemplo n.º 18
0
        public void TestEmitInt()
        {
            var value = 0;

            EventEmitter.Add(GameEvent.None, Action1);
            EventEmitter.Emit(GameEvent.None, new IntEvent(1));
            Assert.AreEqual(expected: 1, actual: value);

            void Action1(IEvent @event)
            {
                value = (@event as IntEvent).Value;
            }
        }
    public void ElectricKill(IEvent @event)
    {
        Debug.LogWarning("ElectricKill");
        transform.SetParent(null);
        m_catAnimator.SetTrigger("Die");
        m_collider.enabled = false;
        m_rigid.velocity   = Vector2.zero;
        m_rigid.bodyType   = RigidbodyType2D.Static;

        EventEmitter.Emit(GameEvent.PlaySound, new SoundEvent(SoundType.cat_screaming, 7));

        StartCoroutine(DiePerform());
    }
Ejemplo n.º 20
0
    void InvaderCheck()
    {
        var player           = GameObject.FindWithTag("Player");
        var playerController = player.GetComponent <PlayerController>();

        if (playerController.CurPlayerState != PlayerState.Walk)
        {
            return;
        }

        if (m_detectArea.OverlapPoint(player.transform.position))
        {
            EventEmitter.Emit(GameEvent.LevelFail);
        }
    }
    public void Jump()
    {
        if (!m_isOnGround || m_isJumping)
        {
            Debug.Log("Not on ground!");
            return;
        }

        transform.SetParent(null);
        m_startJumpAt = DateTime.UtcNow.Ticks;

        m_isOnGround      = false;
        m_isJumping       = true;
        m_rigid.velocity += new Vector2(0, m_jumpForce);

        m_catAnimator.SetTrigger("Jump");

        EventEmitter.Emit(GameEvent.PlaySound, new SoundEvent(SoundType.CatJump, 8));
    }
    public void RequestStageClear(IEvent @event)
    {
        Debug.LogWarning("RequestStageClear");
        var finishPoint = GameObject.FindWithTag("FinishPoint");

        m_collider.enabled = false;
        m_rigid.bodyType   = RigidbodyType2D.Static;
        var oldPosY = transform.position.y;

        m_rigid.velocity = Vector2.zero;

        transform.position = new Vector3(finishPoint.transform.position.x - 0.92f, oldPosY);

        m_catAnimator.SetTrigger("Win");

        EventEmitter.Emit(GameEvent.PlaySound, new SoundEvent(SoundType.Clown_Horn_Squeak, 9));

        StartCoroutine(StageClearPerform());
    }
        private void Start()
        {
            EventEmitter.Emit(GameEvent.PlayMusic, new MusicEvent(MusicType.quiet_voices_roomtone));

            if (toBeContinue.activeInHierarchy)
            {
                StartCoroutine(HideToBeContinue());
            }
            else
            {
                sceneMask.Hide();
            }

            IEnumerator HideToBeContinue()
            {
                yield return(new WaitForSeconds(2f));

                ProgressHelper.I.SetComplete(false);
                toBeContinue.SetActive(false);
            }
        }
Ejemplo n.º 24
0
        public void TestEmitMultiListener()
        {
            var value1 = 0;
            var value2 = 0;

            EventEmitter.Add(GameEvent.None, Action1);
            EventEmitter.Add(GameEvent.None, Action2);
            EventEmitter.Emit(GameEvent.None, new IntEvent(1));
            Assert.AreEqual(expected: 1, actual: value1);
            Assert.AreEqual(expected: 1, actual: value2);

            void Action1(IEvent @event)
            {
                value1 = (@event as IntEvent).Value;
            }

            void Action2(IEvent @event)
            {
                value2 = (@event as IntEvent).Value;
            }
        }
Ejemplo n.º 25
0
        protected void OnKilled(IEvent @event)
        {
            const float r           = 2000f;
            const float duration    = 0.8f;
            const float shackDelay  = 0.5f;
            const float nerveDelay  = 0.8f;
            const float shackStrong = 50f;
            const int   vibrto      = 200;
            const float startAo     = 180f;
            var         ao          = 180f / m_nerves.Count();
            var         idx         = 0;

            foreach (var cell in m_allCells)
            {
                cell.transform.DOShakePosition(duration, shackStrong, vibrto).SetDelay(shackDelay);
            }

            foreach (var nerve in m_nerves)
            {
                if (nerve == null)
                {
                    continue;
                }

                var x      = r * Math.Cos((startAo + ao * idx) * Math.PI / 180);
                var y      = r * Math.Sin((startAo + ao * idx) * Math.PI / 180);
                var rotate = Random.Range(0, 720);

                nerve.transform.DOLocalMove(new Vector3((float)x, (float)y), duration).SetDelay(nerveDelay);
                nerve.transform.DOLocalRotate(new Vector3(0, 0, rotate), duration).SetDelay(nerveDelay);

                idx++;
            }

            DOVirtual.DelayedCall(nerveDelay, () =>
            {
                EventEmitter.Emit(GameEvent.PlaySound, new SoundEvent(SoundType.Cartoon_Boing, 7));
            });
        }
Ejemplo n.º 26
0
        void OnMouseDrag()
        {
            const int minX = -520;
            const int maxX = 520;
            const int minY = -560;
            const int maxY = 380;

            Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, m_screenPoint.z);
            Vector3 curPosition    = Camera.main.ScreenToWorldPoint(curScreenPoint) + m_offset;

            transform.position = curPosition;

            var x = transform.localPosition.x;
            var y = transform.localPosition.y;

            if (x >= maxX)
            {
                x = maxX;
            }
            else if (x <= minX)
            {
                x = minX;
            }

            if (y >= maxY)
            {
                y = maxY;
            }
            else if (y <= minY)
            {
                y = minY;
            }

            transform.localPosition = new Vector3(x, y);

#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
            EventEmitter.Emit(GameEvent.KeyPressed, new KeyCodeEvent(KeyCode.A));
#endif
        }
Ejemplo n.º 27
0
        public void TestEmitOrder()
        {
            var value  = 0;
            var value1 = 0;
            var value2 = 0;

            EventEmitter.Add(GameEvent.None, Action1);
            EventEmitter.Add(GameEvent.None, Action2);
            EventEmitter.Emit(GameEvent.None);
            Assert.AreEqual(expected: 1, actual: value1);
            Assert.AreEqual(expected: 2, actual: value2);

            void Action1(IEvent @event)
            {
                value1 = ++value;
            }

            void Action2(IEvent @event)
            {
                value2 = ++value;
            }
        }
Ejemplo n.º 28
0
 private void Start()
 {
     sceneMask.Hide(NotifyGameStart);
     EventEmitter.Emit(GameEvent.PlayMusic, new MusicEvent(MusicType.Twirly_Tops));
 }
 public void Triggered()
 {
     EventEmitter.Emit(GameEvent.LevelFail);
 }
Ejemplo n.º 30
0
 private void NotifyGameStart()
 {
     EventEmitter.Emit(GameEvent.GameStart, null);
 }
Ejemplo n.º 31
0
        void Update()
        {
            if (Input.GetKeyUp(KeyCode.Z))
            {
                m_pressedKeyCodes.Remove(KeyCode.Z);
            }

            if (Input.GetKeyUp(KeyCode.X))
            {
                m_pressedKeyCodes.Remove(KeyCode.X);
            }

            if (Input.GetKeyUp(KeyCode.C))
            {
                m_pressedKeyCodes.Remove(KeyCode.C);
            }

            if (Input.GetKeyUp(KeyCode.A))
            {
                m_pressedKeyCodes.Remove(KeyCode.A);
            }

            if (Input.GetKeyUp(KeyCode.D))
            {
                m_pressedKeyCodes.Remove(KeyCode.D);
            }

            if (Input.GetKeyDown(KeyCode.Z))
            {
                m_pressedKeyCodes.Add(KeyCode.Z);
            }

            if (Input.GetKeyDown(KeyCode.X))
            {
                m_pressedKeyCodes.Add(KeyCode.X);
            }

            if (Input.GetKeyDown(KeyCode.C))
            {
                m_pressedKeyCodes.Add(KeyCode.C);
            }

            if (Input.GetKeyDown(KeyCode.A))
            {
                m_pressedKeyCodes.Add(KeyCode.A);
            }

            if (Input.GetKeyDown(KeyCode.D))
            {
                m_pressedKeyCodes.Add(KeyCode.D);
            }

            ResetList();

            foreach (var cell in m_allCells)
            {
                cell.Clear();
            }

            var linkGroup = 0;

            foreach (var keyController in m_keys)
            {
                m_linkGroup.Add(linkGroup, new HashSet <BaseCellController>());
                CheckLinkedCells(keyController, linkGroup);
                linkGroup++;
            }

            SetLinkedCells();


            foreach (var keyController in m_keys.Where(e => m_pressedKeyCodes.Contains(e.KeyCode)))
            {
                m_powerUpGroups.Add(keyController.LinkGroup);
                foreach (var cell in m_linkGroup[keyController.LinkGroup])
                {
                    cell.IsPowerUp = true;
                }
            }

            foreach (var cell in m_allCells)
            {
                if (!cell.IsPowerUp)
                {
                    cell.TriggerPowerUp(false);
                }
            }

            var action = ActionType.None;

            foreach (var cell in m_actions.Where(e => e.IsPowerUp))
            {
                action |= cell.ActionType;
            }

            if (m_pressedKeyCodes.Contains(KeyCode.A) && m_pressedKeyCodes.Contains(KeyCode.D))
            {
                EventEmitter.Emit(GameEvent.NerversRotation, new RotationEvent(RotationStatus.None));
            }
            else if (m_pressedKeyCodes.Contains(KeyCode.A))
            {
                EventEmitter.Emit(GameEvent.NerversRotation, new RotationEvent(RotationStatus.Left));
            }
            else if (m_pressedKeyCodes.Contains(KeyCode.D))
            {
                EventEmitter.Emit(GameEvent.NerversRotation, new RotationEvent(RotationStatus.Right));
            }
            else
            {
                EventEmitter.Emit(GameEvent.NerversRotation, new RotationEvent(RotationStatus.None));
            }

            EventEmitter.Emit(GameEvent.Action, new ActionEvent(action));
        }
    private IEnumerator DiePerform()
    {
        yield return(new WaitForSeconds(1.6f));

        EventEmitter.Emit(GameEvent.Restart);
    }
 public override void EmitEvent(EventInfo eventInfo)
 {
     var emitter = new EventEmitter(TypeBuilder, ImplField);
     emitter.Emit(eventInfo);
 }
Ejemplo n.º 34
0
 private void OnMouseUp()
 {
     m_isDragging = false;
     EventEmitter.Emit(GameEvent.NerversDraging, new BoolEvent(false));
 }