示例#1
0
        public IEnumerator UnskipChild()
        {
            // Given an activating repeating behavior sequence of one not optional and one skipped optional behavior,
            OptionalEndlessBehavior optional    = new OptionalEndlessBehavior();
            EndlessBehavior         notOptional = new EndlessBehavior();
            BehaviorSequence        sequence    = new BehaviorSequence(true, new List <IBehavior>
            {
                notOptional,
                optional,
            });

            sequence.Configure(RuntimeConfigurator.Configuration.GetCurrentMode());

            sequence.LifeCycle.Activate();

            yield return(null);

            sequence.Update();

            notOptional.LifeCycle.MarkToFastForwardStage(Stage.Activating);
            notOptional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating);

            sequence.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>()));

            yield return(null);

            sequence.Update();

            //When you re-enable it,
            sequence.Configure(RuntimeConfigurator.Configuration.GetCurrentMode());

            notOptional.LifeCycle.MarkToFastForwardStage(Stage.Activating);
            notOptional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating);

            while (optional.LifeCycle.Stage != Stage.Activating)
            {
                yield return(null);

                sequence.Update();
            }

            // Then it is not skipped when it's its turn.
            Assert.AreEqual(Stage.Activating, optional.LifeCycle.Stage);
        }
示例#2
0
        public IEnumerator SkipChildNotWhenItIsExecuted()
        {
            // Given an activating behavior sequence of one not optional and one optional behavior,
            OptionalEndlessBehavior optional    = new OptionalEndlessBehavior();
            EndlessBehavior         notOptional = new EndlessBehavior();
            BehaviorSequence        sequence    = new BehaviorSequence(false, new List <IBehavior>
            {
                notOptional,
                optional,
            });

            sequence.Configure(RuntimeConfigurator.Configuration.GetCurrentMode());
            sequence.LifeCycle.Activate();

            yield return(null);

            sequence.Update();

            // When the optional behavior is marked to be skipped before it was its turn,
            sequence.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>()));

            notOptional.LifeCycle.MarkToFastForwardStage(Stage.Activating);
            notOptional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating);

            while (notOptional.LifeCycle.Stage != Stage.Inactive)
            {
                yield return(null);

                sequence.Update();
            }

            while (sequence.LifeCycle.Stage != Stage.Active)
            {
                Assert.AreEqual(Stage.Inactive, optional.LifeCycle.Stage);
                yield return(null);

                sequence.Update();
            }

            // Then it is skipped.
            Assert.AreEqual(Stage.Active, sequence.LifeCycle.Stage);

            yield break;
        }