Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / manager / SpecialEffectManager.cs
@小李xl 小李xl on 13 Feb 2023 2 KB PutDown()参数改为枚举类型
  1.  
  2. using Godot;
  3.  
  4. /// <summary>
  5. /// 特效管理器
  6. /// </summary>
  7. public static partial class SpecialEffectManager
  8. {
  9.  
  10. /// <summary>
  11. /// 基础特效播放类, 用于播放序列帧动画特效, 播完就回收
  12. /// </summary>
  13. private partial class SpecialEffect : AnimatedSprite2D
  14. {
  15. //记录循环次数
  16. public int LoopCount;
  17.  
  18. private int currLoopCount = 0;
  19. public override void _Ready()
  20. {
  21. AnimationLooped += OnAnimationLooped;
  22. }
  23.  
  24. //动画结束
  25. private void OnAnimationLooped()
  26. {
  27. currLoopCount++;
  28. if (currLoopCount >= LoopCount)
  29. {
  30. Over();
  31. }
  32. }
  33.  
  34. private void Over()
  35. {
  36. currLoopCount = 0;
  37. QueueFree();
  38. }
  39. }
  40.  
  41. /// <summary>
  42. /// 在场景指定位置播放一个特效, 特效必须是 SpriteFrames 类型
  43. /// </summary>
  44. /// <param name="path">特效SpriteFrames资源路径</param>
  45. /// <param name="animName">动画名称</param>
  46. /// <param name="pos">坐标</param>
  47. /// <param name="rotation">旋转角度, 弧度制</param>
  48. /// <param name="scale">缩放</param>
  49. /// <param name="offset">图像偏移</param>
  50. /// <param name="zIndex">层级</param>
  51. /// <param name="speed">播放速度</param>
  52. /// <param name="loopCount">循环次数, 到达该次数特效停止播放</param>
  53. public static void Play(string path, string animName, Vector2 pos, float rotation, Vector2 scale, Vector2 offset, int zIndex = 0, float speed = 1, int loopCount = 1)
  54. {
  55. var spriteFrames = ResourceManager.Load<SpriteFrames>(path);
  56. var specialEffect = new SpecialEffect();
  57. specialEffect.GlobalPosition = pos;
  58. specialEffect.Rotation = rotation;
  59. specialEffect.Scale = scale;
  60. specialEffect.ZIndex = zIndex;
  61. specialEffect.Offset = offset;
  62. specialEffect.SpeedScale = speed;
  63. specialEffect.LoopCount = loopCount;
  64. specialEffect.SpriteFrames = spriteFrames;
  65. specialEffect.Play(animName);
  66. specialEffect.AddToActivityRoot(RoomLayerEnum.YSortLayer);
  67. }
  68. }