示例#1
0
        public void UpdateParticleSystem()
        {
            //Enables or Disbales Particle Systems you choose in inspector
            for (int i = 0; i < ParticleSystems.Count; i++)
            {
                if (ActiveParticleSystems.Count == ParticleSystems.Count)
                {
                    if (ActiveParticleSystems [i] == true)
                    {
                        ParticleSystems [i].SetActive(true);
                    }
                    else
                    {
                        ParticleSystems [i].SetActive(false);
                    }
                }
                else
                {
                    Debug.Log("Make sure the ActiveParticleSystems list has the same amount as the ParticleSystems list.");
                    return;
                }
            }

            if (ParticleSystems.Count > 0)
            {
                for (int i = 0; i < ParticleSystems.Count; i++)
                {
                    var ps = ParticleSystems [i].GetComponent <ParticleSystem> ();
                    if (ps != null)
                    {
                        var main                  = ps.main;
                        var shape                 = ps.shape;
                        var psLights              = ps.lights;
                        var psTrails              = ps.trails;
                        var colorOverLifetime     = ps.colorOverLifetime;
                        var colorOverLifetimeC    = colorOverLifetime.color;
                        var startColor            = main.startColor;
                        var startSize             = main.startSize;
                        var startSizeX            = main.startSizeX;
                        var startSizeY            = main.startSizeY;
                        var startSizeZ            = main.startSizeZ;
                        var startSpeed            = main.startSpeed;
                        var startDelay            = main.startDelay;
                        var startLifetime         = main.startLifetime;
                        var velocityOverLifetime  = ps.velocityOverLifetime;
                        var velocityOverLifetimeX = velocityOverLifetime.x;
                        var velocityOverLifetimeY = velocityOverLifetime.y;
                        var velocityOverLifetimeZ = velocityOverLifetime.z;
                        var localPos              = ParticleSystems [i].transform.localPosition;

                        //KEEP ORIGINAL VALUES
                        if (!SaveParticleSystemScript.CheckExistingFile(gameObject))
                        {
                            ParticleSystemOriginalSettings psOriginalSettings = new ParticleSystemOriginalSettings()
                            {
                                _startColor            = new SerializableMinMaxGradient(startColor),
                                _colorOverLifetimeC    = new SerializableMinMaxGradient(colorOverLifetimeC),
                                _startSize             = new SerializableMinMaxCurve(startSize),
                                _startSizeX            = new SerializableMinMaxCurve(startSizeX),
                                _startSizeY            = new SerializableMinMaxCurve(startSizeY),
                                _startSizeZ            = new SerializableMinMaxCurve(startSizeZ),
                                _startSpeed            = new SerializableMinMaxCurve(startSpeed),
                                _startDelay            = new SerializableMinMaxCurve(startDelay),
                                _startLifetime         = new SerializableMinMaxCurve(startLifetime),
                                _velocityOverLifetimeX = new SerializableMinMaxCurve(velocityOverLifetimeX),
                                _velocityOverLifetimeY = new SerializableMinMaxCurve(velocityOverLifetimeY),
                                _velocityOverLifetimeZ = new SerializableMinMaxCurve(velocityOverLifetimeZ),
                                _localPosition         = new SerializableVector3(ParticleSystems [i].transform.localPosition),
                                _duration    = main.duration,
                                _shapeRadius = shape.radius,
                                _active      = ps.gameObject.activeSelf,
                                _loop        = main.loop,
                                _prewarm     = main.prewarm
                            };
                            psOriginalSettingsList.Add(psOriginalSettings);
                        }
                        else
                        {
                            List <ParticleSystemOriginalSettings> listOriginalSettings = new List <ParticleSystemOriginalSettings> ();
                            listOriginalSettings = SaveParticleSystemScript.LoadVFX(gameObject);

                            startColor            = listOriginalSettings [i]._startColor.GetMinMaxGradient();
                            colorOverLifetimeC    = listOriginalSettings [i]._colorOverLifetimeC.GetMinMaxGradient();
                            startSize             = listOriginalSettings [i]._startSize.GetMinMaxCurve();
                            startSizeX            = listOriginalSettings [i]._startSizeX.GetMinMaxCurve();
                            startSizeY            = listOriginalSettings [i]._startSizeY.GetMinMaxCurve();
                            startSizeZ            = listOriginalSettings [i]._startSizeZ.GetMinMaxCurve();
                            startSpeed            = listOriginalSettings [i]._startSpeed.GetMinMaxCurve();
                            startDelay            = listOriginalSettings [i]._startDelay.GetMinMaxCurve();
                            startLifetime         = listOriginalSettings [i]._startLifetime.GetMinMaxCurve();
                            velocityOverLifetimeX = listOriginalSettings [i]._velocityOverLifetimeX.GetMinMaxCurve();
                            velocityOverLifetimeY = listOriginalSettings [i]._velocityOverLifetimeY.GetMinMaxCurve();
                            velocityOverLifetimeZ = listOriginalSettings [i]._velocityOverLifetimeZ.GetMinMaxCurve();
                            localPos      = listOriginalSettings [i]._localPosition.GetVector3();
                            main.duration = listOriginalSettings [i]._duration;
                            shape.radius  = listOriginalSettings [i]._shapeRadius;
                            ps.gameObject.SetActive(listOriginalSettings [i]._active);
                            loop    = listOriginalSettings [i]._loop;
                            prewarm = listOriginalSettings [i]._prewarm;
                        }

                        //LOOP
                        if (!main.loop)
                        {
                            main.loop = loop;
                        }

                        //PREWARM
                        main.prewarm = prewarm;

                        //LIGHTS
                        if (!lights && psLights.enabled)
                        {
                            psLights.enabled = false;
                        }

                        //TRAILS
                        if (!trails && psTrails.enabled)
                        {
                            psTrails.enabled = false;
                        }

                        //POSITION
                        if (i > 0)
                        {
                            if (localPos.x != 0 || localPos.y != 0 || localPos.z != 0)
                            {
                                localPos.x *= size;
                                localPos.y *= size;
                                localPos.z *= size;
                                ParticleSystems [i].transform.localPosition = localPos;
                            }
                        }

                        //DURATION
                        if (duration != 1)
                        {
                            main.duration *= duration;
                        }

                        //SIZE
                        if (main.startSize3D)
                        {
                            if (startSize.mode == ParticleSystemCurveMode.TwoConstants)
                            {
                                startSizeX.constantMax *= size;
                                startSizeX.constantMin *= size;

                                startSizeY.constantMax *= size;
                                startSizeY.constantMin *= size;

                                startSizeZ.constantMax *= size;
                                startSizeZ.constantMin *= size;
                            }
                            else
                            {
                                startSizeX.constant *= size;
                                startSizeY.constant *= size;
                                startSizeZ.constant *= size;
                            }
                            main.startSizeX = startSizeX;
                            main.startSizeY = startSizeY;
                            main.startSizeZ = startSizeZ;
                        }
                        else
                        {
                            if (startSize.mode == ParticleSystemCurveMode.TwoConstants)
                            {
                                startSize.constantMax *= size;
                                startSize.constantMin *= size;
                            }
                            else
                            {
                                startSize.constant *= size;
                            }
                            main.startSize = startSize;
                        }

                        //START_SPEED (affected by size)
                        if (startSpeed.mode == ParticleSystemCurveMode.TwoConstants)
                        {
                            startSpeed.constantMax *= size;
                            startSpeed.constantMin *= size;
                            main.startSpeed         = startSpeed;
                        }
                        else
                        {
                            startSpeed.constant *= size;
                            main.startSpeed      = startSpeed;
                        }

                        //START_SPEED (affected by speed)
                        if (startSpeed.mode == ParticleSystemCurveMode.TwoConstants)
                        {
                            startSpeed.constantMax *= speed;
                            startSpeed.constantMin *= speed;
                            main.startSpeed         = startSpeed;
                        }
                        else
                        {
                            startSpeed.constant *= speed;
                            main.startSpeed      = startSpeed;
                        }

                        //LIFETIME
                        if (main.startLifetime.mode == ParticleSystemCurveMode.TwoConstants)
                        {
                            startLifetime.constantMax *= 1 / speed;
                            startLifetime.constantMin *= 1 / speed;
                            main.startLifetime         = startLifetime;
                        }
                        else
                        {
                            startLifetime.constant *= 1 / speed;
                            main.startLifetime      = startLifetime;
                        }

                        //START_DELAY
                        if (startDelay.mode == ParticleSystemCurveMode.TwoConstants)
                        {
                            startDelay.constantMax *= 1 / speed;
                            startDelay.constantMin *= 1 / speed;
                            main.startDelay         = startDelay;
                        }
                        else
                        {
                            startDelay.constant *= 1 / speed;
                            main.startDelay      = startDelay;
                        }

                        //VELOCITY OVERLIFETIME
                        if (velocityOverLifetime.enabled)
                        {
                            float amount = 1;
                            if (size != 1)
                            {
                                amount = size;
                            }
                            if (speed != 1)
                            {
                                amount = speed;
                            }
                            if (size != 1 && speed != 1)
                            {
                                amount = (size + speed) / 2;
                            }

                            if (velocityOverLifetime.x.mode == ParticleSystemCurveMode.TwoConstants)
                            {
                                velocityOverLifetimeX.constantMax *= amount;
                                velocityOverLifetimeX.constantMin *= amount;

                                velocityOverLifetimeY.constantMax *= amount;
                                velocityOverLifetimeY.constantMin *= amount;

                                velocityOverLifetimeZ.constantMax *= amount;
                                velocityOverLifetimeZ.constantMin *= amount;
                            }
                            else
                            {
                                velocityOverLifetimeX.constant *= amount;
                                velocityOverLifetimeY.constant *= amount;
                                velocityOverLifetimeZ.constant *= amount;
                            }
                            velocityOverLifetime.x = velocityOverLifetimeX;
                            velocityOverLifetime.y = velocityOverLifetimeY;
                            velocityOverLifetime.z = velocityOverLifetimeZ;
                        }

                        //RADIUS
                        if (shape.enabled)
                        {
                            shape.radius *= size;
                        }

                        //COLOR
                        if (changeColor)
                        {
                            if (main.startColor.mode == ParticleSystemGradientMode.Color)
                            {
                                startColor.color = ChangeHUE(startColor.color, newMaxColor);
                                main.startColor  = startColor;
                            }
                            if (main.startColor.mode == ParticleSystemGradientMode.TwoColors)
                            {
                                startColor.colorMax = ChangeHUE(startColor.colorMax, newMaxColor);
                                startColor.colorMin = ChangeHUE(startColor.colorMin, newMinColor);
                                main.startColor     = startColor;
                            }
                            if (main.startColor.mode == ParticleSystemGradientMode.Gradient)
                            {
                                startColor.gradient = ChangeGradientColor(startColor.gradient, newMaxColor, newMinColor);
                                main.startColor     = startColor;
                            }
                            if (main.startColor.mode == ParticleSystemGradientMode.TwoGradients)
                            {
                                startColor.gradientMax = ChangeGradientColor(startColor.gradientMax, newMaxColor, newMinColor);
                                startColor.gradientMin = ChangeGradientColor(startColor.gradientMin, newMinColor, newMaxColor);
                                main.startColor        = startColor;
                            }

                            //COLOR OVERLIFETIME
                            if (colorOverLifetime.enabled)
                            {
                                if (colorOverLifetime.color.mode == ParticleSystemGradientMode.Gradient)
                                {
                                    colorOverLifetimeC.gradient = ChangeGradientColor(colorOverLifetimeC.gradient, newMaxColor, newMinColor);
                                }
                                if (colorOverLifetime.color.mode == ParticleSystemGradientMode.TwoGradients)
                                {
                                    colorOverLifetimeC.gradientMax = ChangeGradientColor(colorOverLifetimeC.gradientMax, newMaxColor, newMinColor);
                                    colorOverLifetimeC.gradientMin = ChangeGradientColor(colorOverLifetimeC.gradientMin, newMinColor, newMaxColor);
                                }
                                colorOverLifetime.color = colorOverLifetimeC;
                            }
                        }
                    }
                    else
                    {
                        //TRAIL RENDERER
                        var trail = ParticleSystems [i].GetComponent <TrailRenderer> ();
                        if (trail != null)
                        {
                            if (!SaveParticleSystemScript.CheckExistingFile(gameObject))
                            {
                                ParticleSystemOriginalSettings psOriginalSettings = new ParticleSystemOriginalSettings {
                                    _trailGradient        = new SerializableGradient(trail.colorGradient),
                                    _localPosition        = new SerializableVector3(trail.transform.localPosition),
                                    _trailWidthMultiplier = trail.widthMultiplier,
                                    _trailTime            = trail.time
                                };
                                psOriginalSettingsList.Add(psOriginalSettings);
                            }
                            else
                            {
                                List <ParticleSystemOriginalSettings> listOriginalSettings = new List <ParticleSystemOriginalSettings> ();
                                listOriginalSettings = SaveParticleSystemScript.LoadVFX(gameObject);

                                trail.colorGradient           = listOriginalSettings [i]._trailGradient.GetGradient();
                                trail.transform.localPosition = listOriginalSettings [i]._localPosition.GetVector3();
                                trail.widthMultiplier         = listOriginalSettings [i]._trailWidthMultiplier;
                                trail.time = listOriginalSettings [i]._trailTime;
                            }
                            trail.colorGradient    = ChangeGradientColor(trail.colorGradient, newMaxColor, newMinColor);
                            trail.widthMultiplier *= size;

                            float amount = 1;
                            if (size != 1)
                            {
                                amount = size;
                            }
                            if (speed != 1)
                            {
                                amount = speed;
                            }
                            if (size != 1 && speed != 1)
                            {
                                amount = (size + speed) / 2;
                            }
                            if (amount > 1)
                            {
                                trail.time *= 1 / amount;
                            }
                            else
                            {
                                trail.time *= amount;
                            }
                        }
                    }
                }
                if (!SaveParticleSystemScript.CheckExistingFile(gameObject))
                {
                    SaveParticleSystemScript.SaveVFX(gameObject, psOriginalSettingsList);
                }
            }
            else
            {
                Debug.Log("No Particle Systems added to the Particle Systems list");
            }
        }
