コード例 #1
0
        public IEnumerator ChangeEmissionRateWithZeroTest()
        {
            // Given a valid confetti machine with particle systems and the new 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[] oldRates = new float[particleSystems.Length];

            for (int i = 0; i < oldRates.Length; i++)
            {
                oldRates[i] = particleSystems[i].emission.rateOverTimeMultiplier;
            }

            float multiplier = 0f;

            // When I change the area radius,
            confettiMachine.ChangeAreaRadius(multiplier);

            // Then the emission rate is accordingly changed. It equals squared radius (radius has 0.01f as lowest value) multiplied by the default emission rate over time for radius equals 1.
            for (int i = 0; i < oldRates.Length; i++)
            {
                Assert.IsTrue(Math.Abs(particleSystems[i].emission.rateOverTimeMultiplier - (oldRates[i] * 0.01f * 0.01f)) < 0.001f);
            }

            yield break;
        }
コード例 #2
0
        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;
        }