Newer
Older
DungeonShooting / DungeonShooting_Godot / src / framework / map / fog / AisleFogArea.cs
@小李xl 小李xl on 11 Oct 2023 2 KB 日志系统
  1.  
  2. using Godot;
  3.  
  4. /// <summary>
  5. /// 过道迷雾区域碰撞器, 用于检测玩家是否进入过道
  6. /// </summary>
  7. public partial class AisleFogArea : Area2D, IDestroy
  8. {
  9. public bool IsDestroyed { get; private set; }
  10. /// <summary>
  11. /// 所属连接的门 (起始门)
  12. /// </summary>
  13. public RoomDoorInfo RoomDoorInfo { get; private set; }
  14. private bool _init = false;
  15. private RectangleShape2D _shape;
  16. /// <summary>
  17. /// 根据矩形区域初始化归属区域
  18. /// </summary>
  19. public void Init(RoomDoorInfo doorInfo, Rect2I rect2)
  20. {
  21. if (_init)
  22. {
  23. return;
  24. }
  25.  
  26. _init = true;
  27. RoomDoorInfo = doorInfo;
  28. var collisionShape = new CollisionShape2D();
  29. collisionShape.GlobalPosition = rect2.Position + rect2.Size / 2;
  30. var shape = new RectangleShape2D();
  31. _shape = shape;
  32. shape.Size = rect2.Size;
  33. collisionShape.Shape = shape;
  34. AddChild(collisionShape);
  35. _Init();
  36. }
  37. private void _Init()
  38. {
  39. Monitoring = true;
  40. Monitorable = false;
  41. CollisionLayer = PhysicsLayer.None;
  42. CollisionMask = PhysicsLayer.Player;
  43.  
  44. BodyEntered += OnBodyEntered;
  45. //BodyExited += OnBodyExited;
  46. }
  47. public void Destroy()
  48. {
  49. if (IsDestroyed)
  50. {
  51. return;
  52. }
  53.  
  54. IsDestroyed = true;
  55. QueueFree();
  56. }
  57. private void OnBodyEntered(Node2D body)
  58. {
  59. if (body == Player.Current)
  60. {
  61. //注意需要延时调用
  62. CallDeferred(nameof(InsertItem));
  63. }
  64. }
  65. // private void OnBodyExited(Node2D body)
  66. // {
  67. // if (body == Player.Current)
  68. // {
  69. // //注意需要延时调用
  70. // CallDeferred(nameof(LeavePlayer));
  71. // }
  72. // }
  73.  
  74. private void InsertItem()
  75. {
  76. //Debug.Log("玩家进入过道");
  77. //RoomDoorInfo.ClearFog();
  78. FogMaskHandler.RefreshAisleFog(RoomDoorInfo);
  79. }
  80.  
  81. // private void LeavePlayer()
  82. // {
  83. // //Debug.Log("玩家离开过道");
  84. // //RoomDoorInfo.DarkFog();
  85. // }
  86. }