Esempio n. 1
0
 public static void Scale(ParticleSystem particles, float scale, bool includeChildren = true, ParticleScalerOptions options = null) {
     ScaleSystem(particles, scale, false, options);
     if (includeChildren) {
         var children = particles.GetComponentsInChildren<ParticleSystem>(includeInactive: true);   // my includeInactive addition
         for (var i = children.Length; i-- > 0;) {
             if (children[i] == particles) { continue; }
             ScaleSystem(children[i], scale, true, options);
         }
     }
 }
Esempio n. 2
0
        private static void ScaleSystem(ParticleSystem particles, float scale, bool scalePosition, ParticleScalerOptions options = null) {
            if (options == null) {
                options = defaultOptions;
            }
            if (scalePosition) {
                particles.transform.localPosition *= scale;
            }

            var mainModule = particles.main;
            mainModule.startSizeMultiplier *= scale;    //particles.startSize *= scale; Deprecated in Unity 5.5
            mainModule.gravityModifierMultiplier *= scale;  //particles.gravityModifier *= scale;   Deprecated in Unity 5.5
            mainModule.startSpeedMultiplier *= scale;   //particles.startSpeed *= scale;    Deprecated in Unity 5.5

            if (options.shape) {
                var shape = particles.shape;
                shape.radius *= scale;
                shape.box = shape.box * scale;
            }

            // Currently disabled due to a bug in Unity 5.3.4. 
            // If any of these fields are using "Curves", the editor will shut down when they are modified.
            // If you're not using any curves, feel free to uncomment the following lines;
            // ************************************************************************************************
            if (options.velocity) {
                var vel = particles.velocityOverLifetime;
                vel.x = ScaleMinMaxCurve(vel.x, scale);
                vel.y = ScaleMinMaxCurve(vel.y, scale);
                vel.z = ScaleMinMaxCurve(vel.z, scale);
            }
            if (options.clampVelocity) {
                var clampVel = particles.limitVelocityOverLifetime;
                clampVel.limitX = ScaleMinMaxCurve(clampVel.limitX, scale);
                clampVel.limitY = ScaleMinMaxCurve(clampVel.limitY, scale);
                clampVel.limitZ = ScaleMinMaxCurve(clampVel.limitZ, scale);
            }
            if (options.force) {
                var force = particles.forceOverLifetime;
                force.x = ScaleMinMaxCurve(force.x, scale);
                force.y = ScaleMinMaxCurve(force.y, scale);
                force.z = ScaleMinMaxCurve(force.z, scale);
            }
        }