Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / activity / bullet / normal / SplitBullet.cs
  1.  
  2. using System;
  3. using Config;
  4. using Godot;
  5.  
  6. /// <summary>
  7. /// 分裂子弹
  8. /// </summary>
  9. [Tool]
  10. public partial class SplitBullet : Bullet
  11. {
  12. /// <summary>
  13. /// 创建子分裂子弹时的回调
  14. /// </summary>
  15. public event Action<IBullet> OnCreateSplitBulletEvent;
  16. private BulletData _bulletData;
  17. private int _count = 0;
  18.  
  19. /// <summary>
  20. /// 设置分裂的子弹
  21. /// </summary>
  22. /// <param name="data">子弹数据</param>
  23. /// <param name="count">子弹数量</param>
  24. public void SetSplitBullet(BulletData data, int count)
  25. {
  26. _bulletData = data;
  27. _count = count;
  28. }
  29.  
  30. public override void LogicalFinish()
  31. {
  32. base.LogicalFinish();
  33.  
  34. //创建分裂子弹
  35. if (_count > 0 && _bulletData != null)
  36. {
  37. var a = Mathf.Pi * 2 / _count;
  38. for (var i = 0; i < _count; i++)
  39. {
  40. var clone = _bulletData.Clone();
  41. clone.Rotation = a * i;
  42. clone.Position = Position + new Vector2(5, 0).Rotated(clone.Rotation);
  43. var shootBullet = FireManager.ShootBullet(clone, clone.TriggerRole.Camp);
  44. if (OnCreateSplitBulletEvent != null)
  45. {
  46. OnCreateSplitBulletEvent(shootBullet);
  47. }
  48. }
  49. }
  50. }
  51.  
  52. public override void OnLeavePool()
  53. {
  54. base.OnLeavePool();
  55. OnCreateSplitBulletEvent = null;
  56. _bulletData = null;
  57. _count = 0;
  58. }
  59. }