public IEnumerator SamePosition() { // Given MoveObjectBehavior that takes two training scene objects with the same position and rotation, and positive transition duration, float duration = 0.05f; GameObject movedGo = new GameObject(movedName); TrainingSceneObject moved = movedGo.AddComponent <TrainingSceneObject>(); moved.ChangeUniqueName(movedName); GameObject targetGo = new GameObject(positionProviderName); TrainingSceneObject target = targetGo.AddComponent <TrainingSceneObject>(); target.ChangeUniqueName(positionProviderName); MoveObjectBehavior behavior = new MoveObjectBehavior(moved, target, duration); behavior.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); // When we activate the behavior, behavior.LifeCycle.Activate(); yield return(null); behavior.Update(); // Then it does not finish its activation immediately. Assert.IsTrue(behavior.LifeCycle.Stage == Stage.Activating); // Cleanup created game objects. Object.DestroyImmediate(movedGo); Object.DestroyImmediate(targetGo); yield return(null); }
public IEnumerator PositiveDuration() { // Given MoveObjectBehavior that takes two training scene objects with different positions and rotations, and positive transition duration, float duration = 0.05f; GameObject movedGo = new GameObject(movedName); TrainingSceneObject moved = movedGo.AddComponent <TrainingSceneObject>(); moved.ChangeUniqueName(movedName); GameObject positionProviderGo = new GameObject(positionProviderName); positionProviderGo.transform.position = new Vector3(1, 2, 50); positionProviderGo.transform.rotation = Quaternion.Euler(57, 195, 188); TrainingSceneObject target = positionProviderGo.AddComponent <TrainingSceneObject>(); target.ChangeUniqueName(positionProviderName); MoveObjectBehavior behavior = new MoveObjectBehavior(moved, target, duration); behavior.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); // When I activate that behavior and wait for transition duration, behavior.LifeCycle.Activate(); float startTime = Time.time; while (Stage.Active != behavior.LifeCycle.Stage) { yield return(null); behavior.Update(); } // Then behavior activation is completed, and moved object position and rotation matches positionProvider's. Assert.IsTrue(Time.time - startTime > duration); Assert.IsTrue((movedGo.transform.position - positionProviderGo.transform.position).sqrMagnitude < 0.001f); Assert.IsTrue(Quaternion.Dot(movedGo.transform.rotation, positionProviderGo.transform.rotation) > 0.999f); // Cleanup created game objects. Object.DestroyImmediate(movedGo); Object.DestroyImmediate(positionProviderGo); yield return(null); }
public IEnumerator ZeroDuration() { // Given MoveObjectBehavior that takes two training scene objects with different positions and rotations, and transition duration that equals zero, float duration = 0f; GameObject movedGo = new GameObject(movedName); TrainingSceneObject moved = movedGo.AddComponent <TrainingSceneObject>(); moved.ChangeUniqueName(movedName); GameObject targetGo = new GameObject(positionProviderName); targetGo.transform.position = new Vector3(1, 2, 50); targetGo.transform.rotation = Quaternion.Euler(123, 15, 8); TrainingSceneObject target = targetGo.AddComponent <TrainingSceneObject>(); target.ChangeUniqueName(positionProviderName); MoveObjectBehavior behavior = new MoveObjectBehavior(moved, target, duration); behavior.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); // When we activate that behavior, behavior.LifeCycle.Activate(); yield return(null); behavior.Update(); // Then it immediately completes its activation, and moved object position and rotation matches the ones of positionProvider. Assert.IsTrue(behavior.LifeCycle.Stage == Stage.Active); Assert.IsTrue((movedGo.transform.position - targetGo.transform.position).sqrMagnitude < 0.001f); Assert.IsTrue(Quaternion.Dot(movedGo.transform.rotation, targetGo.transform.rotation) > 0.999f); // Cleanup created game objects. Object.DestroyImmediate(movedGo); Object.DestroyImmediate(targetGo); yield return(null); }