示例#2
0
        public void ChangeColorOnly()
        {
            if (ParticleSystems.Count == 0)
            {
                FillLists();
            }

            if (ParticleSystems.Count > 0)
            {
                for (int i = 0; i < ParticleSystems.Count; i++)
                {
                    var ps = ParticleSystems [i].GetComponent <ParticleSystem> ();
                    if (ps != null)
                    {
                        var main = ps.main;
                        var colorOverLifetime  = ps.colorOverLifetime;
                        var colorOverLifetimeC = colorOverLifetime.color;
                        var startColor         = main.startColor;
                        //COLOR
                        if (changeColor)
                        {
                            if (main.startColor.mode == ParticleSystemGradientMode.Color)
                            {
                                startColor.color = ChangeHUE(startColor.color, newMaxColor);
                                main.startColor  = startColor;
                            }
                            if (main.startColor.mode == ParticleSystemGradientMode.TwoColors)
                            {
                                startColor.colorMax = ChangeHUE(startColor.colorMax, newMaxColor);
                                startColor.colorMin = ChangeHUE(startColor.colorMin, newMinColor);
                                main.startColor     = startColor;
                            }
                            if (main.startColor.mode == ParticleSystemGradientMode.Gradient)
                            {
                                startColor.gradient = ChangeGradientColor(startColor.gradient, newMaxColor, newMinColor);
                                main.startColor     = startColor;
                            }
                            if (main.startColor.mode == ParticleSystemGradientMode.TwoGradients)
                            {
                                startColor.gradientMax = ChangeGradientColor(startColor.gradientMax, newMaxColor, newMinColor);
                                startColor.gradientMin = ChangeGradientColor(startColor.gradientMin, newMinColor, newMaxColor);
                                main.startColor        = startColor;
                            }

                            //COLOR OVERLIFETIME
                            if (colorOverLifetime.enabled)
                            {
                                if (colorOverLifetime.color.mode == ParticleSystemGradientMode.Gradient)
                                {
                                    colorOverLifetimeC.gradient = ChangeGradientColor(colorOverLifetimeC.gradient, newMaxColor, newMinColor);
                                }
                                if (colorOverLifetime.color.mode == ParticleSystemGradientMode.TwoGradients)
                                {
                                    colorOverLifetimeC.gradientMax = ChangeGradientColor(colorOverLifetimeC.gradientMax, newMaxColor, newMinColor);
                                    colorOverLifetimeC.gradientMin = ChangeGradientColor(colorOverLifetimeC.gradientMin, newMinColor, newMaxColor);
                                }
                                colorOverLifetime.color = colorOverLifetimeC;
                            }
                        }
                    }
                    else
                    {
                        //TRAIL RENDERER
                        var trail = ParticleSystems [i].GetComponent <TrailRenderer> ();
                        if (trail != null)
                        {
                            if (!SaveParticleSystemScript.CheckExistingFile(gameObject))
                            {
                                ParticleSystemOriginalSettings psOriginalSettings = new ParticleSystemOriginalSettings {
                                    _trailGradient        = new SerializableGradient(trail.colorGradient),
                                    _localPosition        = new SerializableVector3(trail.transform.localPosition),
                                    _trailWidthMultiplier = trail.widthMultiplier,
                                    _trailTime            = trail.time
                                };
                                psOriginalSettingsList.Add(psOriginalSettings);
                            }
                            else
                            {
                                List <ParticleSystemOriginalSettings> listOriginalSettings = new List <ParticleSystemOriginalSettings> ();
                                listOriginalSettings = SaveParticleSystemScript.LoadVFX(gameObject);

                                trail.colorGradient           = listOriginalSettings [i]._trailGradient.GetGradient();
                                trail.transform.localPosition = listOriginalSettings [i]._localPosition.GetVector3();
                                trail.widthMultiplier         = listOriginalSettings [i]._trailWidthMultiplier;
                                trail.time = listOriginalSettings [i]._trailTime;
                            }
                            trail.colorGradient = ChangeGradientColor(trail.colorGradient, newMaxColor, newMinColor);
                        }
                    }
                }
            }
        }