/// <summary>
        /// Sets up the various components of the Tutorial Manager system
        /// </summary>
        static void BootstrapAdaptiveContent()
        {
            var modelMiddleware = TutorialManagerModelMiddleware.GetInstance();
            var dispatcher      = AdaptiveStateDispatcher.GetInstance();

            dispatcher.OnEnterState += FSM_EnterState;
            dispatcher.OnExitState  += FSM_ExitState;

            var fsm = new TutorialManagerFSM();

            fsm.dispatcher = dispatcher;
            m_State        = new TutorialManagerState(fsm);

            string cueTutorial = m_State.tutorialId;

            if (string.IsNullOrEmpty(cueTutorial))
            {
                if (modelMiddleware.TMData.tutorials.Count == 0)
                {
                    modelMiddleware.CreateTutorialEntity("EmptyTutorial");
                    modelMiddleware.CreateStepEntity("EmptyStep", "EmptyTutorial");
                }
                cueTutorial = modelMiddleware.TMData.tutorials[0].id;
            }
            fsm.stateList = modelMiddleware.TMData.tutorialTable[cueTutorial].steps;

            var provider = StateSystemProvider.GetInstance();

            provider.SetDispatcher(dispatcher);
            provider.SetDataStore(modelMiddleware);
        }
        public void TestDispatcherListener()
        {
            var dispatcher = AdaptiveStateDispatcher.GetInstance();
            var listener   = new TestDispatcherListener(dispatcher);

            dispatcher.DispatchEnterState(state1);

            Assert.That(state1, Is.EqualTo(listener.lastEnterId), string.Format("last entered state should be {0}", state1));
            Assert.IsTrue(string.IsNullOrEmpty(listener.lastExitId), "should be no exit state yet");
            Assert.AreEqual(1, listener.count, "should have fired 1 event");

            dispatcher.DispatchExitState(state1);
            Assert.That(state1, Is.EqualTo(listener.lastExitId), string.Format("last exited state should be {0}", state1));
            Assert.AreEqual(2, listener.count, "should have fired 2 events");

            dispatcher.DispatchEnterState(state2);
            Assert.That(state2, Is.EqualTo(listener.lastEnterId), string.Format("last entered state should be {0}", state2));
            Assert.That(state1, Is.EqualTo(listener.lastExitId), string.Format("last exited state should be {0}", state1));
            Assert.AreEqual(3, listener.count, "should have fired 3 events");

            dispatcher.DispatchEnterState(state3);
            Assert.That(state3, Is.EqualTo(listener.lastEnterId), string.Format("last entered state should be {0}", state3));
            Assert.That(state1, Is.EqualTo(listener.lastExitId), string.Format("last exited state should be {0}", state1));
            Assert.AreEqual(4, listener.count, "should have fired 4 events");

            dispatcher.DispatchExitState(state3);
            Assert.That(state3, Is.EqualTo(listener.lastEnterId), string.Format("last entered state should be {0}", state3));
            Assert.That(state3, Is.EqualTo(listener.lastExitId), string.Format("last exited state should be {0}", state3));
            Assert.AreEqual(5, listener.count, "should have fired 5 events");

            dispatcher.DispatchExitState(state1);
            Assert.That(state3, Is.EqualTo(listener.lastEnterId), string.Format("last entered state should be {0}", state3));
            Assert.That(state1, Is.EqualTo(listener.lastExitId), string.Format("last exited state should be {0}", state1));
            Assert.AreEqual(6, listener.count, "should have fired 6 events");
        }
예제 #3
0
 public static AdaptiveStateDispatcher GetInstance()
 {
     if (m_Instance == null)
     {
         m_Instance = new AdaptiveStateDispatcher();
     }
     return(m_Instance);
 }
        public void TestSingleton()
        {
            var dispatcher = AdaptiveStateDispatcher.GetInstance();

            Assert.IsNotNull(dispatcher, "singleton dispatcher should exist");
            var dispatcher2 = AdaptiveStateDispatcher.GetInstance();

            Assert.AreSame(dispatcher, dispatcher2, "singleton dispatcher should be the same object");
        }
        protected void BootstrapRuntime()
        {
            modelMiddleware = TutorialManagerModelMiddleware.GetInstance();
            dispatcher      = AdaptiveStateDispatcher.GetInstance();
            provider        = StateSystemProvider.GetInstance();

            fsm            = new TutorialManagerFSM();
            fsm.dispatcher = dispatcher;

            provider.SetDispatcher(dispatcher);
            provider.SetDataStore(modelMiddleware);
        }