public IEnumerator ChangeToZeroEmissionDurationTest() { // Given a valid confetti machine with particle systems and the new duration 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 newDuration = 0f; // 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) < 0.1f); foreach (ParticleSystem particleSystem in particleSystems) { // Note it is not possible to set a particle system's duration to zero, Unity will silently set it to 0.05f. Assert.IsTrue(Math.Abs(particleSystem.main.duration) < 0.1f); } 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; }