Newer
Older
DungeonShooting / DungeonShooting_Godot / src / framework / map / fog / PreviewFogMask.cs
@小李xl 小李xl on 24 Feb 2024 4 KB 微调门位置和迷雾
  1.  
  2. using System;
  3. using System.Collections;
  4. using Godot;
  5.  
  6. /// <summary>
  7. /// 绑定在门上的预览迷雾
  8. /// </summary>
  9. public partial class PreviewFogMask : FogMaskBase
  10. {
  11. public enum PreviewFogType
  12. {
  13. Aisle,
  14. Room
  15. }
  16.  
  17. private static bool _initTexture;
  18. private static Texture2D _previewAisle;
  19. private static Texture2D _previewAisle_ew;
  20. private static Texture2D _previewAisle_s;
  21. private static Texture2D _previewRoom;
  22. private static Texture2D _previewRoom_n;
  23. private static Texture2D _previewRoom_ew;
  24. /// <summary>
  25. /// 房间门
  26. /// </summary>
  27. public RoomDoorInfo DoorInfo;
  28. /// <summary>
  29. /// 迷雾类型
  30. /// </summary>
  31. public PreviewFogType FogType { get; private set; }
  32. // private float _previewAisleAngle;
  33. // private float _previewRoomAngle;
  34. // private Vector2 _previewAislePosition;
  35. // private Vector2 _previewRoomPosition;
  36. private long _cid;
  37. private static void InitTexture()
  38. {
  39. if (_initTexture)
  40. {
  41. return;
  42. }
  43.  
  44. _initTexture = true;
  45. _previewAisle = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_map_PreviewTransition_png);
  46. _previewRoom = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_map_PreviewTransition2_png);
  47. _previewRoom_n = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_map_PreviewTransition3_png);
  48. _previewRoom_ew = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_map_PreviewTransition4_png);
  49. _previewAisle_ew = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_map_PreviewTransition5_png);
  50. _previewAisle_s = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_map_PreviewTransition6_png);
  51. }
  52. /// <summary>
  53. /// 初始化迷雾
  54. /// </summary>
  55. public void Init(RoomDoorInfo doorInfo, PreviewFogType fogType)
  56. {
  57. InitTexture();
  58.  
  59. DoorInfo = doorInfo;
  60. FogType = fogType;
  61. var globalPosition = doorInfo.Door.GlobalPosition;
  62. if (doorInfo.Direction == DoorDirection.E)
  63. {
  64. if (fogType == PreviewFogType.Aisle)
  65. {
  66. Texture = _previewAisle_ew;
  67. Position = globalPosition + new Vector2(GameConfig.TileCellSize, -GameConfig.TileCellSize * 0.5f);
  68. RotationDegrees = 90;
  69. }
  70. else
  71. {
  72. Texture = _previewRoom_ew;
  73. Position = globalPosition + new Vector2(-GameConfig.TileCellSize, -GameConfig.TileCellSize * 0.5f);
  74. RotationDegrees = 270;
  75. }
  76. }
  77. else if (doorInfo.Direction == DoorDirection.W)
  78. {
  79. if (fogType == PreviewFogType.Aisle)
  80. {
  81. Texture = _previewAisle_ew;
  82. Position = globalPosition + new Vector2(-GameConfig.TileCellSize, -GameConfig.TileCellSize * 0.5f);
  83. RotationDegrees = 270;
  84. }
  85. else
  86. {
  87. Texture = _previewRoom_ew;
  88. Position = globalPosition + new Vector2(GameConfig.TileCellSize, -GameConfig.TileCellSize * 0.5f);
  89. RotationDegrees = 90;
  90. }
  91. }
  92. else if (doorInfo.Direction == DoorDirection.N)
  93. {
  94. if (fogType == PreviewFogType.Aisle)
  95. {
  96. Texture = _previewAisle;
  97. Position = globalPosition + new Vector2(0, -GameConfig.TileCellSize * 3);
  98. RotationDegrees = 0;
  99. }
  100. else
  101. {
  102. Texture = _previewRoom_n;
  103. Position = globalPosition;
  104. RotationDegrees = 180;
  105. }
  106. }
  107. else if (doorInfo.Direction == DoorDirection.S)
  108. {
  109. if (fogType == PreviewFogType.Aisle)
  110. {
  111. Texture = _previewAisle_s;
  112. Position = globalPosition + new Vector2(0, GameConfig.TileCellSize * 0.5f);
  113. RotationDegrees = 180;
  114. }
  115. else
  116. {
  117. Texture = _previewRoom;
  118. Position = globalPosition + new Vector2(0, -GameConfig.TileCellSize * 2);
  119. RotationDegrees = 0;
  120. }
  121. }
  122. }
  123. }