FxController.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using QFSW.MOP2;
  5. namespace KairoEngine.Core
  6. {
  7. public class FxController : MonoBehaviour
  8. {
  9. public bool autoRemoveFx = true;
  10. public string fxName = "";
  11. public float removeTime = 3f;
  12. void Awake()
  13. {
  14. // Get all particle systems
  15. List<ParticleSystem> particleSystems = new List<ParticleSystem>();
  16. gameObject.GetComponentsInChildren<ParticleSystem>(particleSystems);
  17. var s = gameObject.GetComponent<ParticleSystem>();
  18. if(s != null) particleSystems.Add(s);
  19. // Reset Parcile Systems
  20. foreach (var particleSystem in particleSystems)
  21. {
  22. particleSystem.Clear();
  23. particleSystem.Play();
  24. }
  25. if(autoRemoveFx)
  26. {
  27. StartCoroutine(Timer.Start(removeTime, false, () =>
  28. {
  29. MasterObjectPooler.Instance.GetPool(fxName).Release(this.gameObject);
  30. }));
  31. }
  32. }
  33. }
  34. }