public void testProjectileDuration() { ProjectileBehaviour projectile = RuntimeTestHelpers.CreateObjectWithComponent <ProjectileBehaviour>(); projectile.speed = 1f; projectile.lifetime = 1f; projectile.damage = 1f; projectile.force = 1f; // start projectile projectile.InitializeAndActivate(Vector3.zero, Vector3.forward, DamageDealer.Default); Assert.IsTrue(projectile.IsAlive, "Projectile not alive after activation"); // still alive after .5s projectile.CallPrivateMethod("UpdateLifeTimer", 0.5f); Assert.IsTrue(projectile.IsAlive, "Projectile not alive after .5s"); // not alive after 1s projectile.CallPrivateMethod("UpdateLifeTimer", 0.5f); Assert.IsFalse(projectile.IsAlive, "Projectile alive after lifetime"); // projectile hasn't moved without calling update methods VectorAssert.AreEqual(Vector3.zero, projectile.PhysicsPosition, DELTA, "Physics position moved"); VectorAssert.AreEqual(Vector3.zero, projectile.transform.position, DELTA, "Transform position moved"); // physics can't move while not alive projectile.CallPrivateMethod("PhysicsUpdate", 1f); VectorAssert.AreEqual(Vector3.zero, projectile.PhysicsPosition, DELTA, "Physics position moved"); projectile.CallPrivateMethod("MoveToRaycastGoal", 1f); VectorAssert.AreEqual(Vector3.zero, projectile.transform.position, DELTA, "Transform position moved"); }
private void ensureCameraExists() { if (Camera.main == null) { Camera camera = RuntimeTestHelpers.CreateObjectWithComponent <Camera>("Main Camera"); camera.tag = "MainCamera"; } }
public void SingleDamageHandlerTest() { DamageReceiver receiver = RuntimeTestHelpers.CreateObjectWithComponent <DamageReceiver>("Damage Receiver"); MockDamageHandlerBehaviour handler = receiver.AddComponent <MockDamageHandlerBehaviour>(); receiver.CallAwakeAndStartRecursive(); Assert.False(handler.wasDamaged, "Handler damaged before test conditions."); receiver.ApplyDamage(1f, Vector3.zero, Vector3.zero, DamageDealer.Default); Assert.True(handler.wasDamaged, "Handler not damaged."); }
public void TestDeathHandler() { DamageReceiver receiver = RuntimeTestHelpers.CreateObjectWithComponent <DamageReceiver>("Health Test"); HealthBehaviour health = receiver.AddComponent <HealthBehaviour>(); MockDeathHandlerBehaviour handler = receiver.AddComponent <MockDeathHandlerBehaviour>(); health.maxHealth = 1f; receiver.CallAwakeAndStartRecursive(); Assert.False(handler.isDead, "Handler dead before taking damage"); receiver.ApplyDamage(1f, Vector3.zero, Vector3.zero, DamageDealer.Default); Assert.True(handler.isDead, "Handler still alive after taking damage"); }
public void testTransformFollowPhysics() { ProjectileBehaviour projectile = RuntimeTestHelpers.CreateObjectWithComponent <ProjectileBehaviour>(); projectile.speed = 1f; projectile.lifetime = 10f; projectile.damage = 1f; projectile.force = 1f; // start projectile projectile.InitializeAndActivate(Vector3.zero, Vector3.forward, DamageDealer.Default); // test no movement VectorAssert.AreEqual(Vector3.zero, projectile.PhysicsPosition, DELTA, "Physics position not zero"); VectorAssert.AreEqual(Vector3.zero, projectile.transform.position, DELTA, "Transform position not zero"); // move physics position forward 2s projectile.CallPrivateMethod("PhysicsUpdate", 2f); // test physics moved but not game object VectorAssert.AreEqual(Vector3.forward * 2f, projectile.PhysicsPosition, DELTA, "Physics position incorrect"); VectorAssert.AreEqual(Vector3.zero, projectile.transform.position, DELTA, "Transform position not zero"); // move transform position by half step projectile.CallPrivateMethod("MoveToRaycastGoal", 1f); VectorAssert.AreEqual(Vector3.forward * 2f, projectile.PhysicsPosition, DELTA, "Physics position incorrect"); VectorAssert.AreEqual(Vector3.forward, projectile.transform.position, DELTA, "Transform position not half of physics position"); // move transform position by another half step projectile.CallPrivateMethod("MoveToRaycastGoal", 1f); VectorAssert.AreEqual(Vector3.forward * 2f, projectile.PhysicsPosition, DELTA, "Physics position incorrect"); VectorAssert.AreEqual(projectile.PhysicsPosition, projectile.transform.position, DELTA, "Transform position does not match physics position"); // transform position shouldn't move without physics position moving projectile.CallPrivateMethod("MoveToRaycastGoal", 5f); VectorAssert.AreEqual(Vector3.forward * 2f, projectile.PhysicsPosition, DELTA, "Physics position incorrect"); VectorAssert.AreEqual(projectile.PhysicsPosition, projectile.transform.position, DELTA, "Transform position does not match physics position"); }
public void TestHealthRemoved() { DamageReceiver receiver = RuntimeTestHelpers.CreateObjectWithComponent <DamageReceiver>("Health Test"); HealthBehaviour health = receiver.AddComponent <HealthBehaviour>(); health.maxHealth = 1f; receiver.CallAwakeAndStartRecursive(); Assert.True(health.IsAlive, "Dead before taking damage"); Assert.AreEqual(1f, health.CurrentHealth, 0.001f, "Health doesn't match specified value"); receiver.ApplyDamage(0.75f, Vector3.zero, Vector3.zero, DamageDealer.Default); Assert.True(health.IsAlive, "Dead before all health removed"); Assert.AreEqual(0.25f, health.CurrentHealth, 0.001f, "Health doesn't match specified value minus removed amount"); receiver.ApplyDamage(0.25f, Vector3.zero, Vector3.zero, DamageDealer.Default); Assert.False(health.IsAlive, "Still alive after all health removed"); Assert.AreEqual(0f, health.CurrentHealth, 0.001f, "Still health remaining after dead"); }
public void testCameraFade() { ensureCameraExists(); CameraAimBehaviour camera = RuntimeTestHelpers.CreateObjectWithComponent <CameraAimBehaviour>("Camera Aim"); MeshRenderer renderer = camera.AddComponent <MeshRenderer>(); renderer.sharedMaterial = new Material(Shader.Find("Standard")); camera.charRenderer = renderer; camera.transparencyMaterial = new Material(Shader.Find("Standard")); camera.CallAwakeAndStartRecursive(); camera.minFadeDistance = 1f; camera.maxFadeDistance = 2f; // move past max distance camera.CallPrivateMethod("FadeCameraDistance", 3f); Assert.IsTrue(renderer.enabled, "Renderer not displayed"); Assert.AreNotEqual(renderer.sharedMaterial, camera.transparencyMaterial, "Using transparent material when too far away."); // move to midpoint camera.CallPrivateMethod("FadeCameraDistance", 1.5f); Assert.IsTrue(renderer.enabled, "Renderer not displayed"); Assert.AreEqual(renderer.sharedMaterial, camera.transparencyMaterial, "Not using transparent material when in fade range"); Assert.AreEqual(camera.transparencyMaterial.color.a, 0.5f, 0.01f, "Expected 50% opacity in middle of fade range"); // move up before min distance camera.CallPrivateMethod("FadeCameraDistance", 0.5f); Assert.IsFalse(renderer.enabled, "Renderer displayed when not expected"); // reset past max distance camera.CallPrivateMethod("FadeCameraDistance", 3f); Assert.IsTrue(renderer.enabled, "Renderer not displayed"); Assert.AreNotEqual(renderer.sharedMaterial, camera.transparencyMaterial, "Using transparent material when too far away."); }
public void testProjectileTransformMoveNotAlive() { ProjectileBehaviour projectile = RuntimeTestHelpers.CreateObjectWithComponent <ProjectileBehaviour>(); projectile.speed = 1f; projectile.lifetime = 1f; projectile.damage = 1f; projectile.force = 1f; // start projectile projectile.InitializeAndActivate(Vector3.zero, Vector3.forward, DamageDealer.Default); projectile.CallPrivateMethod("PhysicsUpdate", 1f); projectile.CallPrivateMethod("UpdateLifeTimer", 1f); // assert projectile not alive and transform not updated VectorAssert.AreEqual(Vector3.forward, projectile.PhysicsPosition, DELTA, "Physics position not correct"); Assert.IsFalse(projectile.IsAlive, "Projectile alive after lifetime"); VectorAssert.AreEqual(Vector3.zero, projectile.transform.position, DELTA, "Transform position not correct"); // transform moves to final position regardless of time projectile.CallPrivateMethod("MoveToRaycastGoal", 0.01f); VectorAssert.AreEqual(Vector3.forward, projectile.transform.position, DELTA, "Transform did not move to final position"); }