using UnityEngine; using System.Collections; public class OilParticleControl : 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;//延迟时间 public ParticleSystem.ShapeModule shap; public float NowShape; //圆形发射器大小 private void ConeShapControl() { if (shap.radius < radiusMax) { shap.radius += Time.deltaTime * radiusSpeed; NowShape = shap.radius; } else CancelInvoke("ConeShapControl"); } [SerializeField] private Vector3 BoxMax;//最大尺寸 [SerializeField] private Vector3 BoxSpeed;//速度 [SerializeField] private float BoxLateTime;//延迟时间 //方形发射器大小 private void BoxShapContron() { if (shap.scale.x < BoxMax.x) shap.scale = new Vector3(shap.scale.x + Time.deltaTime * BoxSpeed.x, shap.scale.y, shap.scale.z); if (shap.scale.y < BoxMax.y) shap.scale = new Vector3(shap.scale.x, shap.scale.y + Time.deltaTime * BoxSpeed.y, shap.scale.z); if (shap.scale.z < BoxMax.z) shap.scale = new Vector3(shap.scale.x, shap.scale.y, shap.scale.z + Time.deltaTime * BoxSpeed.z); if (shap.scale.x >= BoxMax.x && shap.scale.y >= BoxMax.y && shap.scale.z >= BoxMax.z) CancelInvoke("BoxShapContron"); } }