Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / effects / AutoDestroyParticles.cs
  1. using Godot;
  2. using Godot.Collections;
  3.  
  4. /// <summary>
  5. /// 到期自动销毁的粒子特效
  6. /// </summary>
  7. public partial class AutoDestroyParticles : GpuParticles2D, IEffect
  8. {
  9. /// <summary>
  10. /// 延时销毁时间
  11. /// </summary>
  12. [Export]
  13. public float DelayTime { get; set; } = 2f;
  14. /// <summary>
  15. /// 子节点包含的例子特效, 在创建完成后自动播放
  16. /// </summary>
  17. [Export]
  18. public Array<GpuParticles2D> Particles2D { get; set; }
  19. public bool IsDestroyed { get; private set; }
  20. public bool IsRecycled { get; set; }
  21. public string Logotype { get; set; }
  22.  
  23. private double _timer;
  24. private bool _isPlay;
  25. public virtual void PlayEffect()
  26. {
  27. ZIndex = 1;
  28. Emitting = true;
  29. Restart();
  30. if (Particles2D != null)
  31. {
  32. foreach (var gpuParticles2D in Particles2D)
  33. {
  34. gpuParticles2D.Emitting = true;
  35. Restart();
  36. }
  37. }
  38. _timer = 0;
  39. _isPlay = true;
  40. }
  41.  
  42. public override void _Process(double delta)
  43. {
  44. if (!_isPlay)
  45. {
  46. return;
  47. }
  48. _timer += delta;
  49. if (_timer >= DelayTime)
  50. {
  51. Emitting = false;
  52. if (Particles2D != null)
  53. {
  54. foreach (var gpuParticles2D in Particles2D)
  55. {
  56. gpuParticles2D.Emitting = false;
  57. }
  58. }
  59. _isPlay = false;
  60. ObjectPool.Reclaim(this);
  61. }
  62. }
  63.  
  64.  
  65. public void Destroy()
  66. {
  67. if (IsDestroyed)
  68. {
  69. return;
  70. }
  71.  
  72. IsDestroyed = true;
  73. QueueFree();
  74. }
  75.  
  76.  
  77. public void OnReclaim()
  78. {
  79. GetParent().RemoveChild(this);
  80. }
  81.  
  82. public void OnLeavePool()
  83. {
  84. }
  85. }