Update() public method

public Update ( ) : void
return void
Esempio n. 1
0
        public IEnumerator ConditionsActivateOnlyAfterBehaviors()
        {
            Step step = new Step("Step1");
            EndlessConditionMock conditionMock = new EndlessConditionMock();
            EndlessBehaviorMock  behaviorMock  = new EndlessBehaviorMock();
            Transition           transition    = new Transition();

            transition.Data.Conditions.Add(conditionMock);
            step.Data.Transitions.Data.Transitions.Add(transition);
            step.Data.Behaviors.Data.Behaviors.Add(behaviorMock);
            step.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            step.LifeCycle.Activate();

            while (behaviorMock.LifeCycle.Stage != Stage.Activating)
            {
                Assert.AreEqual(Stage.Activating, step.LifeCycle.Stage);
                Assert.AreEqual(Stage.Inactive, conditionMock.LifeCycle.Stage);
                yield return(null);

                step.Update();
            }

            behaviorMock.LifeCycle.MarkToFastForwardStage(Stage.Activating);

            while (conditionMock.LifeCycle.Stage != Stage.Active)
            {
                Assert.AreEqual(Stage.Activating, step.LifeCycle.Stage);
                yield return(null);

                step.Update();
            }
        }
Esempio n. 2
0
        public IEnumerator StepWithCondition()
        {
            Step step = new Step("Step1");
            EndlessConditionMock conditionMock = new EndlessConditionMock();
            Transition           transition    = new Transition();

            transition.Data.Conditions.Add(conditionMock);
            step.Data.Transitions.Data.Transitions.Add(transition);
            step.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            step.LifeCycle.Activate();

            while (step.LifeCycle.Stage != Stage.Active)
            {
                yield return(null);

                step.Update();
            }

            Stage stepInitialStage              = step.LifeCycle.Stage;
            Stage conditionInitialStage         = conditionMock.LifeCycle.Stage;
            bool  conditionIsCompletedInitially = conditionMock.IsCompleted;

            conditionMock.Autocomplete();

            bool conditionIsCompleted = conditionMock.IsCompleted;

            step.LifeCycle.Deactivate();

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

                step.Update();
            }

            Stage stepStageInEnd            = step.LifeCycle.Stage;
            Stage conditionStageInEnd       = conditionMock.LifeCycle.Stage;
            bool  conditionIsCompletedInEnd = conditionMock.IsCompleted;

            // Check states were correct
            Assert.AreEqual(Stage.Active, stepInitialStage, "Step should be active initially");
            Assert.AreEqual(Stage.Active, conditionInitialStage, "Condition should be active initially");
            Assert.IsFalse(conditionIsCompletedInitially, "Condition should not completed initially");

            Assert.IsTrue(conditionIsCompleted, "Condition should be completed now");

            Assert.AreEqual(Stage.Inactive, stepStageInEnd, "Step should be inactive in the end");
            Assert.AreEqual(Stage.Inactive, conditionStageInEnd, "Condition should not be active in the end");
            Assert.IsTrue(conditionIsCompletedInEnd, "Condition should be completed in the end");

            yield return(null);
        }
Esempio n. 3
0
        public IEnumerator UnlockBehaviorOnLockedObject()
        {
            // Given an UnlockObjectBehavior, a locked game object, and a full training step,
            GameObject          gameObject   = new GameObject("Test");
            TrainingSceneObject targetObject = gameObject.AddComponent <TrainingSceneObject>();

            Step       step       = new Step("TestStep");
            Transition transition = new Transition();

            step.Data.Transitions.Data.Transitions.Add(transition);

            UnlockObjectBehavior unlockBehavior = new UnlockObjectBehavior(targetObject);

            step.Data.Behaviors.Data.Behaviors.Add(unlockBehavior);
            step.Configure(RuntimeConfigurator.Configuration.GetCurrentMode());

            targetObject.SetLocked(true);

            // When we fulfill the step,
            bool isLockedInitially = targetObject.IsLocked;

            step.LifeCycle.Activate();

            while (step.LifeCycle.Stage != Stage.Active)
            {
                yield return(null);

                step.Update();
            }

            bool isLockedDuringStep = targetObject.IsLocked;

            step.LifeCycle.Deactivate();

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

                step.Update();
            }

            bool isLockedInEnd = targetObject.IsLocked;

            // Then the game object was locked initially, unlocked during step execution, and locked after the completion.
            Assert.IsTrue(isLockedInitially, "Object should be locked initially");
            Assert.IsFalse(isLockedDuringStep, "Object should be unlocked during step");
            Assert.IsTrue(isLockedInEnd, "Object should be locked in the end");

            // Cleanup created game objects.
            Object.DestroyImmediate(gameObject);
            yield return(null);
        }
