Newer
Older
DungeonShooting / DungeonShooting_Godot / src / framework / map / fog / PreviewFogMask.cs
  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 _previewRoom;
  21. private static Texture2D _previewRoom_n;
  22. private static Texture2D _previewRoom_ew;
  23. /// <summary>
  24. /// 房间门
  25. /// </summary>
  26. public RoomDoorInfo DoorInfo;
  27. /// <summary>
  28. /// 迷雾类型
  29. /// </summary>
  30. public PreviewFogType FogType { get; private set; }
  31. // private float _previewAisleAngle;
  32. // private float _previewRoomAngle;
  33. // private Vector2 _previewAislePosition;
  34. // private Vector2 _previewRoomPosition;
  35. private long _cid;
  36. private static void InitTexture()
  37. {
  38. if (_initTexture)
  39. {
  40. return;
  41. }
  42.  
  43. _initTexture = true;
  44. _previewAisle = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_map_PreviewTransition_png);
  45. _previewRoom = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_map_PreviewTransition2_png);
  46. _previewRoom_n = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_map_PreviewTransition3_png);
  47. _previewRoom_ew = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_map_PreviewTransition4_png);
  48. _previewAisle_ew = ResourceManager.LoadTexture2D(ResourcePath.resource_sprite_map_PreviewTransition5_png);
  49. }
  50. /// <summary>
  51. /// 初始化迷雾
  52. /// </summary>
  53. public void Init(RoomDoorInfo doorInfo, PreviewFogType fogType)
  54. {
  55. InitTexture();
  56.  
  57. DoorInfo = doorInfo;
  58. FogType = fogType;
  59. var globalPosition = doorInfo.Door.GlobalPosition;
  60. if (doorInfo.Direction == DoorDirection.E)
  61. {
  62. if (fogType == PreviewFogType.Aisle)
  63. {
  64. Texture = _previewAisle_ew;
  65. Position = globalPosition + new Vector2(GameConfig.TileCellSize, -GameConfig.TileCellSize * 0.5f);
  66. RotationDegrees = 90;
  67. }
  68. else
  69. {
  70. Texture = _previewRoom_ew;
  71. Position = globalPosition + new Vector2(-GameConfig.TileCellSize, -GameConfig.TileCellSize * 0.5f);
  72. RotationDegrees = 270;
  73. }
  74. }
  75. else if (doorInfo.Direction == DoorDirection.W)
  76. {
  77. if (fogType == PreviewFogType.Aisle)
  78. {
  79. Texture = _previewAisle_ew;
  80. Position = globalPosition + new Vector2(-GameConfig.TileCellSize, -GameConfig.TileCellSize * 0.5f);
  81. RotationDegrees = 270;
  82. }
  83. else
  84. {
  85. Texture = _previewRoom_ew;
  86. Position = globalPosition + new Vector2(GameConfig.TileCellSize, -GameConfig.TileCellSize * 0.5f);
  87. RotationDegrees = 90;
  88. }
  89. }
  90. else if (doorInfo.Direction == DoorDirection.N)
  91. {
  92. if (fogType == PreviewFogType.Aisle)
  93. {
  94. Texture = _previewAisle;
  95. Position = globalPosition + new Vector2(0, -GameConfig.TileCellSize * 2);
  96. RotationDegrees = 0;
  97. }
  98. else
  99. {
  100. Texture = _previewRoom_n;
  101. Position = globalPosition + new Vector2(0, GameConfig.TileCellSize * 0.5f);
  102. RotationDegrees = 180;
  103. }
  104. }
  105. else if (doorInfo.Direction == DoorDirection.S)
  106. {
  107. if (fogType == PreviewFogType.Aisle)
  108. {
  109. Texture = _previewAisle;
  110. Position = globalPosition;
  111. RotationDegrees = 180;
  112. }
  113. else
  114. {
  115. Texture = _previewRoom;
  116. Position = globalPosition + new Vector2(0, -GameConfig.TileCellSize * 2);
  117. RotationDegrees = 0;
  118. }
  119. }
  120. }
  121. }