using UnityEngine; using System.Collections; public class ParticleControl : MonoBehaviour { private ParticleSystem particle; [SerializeField] private bool startLifetimeIsOn; [SerializeField] private bool startSizeIsOn; [SerializeField] private bool RateIsOn; [SerializeField] private bool shapIsOn; private void Start() { particle = GetComponent(); mo = particle.emission; shap = particle.shape; curve = new ParticleSystem.MinMaxCurve(mo.rate.constant); if (RateIsOn) InvokeRepeating("RateControl", RateLateTime, Time.deltaTime); if (startSizeIsOn) InvokeRepeating("startSizeControl", startSizeLateTime, Time.deltaTime); if (startLifetimeIsOn) InvokeRepeating("startLifetimeControl", startLifetimeLateTime, Time.deltaTime); if (shapIsOn) { if (shap.shapeType == ParticleSystemShapeType.Cone) InvokeRepeating("ConeShapControl", radiusLateTime, Time.deltaTime); if (shap.shapeType == ParticleSystemShapeType.Box) InvokeRepeating("BoxShapContron", BoxLateTime, Time.deltaTime); } } private void Update() { } [SerializeField] private float RateMax;//数量 [SerializeField] private float RateSpeed;//数量速度 [SerializeField] private float RateLateTime;//延迟时间 private ParticleSystem.EmissionModule mo; private ParticleSystem.MinMaxCurve curve; //发射数量 private void RateControl() { if (curve.constant < RateMax) { curve.constant += Time.deltaTime * RateSpeed; mo.rate = curve; } else CancelInvoke("RateControl"); } [SerializeField] private float startSizeMax;//大小 [SerializeField] private float startSizeSpeed;//速度 [SerializeField] private float startSizeLateTime;//延迟时间 //粒子大小 private void startSizeControl() { if (particle.startSize < startSizeMax) { particle.startSize += Time.deltaTime * startSizeSpeed; } else CancelInvoke("startSizeControl"); } [SerializeField] private float startLifetimeMax;//生命周期 [SerializeField] private float startLifetimeSpeed;//速度 [SerializeField] private float startLifetimeLateTime;//延迟时间 //生命周期 private void startLifetimeControl() { if (particle.startLifetime < startLifetimeMax) { particle.startLifetime += Time.deltaTime * startLifetimeSpeed; } else CancelInvoke("startLifetimeControl"); } [SerializeField] private float radiusMax;//最大半径 [SerializeField] private float radiusSpeed;//速度 [SerializeField] private float radiusLateTime;//延迟时间 private ParticleSystem.ShapeModule shap; //圆形发射器大小 private void ConeShapControl() { if (shap.radius < radiusMax) { shap.radius += Time.deltaTime * radiusSpeed; } else CancelInvoke("ConeShapControl"); } [SerializeField] private Vector3 BoxMax;//最大尺寸 [SerializeField] private Vector3 BoxSpeed;//速度 [SerializeField] private float BoxLateTime;//延迟时间 //方形发射器大小 private void BoxShapContron() { if (shap.box.x < BoxMax.x) shap.box = new Vector3(shap.box.x + Time.deltaTime * BoxSpeed.x, shap.box.y, shap.box.z); if (shap.box.y < BoxMax.y) shap.box = new Vector3(shap.box.x, shap.box.y + Time.deltaTime * BoxSpeed.y, shap.box.z); if (shap.box.z < BoxMax.z) shap.box = new Vector3(shap.box.x, shap.box.y, shap.box.z + Time.deltaTime * BoxSpeed.z); if (shap.box.x >= BoxMax.x && shap.box.y >= BoxMax.y && shap.box.z >= BoxMax.z) CancelInvoke("BoxShapContron"); } }