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