Esempio n. 4
0
    public void test_step()
    {
        var step = new Step(0f, 10f, 1.0f);

        Assert(step.Value == 0f);

        step.Update(5.0f);
        Assert(step.Value == 5f);
        Assert(step.Next == 1f);

        step.Update(10.0f);
        Assert(step.Value == 10f);
        Assert(step.Next == 0f);
    }
Esempio n. 5
0
    public void test_step_down()
    {
        var step = new Step(0f, -10f, 1.0f);

        Assert(step.Value == 0f);
        Assert(step.Next == -1f);

        step.Update(5.0f);
        Assert(step.Value == -5f);
        Assert(step.Next == -1f);

        step.Update(10.0f);
        Assert(step.Value == -10f);
        Assert(step.Next == 0f);
    }
Esempio n. 6
0
        public IEnumerator FastForwardActivatingBehavior()
        {
            // Given a LockObjectBehavior, an unlocked game object, and an activated full training step,
            GameObject          gameObject   = new GameObject("Test");
            TrainingSceneObject targetObject = gameObject.AddComponent <TrainingSceneObject>();

            Step       step       = new Step("TestStep");
            Transition transition = new Transition();

            step.Data.Transitions.Data.Transitions.Add(transition);

            LockObjectBehavior behavior = new LockObjectBehavior(targetObject);

            step.Data.Behaviors.Data.Behaviors.Add(behavior);

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

            bool isLockedInitially = targetObject.IsLocked;

            step.LifeCycle.Activate();

            yield return(null);

            step.Update();

            // When we mark the behavior to fast-forward,
            behavior.LifeCycle.MarkToFastForward();

            // Then it should work without any differences because the behavior is done immediately anyways.
            bool isLockedDuringStep = targetObject.IsLocked;

            step.LifeCycle.Deactivate();

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

                step.Update();
            }

            bool isLockedInEnd = targetObject.IsLocked;

            Assert.IsFalse(isLockedInitially, "Object should not be locked initially");
            Assert.IsTrue(isLockedDuringStep, "Object should be locked during step");
            Assert.IsFalse(isLockedInEnd, "Object should not be locked in the end");

            yield break;
        }
Esempio n. 7
0
        public IEnumerator ActivateTest()
        {
            // Setup Step with event listener for checking states.
            Step step = new Step("Step1");
            EndlessConditionMock conditionMock = new EndlessConditionMock(); // add condition to prevent step from auto-completing on activation

            Transition transition = new Transition();

            transition.Data.Conditions.Add(conditionMock);
            step.Data.Transitions.Data.Transitions.Add(transition);
            step.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // Activate should work on simple steps.
            step.LifeCycle.Activate();

            while (step.LifeCycle.Stage != Stage.Active)
            {
                yield return(null);

                step.Update();
            }

            // Chapter should be active now.
            Assert.AreEqual(Stage.Active, step.LifeCycle.Stage, "Step was not activated");
        }
Esempio n. 8
0
        public IEnumerator StepWithInitiallyCompletedConditionResetsCondition()
        {
            // Given a step with an already completed condition,
            Step       step      = new Step("Step1");
            ICondition condition = new EndlessConditionMock();

            condition.Autocomplete();
            Transition transition = new Transition();

            transition.Data.Conditions.Add(condition);
            step.Data.Transitions.Data.Transitions.Add(transition);
            step.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // When it is activated,
            step.LifeCycle.Activate();

            while (condition.LifeCycle.Stage != Stage.Active)
            {
                yield return(null);

                step.Update();
            }

            // Then the condition is reset to not completed.
            Assert.IsFalse(condition.IsCompleted);

            yield return(null);
        }
