Beispiel #1
0
        public void TestStateOutsideSetup()
        {
            StateWorker stateWorker = new StateWorker();

            mState.EventDispatcher.AddListener <StatePreEnterEvent>(stateWorker.OnPreEnter);
            mState.EventDispatcher.AddListener <StateEnterEvent>(stateWorker.OnEnter);
            mState.EventDispatcher.AddListener <StatePostEnterEvent>(stateWorker.OnPostEnter);
            mState.EventDispatcher.AddListener <StatePreUpdateEvent>(stateWorker.OnPreUpdate);
            mState.EventDispatcher.AddListener <StateUpdateEvent>(stateWorker.OnUpdate);
            mState.EventDispatcher.AddListener <StatePostUpdateEvent>(stateWorker.OnPostUpdate);
            mState.EventDispatcher.AddListener <StatePreExitEvent>(stateWorker.OnPreExit);
            mState.EventDispatcher.AddListener <StateExitEvent>(stateWorker.OnExit);
            mState.EventDispatcher.AddListener <StatePostExitEvent>(stateWorker.OnPostExit);
            Assert.That(stateWorker.mOnPreEnterCalledCount, Is.EqualTo(0));
            Assert.That(stateWorker.mOnEnterCalledCount, Is.EqualTo(0));
            Assert.That(stateWorker.mOnPostEnterCalledCount, Is.EqualTo(0));
            Assert.That(stateWorker.mOnPreUpdateCalledCount, Is.EqualTo(0));
            Assert.That(stateWorker.mOnUpdateCalledCount, Is.EqualTo(0));
            Assert.That(stateWorker.mOnPostUpdateCalledCount, Is.EqualTo(0));
            Assert.That(stateWorker.mOnPreExitCalledCount, Is.EqualTo(0));
            Assert.That(stateWorker.mOnExitCalledCount, Is.EqualTo(0));
            Assert.That(stateWorker.mOnPostExitCalledCount, Is.EqualTo(0));
            StateChangeArgs stateChangeDetails = new StateChangeArgs(null, null, null, null, null);

            mState.RaisePreEnterEvent(stateChangeDetails);
            mState.RaiseEnterEvent(stateChangeDetails);
            mState.RaisePostEnterEvent(stateChangeDetails);
            mState.RaisePreUpdateEvent();
            mState.RaiseUpdateEvent();
            mState.RaisePostUpdateEvent();
            mState.RaisePreExitEvent(stateChangeDetails);
            mState.RaiseExitEvent(stateChangeDetails);
            mState.RaisePostExitEvent(stateChangeDetails);
            Assert.That(stateWorker.mOnPreEnterCalledCount, Is.EqualTo(1));
            Assert.That(stateWorker.mOnEnterCalledCount, Is.EqualTo(1));
            Assert.That(stateWorker.mOnPostEnterCalledCount, Is.EqualTo(1));
            Assert.That(stateWorker.mOnPreUpdateCalledCount, Is.EqualTo(1));
            Assert.That(stateWorker.mOnUpdateCalledCount, Is.EqualTo(1));
            Assert.That(stateWorker.mOnPostUpdateCalledCount, Is.EqualTo(1));
            Assert.That(stateWorker.mOnPreExitCalledCount, Is.EqualTo(1));
            Assert.That(stateWorker.mOnExitCalledCount, Is.EqualTo(1));
            Assert.That(stateWorker.mOnPostExitCalledCount, Is.EqualTo(1));
            for (int i = 0; i < 10; i++)
            {
                mState.RaiseUpdateEvent();
            }
            Assert.That(stateWorker.mOnUpdateCalledCount, Is.EqualTo(11));
        }
Beispiel #2
0
 public void SetUp()
 {
     mGameObject = new GameObject();
     mGameObject.AddComponent <ImmediateTransition>();
     Assert.NotNull(mGameObject);
     mTransition = mGameObject.GetComponent <ImmediateTransition>();
     Assert.NotNull(mTransition);
     mState           = new State[2];
     mStateWorker     = new StateWorker[2];
     mStateGameObject = new GameObject[2];
     for (int i = 0; i < 2; i++)
     {
         mStateGameObject[i] = new GameObject();
         Assert.NotNull(mStateGameObject[i]);
         mStateGameObject[i].AddComponent <State>();
         mState[i] = mStateGameObject[i].GetComponent <State>();
         Assert.NotNull(mState[i]);
         mStateWorker[i] = new StateWorker();
         Assert.NotNull(mStateWorker[i]);
     }
 }