コード例 #1
0
        public IEnumerator ActivateWithParametersTest()
        {
            // Given a valid confetti machine with particle systems and some valid positive parameters,
            GameObject      machineObject   = Object.Instantiate(Resources.Load <GameObject>(pathToDefaultPrefab));
            ConfettiMachine confettiMachine = machineObject.GetComponent <ConfettiMachine>();

            float newDuration = 22.5f;
            float newRadius   = 9.75f;

            ParticleSystem[] particleSystems = machineObject.GetComponentsInChildren <ParticleSystem>(true);
            Assert.IsTrue(particleSystems.Length > 0);

            float oldRate = particleSystems[0].emission.rateOverTimeMultiplier;

            // When I call Activate with parameters on it,
            confettiMachine.Activate(newRadius, newDuration);

            // Then the confetti machine is active and all of its particle systems are active and playing with the new given parameters.
            Assert.IsTrue(confettiMachine.IsActive);

            foreach (ParticleSystem particleSystem in particleSystems)
            {
                Assert.IsTrue(particleSystem.isPlaying);
                Assert.IsTrue(Math.Abs(particleSystem.shape.radius - newRadius) < 0.001f);
                Assert.IsTrue(Math.Abs(particleSystem.main.duration - newDuration) < 0.001f);
            }

            Assert.IsTrue(Math.Abs(particleSystems[0].emission.rateOverTimeMultiplier - (oldRate * newRadius * newRadius)) < 0.001f);

            yield break;
        }
コード例 #2
0
        public IEnumerator DeactivateWhenActiveTest()
        {
            // Given an active valid confetti machine,
            GameObject      machineObject   = Object.Instantiate(Resources.Load <GameObject>(pathToDefaultPrefab));
            ConfettiMachine confettiMachine = machineObject.GetComponent <ConfettiMachine>();

            confettiMachine.Activate();

            ParticleSystem[] particleSystems = machineObject.GetComponentsInChildren <ParticleSystem>();
            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;
        }
コード例 #3
0
        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;
        }