Esempio n. 9
0
        public IEnumerator ActivateEventEmitted()
        {
            // Setup Step with event listener for checking states.
            Step step                = new Step("Step1");
            bool isActivated         = false;
            bool isActivationStarted = false;

            step.LifeCycle.StageChanged += (sender, args) =>
            {
                if (args.Stage == Stage.Active)
                {
                    isActivated = true;
                }

                if (args.Stage == Stage.Activating)
                {
                    isActivationStarted = true;
                }
            };

            step.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            // Activate should work on simple steps.
            step.LifeCycle.Activate();

            while (step.LifeCycle.Stage != Stage.Active)
            {
                yield return(null);

                step.Update();
            }

            Assert.IsTrue(isActivationStarted, "Step was not activated");
            Assert.IsTrue(isActivated, "Step was not set to active");
        }
Esempio n. 10
0
        public void Update(float delta)
        {
            if (!IsRunning)
            {
                return;
            }

            if (IsComplete || _steps.Count < _currentIndex)
            {
                return;
            }

            if (!CurrentStep.IsComplete)
            {
                CurrentStep.Update(delta);
            }
            else
            {
                _currentIndex++;

                if (_currentIndex >= _steps.Count)
                {
                    IsComplete = true;
                }
                else
                {
                    CurrentStep.Start();
                    Update(delta);
                }
            }
        }
Esempio n. 11
0
        public IEnumerator EmptyStepRaisesEvents()
        {
            Step step = new Step("Step1");

            step.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            bool wasActivated   = false;
            bool wasDeactivated = false;

            step.LifeCycle.StageChanged += (sender, args) =>
            {
                if (args.Stage == Stage.Active)
                {
                    wasActivated = true;
                }

                if (args.Stage == Stage.Inactive)
                {
                    wasDeactivated = true;
                }
            };

            // Activate should work on simple steps.
            step.LifeCycle.Activate();

            while (step.LifeCycle.Stage != Stage.Active)
            {
                yield return(null);

                step.Update();
            }

            step.LifeCycle.Deactivate();

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

                step.Update();
            }

            // Step should be completed, and have become activated and deactivated.
            Assert.IsTrue(wasActivated, "Step was not activated");
            Assert.IsTrue(wasDeactivated, "Step was not deactivated");
        }
        public IEnumerator ConditionCompletedAfterTimingBehaviorInStep()
        {
            float      targetDuration = 0.5f;
            Step       step           = new Step("Step1");
            ICondition condition      = new TimeoutCondition(targetDuration, "Timeout1");
            Transition transition     = new Transition();
            IBehavior  behavior       = new TimeoutBehaviorMock(targetDuration, targetDuration);

            transition.Data.Conditions.Add(condition);
            step.Data.Transitions.Data.Transitions.Add(transition);
            step.Data.Behaviors.Data.Behaviors.Add(behavior);
            step.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode);

            step.LifeCycle.Activate();

            // Activation frame
            yield return(null);

            step.Update();

            float startTime = Time.time;

            while (behavior.LifeCycle.Stage != Stage.Active)
            {
                yield return(null);

                step.Update();
            }

            float behaviorDuration = Time.time - startTime;

            Assert.AreEqual(targetDuration, behaviorDuration, Time.deltaTime);
            Assert.IsFalse(condition.IsCompleted);

            // Process frames
            yield return(null);

            step.Update();
            yield return(null);

            step.Update();
            yield return(null);

            step.Update();

            startTime = Time.time;
            while (condition.IsCompleted == false)
            {
                yield return(null);

                step.Update();
            }

            float conditionDuration = Time.time - startTime;

            Assert.AreEqual(targetDuration, conditionDuration, 2 * Time.deltaTime);
            Assert.IsTrue(condition.IsCompleted);
        }
Esempio n. 13
0
    public void test_step_new_target()
    {
        var step = new Step(0f, 10f, 1.0f);

        step.Update(5.0f);
        step.End = -10f;
        step.Update(1f);
        step.Update(1f);
        step.Update(1f);
        step.Update(1f);
        step.Update(1f);
        Assert(step.Value == 0f);
    }