public IEnumerator ActivateWithoutParametersTest() { // Given a valid confetti machine, GameObject machineObject = Object.Instantiate(Resources.Load <GameObject>(pathToDefaultPrefab)); ConfettiMachine confettiMachine = machineObject.GetComponent <ConfettiMachine>(); // When I call Activate without parameters on it, confettiMachine.Activate(); // Then the confetti machine is active and all of its particle systems are active and playing. Assert.IsTrue(confettiMachine.IsActive); ParticleSystem[] particleSystems = machineObject.GetComponentsInChildren <ParticleSystem>(); Assert.IsTrue(particleSystems.Length > 0); foreach (ParticleSystem particleSystem in particleSystems) { Assert.IsTrue(particleSystem.isPlaying); } yield break; }
public IEnumerator ChangeToZeroAreaRadiusTest() { // Given a valid confetti machine with particle systems and a area radius equals zero, GameObject machineObject = Object.Instantiate(Resources.Load <GameObject>(pathToDefaultPrefab)); ConfettiMachine confettiMachine = machineObject.GetComponent <ConfettiMachine>(); ParticleSystem[] particleSystems = machineObject.GetComponentsInChildren <ParticleSystem>(true); Assert.IsTrue(particleSystems.Length > 0); float newRadius = 0f; // When I change the area radius, confettiMachine.ChangeAreaRadius(newRadius); // Then the radius is changed to 0.01f (lowest possible value) in all provided particle systems. foreach (ParticleSystem particleSystem in particleSystems) { Assert.IsTrue(Math.Abs(particleSystem.shape.radius - 0.01f) < 0.001f); } yield break; }
public IEnumerator DeactivateWhenNotActiveTest() { // Given an inactive valid confetti machine, GameObject machineObject = Object.Instantiate(Resources.Load <GameObject>(pathToDefaultPrefab)); ConfettiMachine confettiMachine = machineObject.GetComponent <ConfettiMachine>(); ParticleSystem[] particleSystems = machineObject.GetComponentsInChildren <ParticleSystem>(true); Assert.IsTrue(particleSystems.Length > 0); // When I deactivate it, confettiMachine.Deactivate(); // Then the confetti machine is not active and all of its particle systems are deactivated and not playing. Assert.IsFalse(confettiMachine.IsActive); foreach (ParticleSystem particleSystem in particleSystems) { Assert.IsFalse(particleSystem.isPlaying); Assert.IsFalse(particleSystem.gameObject.activeSelf); } yield break; }
public IEnumerator ChangeToPositiveEmissionDurationTest() { // Given a valid confetti machine with particle systems and a new positive duration, GameObject machineObject = Object.Instantiate(Resources.Load <GameObject>(pathToDefaultPrefab)); ConfettiMachine confettiMachine = machineObject.GetComponent <ConfettiMachine>(); ParticleSystem[] particleSystems = machineObject.GetComponentsInChildren <ParticleSystem>(true); Assert.IsTrue(particleSystems.Length > 0); float newDuration = particleSystems[0].main.duration + confettiMachine.EmissionDuration + 1.47f; // When I change the emission duration, confettiMachine.ChangeEmissionDuration(newDuration); // Then it is accordingly changed in the confetti machine component itself and in all of its particle systems. Assert.IsTrue(Math.Abs(confettiMachine.EmissionDuration - newDuration) < 0.001f); foreach (ParticleSystem particleSystem in particleSystems) { Assert.IsTrue(Math.Abs(particleSystem.main.duration - newDuration) < 0.001f); } yield break; }