diff --git a/DungeonShooting_Godot/addons/dungeonShooting_plugin/Automation.cs b/DungeonShooting_Godot/addons/dungeonShooting_plugin/Automation.cs index d33af7d..e8b7e51 100644 --- a/DungeonShooting_Godot/addons/dungeonShooting_plugin/Automation.cs +++ b/DungeonShooting_Godot/addons/dungeonShooting_plugin/Automation.cs @@ -120,7 +120,12 @@ { var dungeonRoomTemplate = packedScene.Instantiate(); var usedRect = dungeonRoomTemplate.GetUsedRect(); - DungeonRoomTemplate.SaveConfig(new List(), usedRect.Position, usedRect.Size, item); + var dungeonTile = new DungeonTile(dungeonRoomTemplate); + dungeonTile.SetFloorAtlasCoords(new List() { new Vector2I(0, 8) }); + //计算导航网格 + dungeonTile.GenerateNavigationPolygon(0); + var polygonData = dungeonTile.GetPolygonData(); + DungeonRoomTemplate.SaveConfig(new List(), usedRect.Position, usedRect.Size, polygonData.ToList(), item); dungeonRoomTemplate.QueueFree(); } } diff --git a/DungeonShooting_Godot/resource/map/RoomConfig.json b/DungeonShooting_Godot/resource/map/RoomConfig.json index a65a026..35e52d5 100644 --- a/DungeonShooting_Godot/resource/map/RoomConfig.json +++ b/DungeonShooting_Godot/resource/map/RoomConfig.json @@ -12,7 +12,50 @@ "Y": 13 }, "DoorAreaInfos": [], - "NavigationList": [] + "NavigationList": [ + { + "Type": 0, + "Points": [ + { + "X": 8, + "Y": 8 + }, + { + "X": 280, + "Y": 8 + }, + { + "X": 280, + "Y": 168 + }, + { + "X": 8, + "Y": 168 + } + ] + }, + { + "Type": 1, + "Points": [ + { + "X": 40, + "Y": 40 + }, + { + "X": 248, + "Y": 40 + }, + { + "X": 248, + "Y": 136 + }, + { + "X": 40, + "Y": 136 + } + ] + } + ] } }, { @@ -28,7 +71,61 @@ "Y": 12 }, "DoorAreaInfos": [], - "NavigationList": [] + "NavigationList": [ + { + "Type": 0, + "Points": [ + { + "X": 8, + "Y": 8 + }, + { + "X": 40, + "Y": 8 + }, + { + "X": 40, + "Y": 120 + }, + { + "X": 120, + "Y": 120 + }, + { + "X": 120, + "Y": 8 + }, + { + "X": 264, + "Y": 8 + }, + { + "X": 264, + "Y": 152 + }, + { + "X": 232, + "Y": 152 + }, + { + "X": 232, + "Y": 24 + }, + { + "X": 152, + "Y": 24 + }, + { + "X": 152, + "Y": 152 + }, + { + "X": 8, + "Y": 152 + } + ] + } + ] } }, { @@ -44,7 +141,113 @@ "Y": 21 }, "DoorAreaInfos": [], - "NavigationList": [] + "NavigationList": [ + { + "Type": 0, + "Points": [ + { + "X": 8, + "Y": 8 + }, + { + "X": 296, + "Y": 8 + }, + { + "X": 296, + "Y": 296 + }, + { + "X": 8, + "Y": 296 + } + ] + }, + { + "Type": 1, + "Points": [ + { + "X": 40, + "Y": 40 + }, + { + "X": 136, + "Y": 40 + }, + { + "X": 136, + "Y": 136 + }, + { + "X": 40, + "Y": 136 + } + ] + }, + { + "Type": 1, + "Points": [ + { + "X": 168, + "Y": 40 + }, + { + "X": 264, + "Y": 40 + }, + { + "X": 264, + "Y": 136 + }, + { + "X": 168, + "Y": 136 + } + ] + }, + { + "Type": 1, + "Points": [ + { + "X": 40, + "Y": 168 + }, + { + "X": 136, + "Y": 168 + }, + { + "X": 136, + "Y": 264 + }, + { + "X": 40, + "Y": 264 + } + ] + }, + { + "Type": 1, + "Points": [ + { + "X": 168, + "Y": 168 + }, + { + "X": 264, + "Y": 168 + }, + { + "X": 264, + "Y": 264 + }, + { + "X": 168, + "Y": 264 + } + ] + } + ] } } ] \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tileMaps/Room2.tscn b/DungeonShooting_Godot/resource/map/tileMaps/Room2.tscn index 841ed7d..a9ce8aa 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/Room2.tscn +++ b/DungeonShooting_Godot/resource/map/tileMaps/Room2.tscn @@ -6,5 +6,5 @@ [node name="Room2" type="TileMap"] tile_set = ExtResource("1_u22xh") format = 2 -layer_0/tile_data = PackedInt32Array(589840, 0, 8, 524304, 0, 8, 458768, 0, 8, 393232, 0, 8, 327696, 0, 8, 262160, 0, 8, 196624, 0, 8, 131088, 0, 8, 65552, 0, 8, 16, 0, 8, 589839, 0, 8, 524303, 0, 8, 458767, 0, 8, 393231, 0, 8, 327695, 0, 8, 262159, 0, 8, 196623, 0, 8, 131087, 0, 8, 65551, 0, 8, 15, 0, 8, 589838, 0, 8, 524302, 0, 8, 458766, 0, 8, 393230, 0, 8, 327694, 0, 8, 262158, 0, 8, 196622, 0, 8, 131086, 0, 8, 65550, 0, 8, 14, 0, 8, 65549, 0, 8, 13, 0, 8, 65548, 0, 8, 12, 0, 8, 65547, 0, 8, 11, 0, 8, 65546, 0, 8, 10, 0, 8, 589833, 0, 8, 524297, 0, 8, 458761, 0, 8, 393225, 0, 8, 327689, 0, 8, 262153, 0, 8, 196617, 0, 8, 131081, 0, 8, 65545, 0, 8, 9, 0, 8, 589832, 0, 8, 524296, 0, 8, 458760, 0, 8, 393224, 0, 8, 327688, 0, 8, 262152, 0, 8, 196616, 0, 8, 131080, 0, 8, 65544, 0, 8, 8, 0, 8, 589831, 0, 8, 524295, 0, 8, 458759, 0, 8, 393223, 0, 8, 327687, 0, 8, 262151, 0, 8, 196615, 0, 8, 131079, 0, 8, 65543, 0, 8, 7, 0, 8, 589830, 0, 8, 524294, 0, 8, 458758, 0, 8, 589829, 0, 8, 524293, 0, 8, 458757, 0, 8, 589828, 0, 8, 524292, 0, 8, 458756, 0, 8, 589827, 0, 8, 524291, 0, 8, 458755, 0, 8, 589826, 0, 8, 524290, 0, 8, 458754, 0, 8, 393218, 0, 8, 327682, 0, 8, 262146, 0, 8, 196610, 0, 8, 131074, 0, 8, 65538, 0, 8, 2, 0, 8, 589825, 0, 8, 524289, 0, 8, 458753, 0, 8, 393217, 0, 8, 327681, 0, 8, 262145, 0, 8, 196609, 0, 8, 131073, 0, 8, 65537, 0, 8, 1, 0, 8, 589824, 0, 8, 524288, 0, 8, 458752, 0, 8, 393216, 0, 8, 327680, 0, 8, 262144, 0, 8, 196608, 0, 8, 131072, 0, 8, 65536, 0, 8, 0, 0, 8, 131071, 196608, 3, 65535, 196608, 3, -1, 196608, 4, -65536, 131072, 7, -65535, 131072, 7, 196607, 196608, 3, 262143, 196608, 3, 327679, 196608, 3, 393215, 196608, 3, 458751, 196608, 3, 524287, 196608, 3, 589823, 196608, 3, 655359, 196608, 3, 655361, 131072, 2, 655360, 131072, 2, 720895, 720896, 2, -65534, 131072, 7, 655362, 131072, 2, 655363, 131072, 2, 655364, 131072, 2, 655365, 131072, 2, 655366, 131072, 2, -65529, 131072, 7, 655367, 131072, 2, -65528, 131072, 7, 655368, 131072, 2, -65527, 131072, 7, 655369, 131072, 2, -65526, 131072, 7, -65525, 131072, 7, -65524, 131072, 7, -65523, 131072, 7, -65522, 131072, 7, 655374, 131072, 2, -65521, 131072, 7, 655375, 131072, 2, -65520, 131072, 7, 655376, 131072, 2, 3, 65536, 3, 65539, 65536, 3, -65533, 65536, 4, 131075, 65536, 3, 196611, 65536, 3, 262147, 65536, 3, 327683, 65536, 3, 393219, 65536, 7, 393220, 131072, 7, 393221, 131072, 7, 393222, 196608, 7, 327686, 196608, 3, 262150, 196608, 3, 196614, 196608, 3, 131078, 196608, 3, 65542, 196608, 3, 6, 196608, 3, -65530, 196608, 4, 17, 65536, 3, 65553, 65536, 3, -65519, 65536, 4, 131089, 65536, 3, 196625, 65536, 3, 262161, 65536, 3, 327697, 65536, 3, 393233, 65536, 3, 458769, 65536, 3, 524305, 65536, 3, 589841, 65536, 3, 655377, 851968, 2, 655373, 720896, 2, 589837, 196608, 3, 524301, 196608, 3, 458765, 196608, 3, 393229, 196608, 3, 327693, 196608, 3, 262157, 196608, 3, 196621, 196608, 3, 131085, 196608, 2, 131084, 131072, 2, 131083, 131072, 2, 131082, 65536, 2, 196618, 65536, 3, 262154, 65536, 3, 327690, 65536, 3, 393226, 65536, 3, 458762, 65536, 3, 524298, 65536, 3, 589834, 65536, 3, 655370, 851968, 2) +layer_0/tile_data = PackedInt32Array(589840, 0, 8, 524304, 0, 8, 458768, 0, 8, 393232, 0, 8, 327696, 0, 8, 262160, 0, 8, 196624, 0, 8, 131088, 0, 8, 65552, 0, 8, 16, 0, 8, 589839, 0, 8, 524303, 0, 8, 458767, 0, 8, 393231, 0, 8, 327695, 0, 8, 262159, 0, 8, 196623, 0, 8, 131087, 0, 8, 65551, 0, 8, 15, 0, 8, 589838, 0, 8, 524302, 0, 8, 458766, 0, 8, 393230, 0, 8, 327694, 0, 8, 262158, 0, 8, 196622, 0, 8, 131086, 0, 8, 65550, 0, 8, 14, 0, 8, 65549, 0, 8, 13, 0, 8, 65548, 0, 8, 12, 0, 8, 65547, 0, 8, 11, 0, 8, 65546, 0, 8, 10, 0, 8, 589833, 0, 8, 524297, 0, 8, 458761, 0, 8, 393225, 0, 8, 327689, 0, 8, 262153, 0, 8, 196617, 0, 8, 131081, 0, 8, 65545, 0, 8, 9, 0, 8, 589832, 0, 8, 524296, 0, 8, 458760, 0, 8, 393224, 0, 8, 327688, 0, 8, 262152, 0, 8, 196616, 0, 8, 131080, 0, 8, 65544, 0, 8, 8, 0, 8, 589831, 0, 8, 524295, 0, 8, 458759, 0, 8, 393223, 0, 8, 327687, 0, 8, 262151, 0, 8, 196615, 0, 8, 131079, 0, 8, 65543, 0, 8, 7, 0, 8, 589830, 0, 8, 524294, 0, 8, 458758, 0, 8, 589829, 0, 8, 524293, 0, 8, 458757, 0, 8, 589828, 0, 8, 524292, 0, 8, 458756, 0, 8, 589827, 0, 8, 524291, 0, 8, 458755, 0, 8, 589826, 0, 8, 524290, 0, 8, 458754, 0, 8, 393218, 0, 8, 327682, 0, 8, 262146, 0, 8, 196610, 0, 8, 131074, 0, 8, 65538, 0, 8, 2, 0, 8, 589825, 0, 8, 524289, 0, 8, 458753, 0, 8, 393217, 0, 8, 327681, 0, 8, 262145, 0, 8, 196609, 0, 8, 131073, 0, 8, 65537, 0, 8, 1, 0, 8, 589824, 0, 8, 524288, 0, 8, 458752, 0, 8, 393216, 0, 8, 327680, 0, 8, 262144, 0, 8, 196608, 0, 8, 131072, 0, 8, 65536, 0, 8, 0, 0, 8, 131071, 196608, 3, 65535, 196608, 3, -1, 196608, 4, -65536, 131072, 7, -65535, 131072, 7, 196607, 196608, 3, 262143, 196608, 3, 327679, 196608, 3, 393215, 196608, 3, 458751, 196608, 3, 524287, 196608, 3, 589823, 196608, 3, 655359, 196608, 3, 655361, 131072, 2, 655360, 131072, 2, 720895, 720896, 2, -65534, 131072, 7, 655362, 131072, 2, 655363, 131072, 2, 655364, 131072, 2, 655365, 131072, 2, 655366, 131072, 2, -65529, 131072, 7, 655367, 131072, 2, -65528, 131072, 7, 655368, 131072, 2, -65527, 131072, 7, 655369, 131072, 2, -65526, 131072, 7, -65525, 131072, 7, -65524, 131072, 7, -65523, 131072, 7, -65522, 131072, 7, 655374, 131072, 2, -65521, 131072, 7, 655375, 131072, 2, -65520, 131072, 7, 655376, 131072, 2, 3, 65536, 3, 65539, 65536, 3, -65533, 65536, 4, 131075, 65536, 3, 196611, 65536, 3, 262147, 65536, 3, 327683, 65536, 3, 393219, 65536, 7, 393220, 131072, 7, 393221, 131072, 7, 393222, 196608, 7, 327686, 196608, 3, 262150, 196608, 3, 196614, 196608, 3, 131078, 196608, 3, 65542, 196608, 3, 6, 196608, 3, -65530, 196608, 4, 17, 65536, 3, 65553, 65536, 3, -65519, 65536, 4, 131089, 65536, 3, 196625, 65536, 3, 262161, 65536, 3, 327697, 65536, 3, 393233, 65536, 3, 458769, 65536, 3, 655377, 851968, 2, 655373, 720896, 2, 589837, 196608, 3, 524301, 196608, 3, 458765, 196608, 3, 393229, 196608, 3, 327693, 196608, 3, 262157, 196608, 3, 196621, 196608, 3, 131085, 196608, 2, 131084, 131072, 2, 131083, 131072, 2, 131082, 65536, 2, 196618, 65536, 3, 262154, 65536, 3, 327690, 65536, 3, 393226, 65536, 3, 458762, 65536, 3, 524298, 65536, 3, 589834, 65536, 3, 655370, 851968, 2, 524305, 65536, 3, 589841, 65536, 3) script = ExtResource("1_hg3w8") diff --git a/DungeonShooting_Godot/resource/map/tiledata/Room1.json b/DungeonShooting_Godot/resource/map/tiledata/Room1.json index 9de281a..f64b47a 100644 --- a/DungeonShooting_Godot/resource/map/tiledata/Room1.json +++ b/DungeonShooting_Godot/resource/map/tiledata/Room1.json @@ -8,5 +8,48 @@ "Y": 13 }, "DoorAreaInfos": [], - "NavigationList": [] + "NavigationList": [ + { + "Type": 0, + "Points": [ + { + "X": 8, + "Y": 8 + }, + { + "X": 280, + "Y": 8 + }, + { + "X": 280, + "Y": 168 + }, + { + "X": 8, + "Y": 168 + } + ] + }, + { + "Type": 1, + "Points": [ + { + "X": 40, + "Y": 40 + }, + { + "X": 248, + "Y": 40 + }, + { + "X": 248, + "Y": 136 + }, + { + "X": 40, + "Y": 136 + } + ] + } + ] } \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tiledata/Room2.json b/DungeonShooting_Godot/resource/map/tiledata/Room2.json index 1af8a70..5efa182 100644 --- a/DungeonShooting_Godot/resource/map/tiledata/Room2.json +++ b/DungeonShooting_Godot/resource/map/tiledata/Room2.json @@ -8,5 +8,59 @@ "Y": 12 }, "DoorAreaInfos": [], - "NavigationList": [] + "NavigationList": [ + { + "Type": 0, + "Points": [ + { + "X": 8, + "Y": 8 + }, + { + "X": 40, + "Y": 8 + }, + { + "X": 40, + "Y": 120 + }, + { + "X": 120, + "Y": 120 + }, + { + "X": 120, + "Y": 8 + }, + { + "X": 264, + "Y": 8 + }, + { + "X": 264, + "Y": 152 + }, + { + "X": 232, + "Y": 152 + }, + { + "X": 232, + "Y": 24 + }, + { + "X": 152, + "Y": 24 + }, + { + "X": 152, + "Y": 152 + }, + { + "X": 8, + "Y": 152 + } + ] + } + ] } \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/map/tiledata/Room3.json b/DungeonShooting_Godot/resource/map/tiledata/Room3.json index cc1b1bd..1be08dd 100644 --- a/DungeonShooting_Godot/resource/map/tiledata/Room3.json +++ b/DungeonShooting_Godot/resource/map/tiledata/Room3.json @@ -8,5 +8,111 @@ "Y": 21 }, "DoorAreaInfos": [], - "NavigationList": [] + "NavigationList": [ + { + "Type": 0, + "Points": [ + { + "X": 8, + "Y": 8 + }, + { + "X": 296, + "Y": 8 + }, + { + "X": 296, + "Y": 296 + }, + { + "X": 8, + "Y": 296 + } + ] + }, + { + "Type": 1, + "Points": [ + { + "X": 40, + "Y": 40 + }, + { + "X": 136, + "Y": 40 + }, + { + "X": 136, + "Y": 136 + }, + { + "X": 40, + "Y": 136 + } + ] + }, + { + "Type": 1, + "Points": [ + { + "X": 168, + "Y": 40 + }, + { + "X": 264, + "Y": 40 + }, + { + "X": 264, + "Y": 136 + }, + { + "X": 168, + "Y": 136 + } + ] + }, + { + "Type": 1, + "Points": [ + { + "X": 40, + "Y": 168 + }, + { + "X": 136, + "Y": 168 + }, + { + "X": 136, + "Y": 264 + }, + { + "X": 40, + "Y": 264 + } + ] + }, + { + "Type": 1, + "Points": [ + { + "X": 168, + "Y": 168 + }, + { + "X": 264, + "Y": 168 + }, + { + "X": 264, + "Y": 264 + }, + { + "X": 168, + "Y": 264 + } + ] + } + ] } \ No newline at end of file diff --git a/DungeonShooting_Godot/resource/theme/mainTheme.tres b/DungeonShooting_Godot/resource/theme/mainTheme.tres index d973ebf..419b387 100644 --- a/DungeonShooting_Godot/resource/theme/mainTheme.tres +++ b/DungeonShooting_Godot/resource/theme/mainTheme.tres @@ -352,7 +352,7 @@ [sub_resource type="ImageTexture" id="58"] -[sub_resource type="Image" id="Image_3e4qi"] +[sub_resource type="Image" id="Image_al0gg"] data = { "data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 1, 255, 255, 255, 39, 255, 255, 255, 67, 255, 255, 255, 67, 255, 255, 255, 39, 255, 255, 255, 1, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 39, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 39, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 66, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 66, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 66, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 66, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 39, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 75, 255, 255, 255, 39, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 1, 255, 255, 255, 39, 255, 255, 255, 67, 255, 255, 255, 67, 255, 255, 255, 39, 255, 255, 255, 1, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -362,7 +362,7 @@ } [sub_resource type="ImageTexture" id="60"] -image = SubResource("Image_3e4qi") +image = SubResource("Image_al0gg") [sub_resource type="StyleBoxTexture" id="61"] content_margin_left = 2.0 @@ -372,7 +372,7 @@ texture = SubResource("60") region_rect = Rect2(0, 0, 12, 12) -[sub_resource type="Image" id="Image_yra6h"] +[sub_resource type="Image" id="Image_rjd4c"] data = { "data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 191, 191, 0, 247, 247, 247, 0, 248, 248, 248, 0, 248, 248, 248, 0, 247, 247, 247, 0, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 191, 191, 0, 191, 191, 191, 4, 247, 247, 247, 98, 248, 248, 248, 167, 248, 248, 248, 167, 247, 247, 247, 98, 191, 191, 191, 4, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 247, 247, 247, 0, 247, 247, 247, 97, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 247, 247, 247, 97, 247, 247, 247, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 248, 248, 0, 248, 248, 248, 164, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 164, 248, 248, 248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 248, 248, 0, 248, 248, 248, 164, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 164, 248, 248, 248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 247, 247, 247, 0, 247, 247, 247, 97, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 248, 248, 248, 186, 247, 247, 247, 97, 247, 247, 247, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 191, 191, 0, 191, 191, 191, 4, 247, 247, 247, 98, 248, 248, 248, 167, 248, 248, 248, 167, 247, 247, 247, 98, 191, 191, 191, 4, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 191, 191, 0, 247, 247, 247, 0, 248, 248, 248, 0, 248, 248, 248, 0, 247, 247, 247, 0, 191, 191, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -382,7 +382,7 @@ } [sub_resource type="ImageTexture" id="63"] -image = SubResource("Image_yra6h") +image = SubResource("Image_rjd4c") [sub_resource type="StyleBoxTexture" id="64"] content_margin_left = 2.0 @@ -392,7 +392,7 @@ texture = SubResource("63") region_rect = Rect2(0, 0, 12, 12) -[sub_resource type="Image" id="Image_ea71e"] +[sub_resource type="Image" id="Image_e5wah"] data = { "data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 0, 173, 173, 173, 0, 173, 173, 173, 0, 173, 173, 173, 0, 173, 173, 173, 0, 127, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 0, 127, 127, 127, 4, 173, 173, 173, 97, 173, 173, 173, 166, 173, 173, 173, 166, 173, 173, 173, 97, 127, 127, 127, 4, 127, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 172, 172, 172, 0, 172, 172, 172, 96, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 172, 172, 172, 96, 172, 172, 172, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 173, 173, 173, 0, 173, 173, 173, 163, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 163, 173, 173, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 173, 173, 173, 0, 173, 173, 173, 163, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 163, 173, 173, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 172, 172, 172, 0, 172, 172, 172, 96, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 173, 173, 173, 185, 172, 172, 172, 96, 172, 172, 172, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 0, 127, 127, 127, 4, 173, 173, 173, 97, 173, 173, 173, 166, 173, 173, 173, 166, 173, 173, 173, 97, 127, 127, 127, 4, 127, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 127, 127, 0, 173, 173, 173, 0, 173, 173, 173, 0, 173, 173, 173, 0, 173, 173, 173, 0, 127, 127, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -402,7 +402,7 @@ } [sub_resource type="ImageTexture" id="66"] -image = SubResource("Image_ea71e") +image = SubResource("Image_e5wah") [sub_resource type="StyleBoxTexture" id="67"] content_margin_left = 2.0 @@ -412,7 +412,7 @@ texture = SubResource("66") region_rect = Rect2(0, 0, 12, 12) -[sub_resource type="Image" id="Image_5txkb"] +[sub_resource type="Image" id="Image_iikp8"] data = { "data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 4, 255, 255, 255, 16, 255, 255, 255, 16, 255, 255, 255, 4, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 16, 255, 255, 255, 21, 255, 255, 255, 21, 255, 255, 255, 16, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 16, 255, 255, 255, 21, 255, 255, 255, 21, 255, 255, 255, 16, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 4, 255, 255, 255, 16, 255, 255, 255, 16, 255, 255, 255, 4, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -422,7 +422,7 @@ } [sub_resource type="ImageTexture" id="69"] -image = SubResource("Image_5txkb") +image = SubResource("Image_iikp8") [sub_resource type="StyleBoxTexture" id="70"] content_margin_left = 0.0 @@ -446,7 +446,7 @@ content_margin_right = 4.0 content_margin_bottom = 4.0 -[sub_resource type="Image" id="Image_2t830"] +[sub_resource type="Image" id="Image_qm6yi"] data = { "data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 76, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 76, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 76, 255, 255, 255, 228, 255, 255, 255, 188, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 188, 255, 255, 255, 228, 255, 255, 255, 76, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 18, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 187, 255, 255, 255, 17, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 187, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 18, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 185, 255, 255, 255, 17, 255, 255, 255, 17, 255, 255, 255, 186, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 190, 255, 255, 255, 229, 255, 255, 255, 185, 255, 255, 255, 185, 255, 255, 255, 229, 255, 255, 255, 189, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 191, 255, 255, 255, 229, 255, 255, 255, 229, 255, 255, 255, 190, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 187, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 187, 255, 255, 255, 229, 255, 255, 255, 188, 255, 255, 255, 18, 255, 255, 255, 19, 255, 255, 255, 188, 255, 255, 255, 229, 255, 255, 255, 186, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 17, 255, 255, 255, 185, 255, 255, 255, 229, 255, 255, 255, 189, 255, 255, 255, 19, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 189, 255, 255, 255, 229, 255, 255, 255, 185, 255, 255, 255, 17, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 76, 255, 255, 255, 229, 255, 255, 255, 190, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 190, 255, 255, 255, 229, 255, 255, 255, 76, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 77, 255, 255, 255, 19, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 19, 255, 255, 255, 77, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "format": "RGBA8", @@ -456,7 +456,7 @@ } [sub_resource type="ImageTexture" id="56"] -image = SubResource("Image_2t830") +image = SubResource("Image_qm6yi") [sub_resource type="StyleBoxFlat" id="57"] content_margin_left = 6.0 diff --git a/DungeonShooting_Godot/src/framework/common/Utils.cs b/DungeonShooting_Godot/src/framework/common/Utils.cs index 3b06941..0e8b005 100644 --- a/DungeonShooting_Godot/src/framework/common/Utils.cs +++ b/DungeonShooting_Godot/src/framework/common/Utils.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Godot; /// @@ -97,4 +98,28 @@ Mathf.Abs(start1 - start2), Mathf.Abs(end1 - end2) ); } + + /// + /// 使用定的 canvasItem 绘制导航区域, 注意, 该函数只能在 draw 函数中调用 + /// + public static void DrawNavigationPolygon(CanvasItem canvasItem, NavigationPolygonData[] polygonData) + { + for (var i = 0; i < polygonData.Length; i++) + { + var item = polygonData[i]; + if (item.Points.Count >= 2) + { + var array = item.ConvertPointsToVector2Array().ToList(); + array.Add(array[0]); + if (item.Type == NavigationPolygonType.In) + { + canvasItem.DrawPolyline(array.ToArray(), Colors.Yellow); + } + else + { + canvasItem.DrawPolyline(array.ToArray(), Colors.Red); + } + } + } + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/map/DungeonRoomTemplate.cs b/DungeonShooting_Godot/src/framework/map/DungeonRoomTemplate.cs index b10bc0f..4510201 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonRoomTemplate.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonRoomTemplate.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text.Json; using Godot; @@ -54,7 +55,7 @@ private bool _mouseDown = false; - // + //门区域数据 private List _doorConfigs; private Rect2 _prevRect; @@ -62,8 +63,17 @@ private bool _canSave = false; private bool _clickSave = false; + private DungeonTile _dungeonTile; + + //计算导航的计时器 + private float _calcTileNavTimer = 0; + public override void _Ready() { + if (!Engine.IsEditorHint()) + { + return; + } EnableEdit = false; } @@ -74,6 +84,29 @@ return; } + if (_dungeonTile == null) + { + _dungeonTile = new DungeonTile(this); + _dungeonTile.SetFloorAtlasCoords(new List() { new Vector2I(0, 8) }); + OnTileChanged(); + var callable = new Callable(this, nameof(OnTileChanged)); + if (!IsConnected("changed", callable)) + { + Connect("changed", callable); + } + } + + //导航计算 + if (_calcTileNavTimer > 0) + { + _calcTileNavTimer -= (float)delta; + //重新计算导航 + if (_calcTileNavTimer <= 0) + { + _dungeonTile.GenerateNavigationPolygon(0); + } + } + //加载配置 var initConfigs = false; if (_doorConfigs == null) @@ -416,6 +449,7 @@ } } + //绘制区域 if (_doorConfigs != null) { var color2 = new Color(0, 1, 0, 0.8f); @@ -493,6 +527,24 @@ } } } + + //绘制导航, 现在有点问题, 绘制的内容会被自身的 tile 所挡住 + if (_dungeonTile != null) + { + var result = _dungeonTile.GetGenerateNavigationResult(); + if (result != null) + { + if (result.Success) + { + var polygonData = _dungeonTile.GetPolygonData(); + Utils.DrawNavigationPolygon(this, polygonData); + } + else + { + DrawCircle(result.Exception.Point * GenerateDungeon.TileCellSize, 10, Colors.Red); + } + } + } } } @@ -503,6 +555,11 @@ _hasActivePoint = false; _activeArea = null; } + + private void OnTileChanged() + { + _calcTileNavTimer = 1f; + } //创建门 private void CreateDoorArea(Rect2 mapRect) @@ -678,8 +735,11 @@ //触发保存操作 private void TriggerSave() { + //计算导航网格 + _dungeonTile.GenerateNavigationPolygon(0); + var polygonData = _dungeonTile.GetPolygonData(); var rect = GetUsedRect(); - SaveConfig(_doorConfigs, rect.Position, rect.Size, Name); + SaveConfig(_doorConfigs, rect.Position, rect.Size, polygonData.ToList(), Name); } /// @@ -697,7 +757,7 @@ /// /// 保存房间配置 /// - public static void SaveConfig(List doorConfigs, Vector2I position, Vector2I size, string name) + public static void SaveConfig(List doorConfigs, Vector2I position, Vector2I size, List polygonData, string name) { //存入本地 var path = RoomTileDataDir + name + ".json"; @@ -705,7 +765,7 @@ roomInfo.Position = new SerializeVector2(position); roomInfo.Size = new SerializeVector2(size); roomInfo.DoorAreaInfos = doorConfigs; - roomInfo.NavigationList = new List(); + roomInfo.NavigationList = polygonData; var config = new JsonSerializerOptions(); config.WriteIndented = true; diff --git a/DungeonShooting_Godot/src/framework/map/DungeonTile.cs b/DungeonShooting_Godot/src/framework/map/DungeonTile.cs index 8dac660..830714d 100644 --- a/DungeonShooting_Godot/src/framework/map/DungeonTile.cs +++ b/DungeonShooting_Godot/src/framework/map/DungeonTile.cs @@ -43,6 +43,8 @@ private TileMap _tileRoot; //地面地砖在 Atlas 的位置 private List _floorAtlasCoords; + //生成导航的结果 + private GenerateNavigationResult _generateNavigationResult; public DungeonTile(TileMap tileRoot) { @@ -438,77 +440,84 @@ { _usePoints.Clear(); _polygonDataList.Clear(); - - var size = new Vector2(_tileRoot.CellQuadrantSize, _tileRoot.CellQuadrantSize); - var rect = _tileRoot.GetUsedRect(); - - var x = rect.Position.X; - var y = rect.Position.Y; - var w = rect.Size.X; - var h = rect.Size.Y; - - for (int j = y; j < h; j++) + try { - for (int i = x; i < w; i++) + var size = new Vector2(_tileRoot.CellQuadrantSize, _tileRoot.CellQuadrantSize); + + var rect = _tileRoot.GetUsedRect(); + + var x = rect.Position.X; + var y = rect.Position.Y; + var w = rect.Size.X; + var h = rect.Size.Y; + + for (int j = y; j < h; j++) { - if (IsWayTile(layer, i, j)) + for (int i = x; i < w; i++) { - if (!_usePoints.Contains(new Vector2(i, j))) + if (IsWayTile(layer, i, j)) { - NavigationPolygonData polygonData = null; + if (!_usePoints.Contains(new Vector2(i, j))) + { + NavigationPolygonData polygonData = null; - if (!IsWayTile(layer, i, j - 1)) - { - polygonData = CalcOutline(layer, i, j, size); - } - else if (!IsWayTile(layer, i, j + 1)) - { - polygonData = CalcInline(layer, i, j, size); - } + if (!IsWayTile(layer, i, j - 1)) + { + polygonData = CalcOutline(layer, i, j, size); + } + else if (!IsWayTile(layer, i, j + 1)) + { + polygonData = CalcInline(layer, i, j, size); + } - if (polygonData != null) - { - _polygonDataList.Add(polygonData); + if (polygonData != null) + { + _polygonDataList.Add(polygonData); + } } } } } + + _generateNavigationResult = new GenerateNavigationResult(true); + } + catch (NavigationPointInterleavingException e) + { + _usePoints.Clear(); + _polygonDataList.Clear(); + GD.Print(e.Message); + _generateNavigationResult = new GenerateNavigationResult(false, e); } } /// + /// 获取生成导航区域操作的结果, 如果没有调用过 GenerateNavigationPolygon() 函数, 则返回 null + /// + /// + public GenerateNavigationResult GetGenerateNavigationResult() + { + return _generateNavigationResult; + } + + /// /// 将导航区域挂载到 navigationRoot 上 /// public void MountNavigationPolygon(Node2D navigationRoot) { //TestData(); // 在 Godot4.0_rc6 中 如果将所有点都放在 NavigationPolygon 里面, 即使点是对的, 但调用 MakePolygonsFromOutlines 还是可能会报错, 这应该是个bug - // for (var i = 0; i < _polygonDataList.Count; i++) - // { - // var polygonData = _polygonDataList[i]; - // var polygon = new NavigationPolygon(); - // var array = polygonData.Points.ToArray(); - // polygon.AddOutline(array); - // polygon.MakePolygonsFromOutlines(); - // var navigationPolygon = new NavigationRegion2D(); - // navigationPolygon.Name = "NavigationRegion" + i; - // navigationPolygon.NavigationPolygon = polygon; - // navigationRoot.AddChild(navigationPolygon); - // } - var polygon = new NavigationPolygon(); - for (var i = 0; i < _polygonDataList.Count; i++) { var polygonData = _polygonDataList[i]; + var polygon = new NavigationPolygon(); polygon.AddOutline(polygonData.ConvertPointsToVector2Array()); + polygon.MakePolygonsFromOutlines(); + var navigationPolygon = new NavigationRegion2D(); + navigationPolygon.Name = "NavigationRegion" + (navigationRoot.GetChildCount() + 1); + navigationPolygon.NavigationPolygon = polygon; + navigationRoot.AddChild(navigationPolygon); } - - polygon.MakePolygonsFromOutlines(); - var navigationPolygon = new NavigationRegion2D(); - navigationPolygon.Name = "NavigationRegion"; - navigationPolygon.NavigationPolygon = polygon; - navigationRoot.AddChild(navigationPolygon); } /// @@ -1024,7 +1033,7 @@ { if (_usePoints.Contains(pos)) { - throw new Exception("生成导航多边形发生错误! 点: " + pos + "发生交错!"); + throw new NavigationPointInterleavingException(pos, "生成导航多边形发生错误! 点: " + pos + "发生交错!"); } _usePoints.Add(pos); diff --git a/DungeonShooting_Godot/src/framework/map/GenerateDungeon.cs b/DungeonShooting_Godot/src/framework/map/GenerateDungeon.cs index 6574201..84511b5 100644 --- a/DungeonShooting_Godot/src/framework/map/GenerateDungeon.cs +++ b/DungeonShooting_Godot/src/framework/map/GenerateDungeon.cs @@ -83,6 +83,28 @@ // //没有合适的门 // NoProperDoor, } + + /// + /// 遍历所有房间 + /// + public void EachRoom(Action cb) + { + EachRoom(StartRoom, cb); + } + + private void EachRoom(RoomInfo roomInfo, Action cb) + { + if (roomInfo == null) + { + return; + } + + cb(roomInfo); + foreach (var next in roomInfo.Next) + { + EachRoom(next, cb); + } + } /// /// 生成房间 diff --git a/DungeonShooting_Godot/src/framework/map/GenerateNavigationResult.cs b/DungeonShooting_Godot/src/framework/map/GenerateNavigationResult.cs new file mode 100644 index 0000000..9a6001c --- /dev/null +++ b/DungeonShooting_Godot/src/framework/map/GenerateNavigationResult.cs @@ -0,0 +1,22 @@ + +/// +/// 生成导航返回的结果 +/// +public class GenerateNavigationResult +{ + public GenerateNavigationResult(bool success, NavigationPointInterleavingException exception = null) + { + Success = success; + Exception = exception; + } + + /// + /// 是否成功 + /// + public bool Success; + + /// + /// 异常信息 + /// + public NavigationPointInterleavingException Exception; +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/map/NavigationPointInterleavingException.cs b/DungeonShooting_Godot/src/framework/map/NavigationPointInterleavingException.cs new file mode 100644 index 0000000..284683c --- /dev/null +++ b/DungeonShooting_Godot/src/framework/map/NavigationPointInterleavingException.cs @@ -0,0 +1,19 @@ + +using System; +using Godot; + +/// +/// 导航点交错异常 +/// +public class NavigationPointInterleavingException : Exception +{ + /// + /// 交错点 + /// + public Vector2 Point { get; } + + public NavigationPointInterleavingException(Vector2 point, string message): base(message) + { + Point = point; + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/role/Player.cs b/DungeonShooting_Godot/src/game/role/Player.cs index e54164c..7e122e5 100644 --- a/DungeonShooting_Godot/src/game/role/Player.cs +++ b/DungeonShooting_Godot/src/game/role/Player.cs @@ -50,12 +50,12 @@ Shield = 30; // debug用 - Acceleration = 3000; - Friction = 3000; - MoveSpeed = 500; - CollisionLayer = 0; - CollisionMask = 0; - GameCamera.Main.Zoom = new Vector2(0.5f, 0.5f); + // Acceleration = 3000; + // Friction = 3000; + // MoveSpeed = 500; + // CollisionLayer = 0; + // CollisionMask = 0; + // GameCamera.Main.Zoom = new Vector2(0.5f, 0.5f); } protected override void Process(float delta) diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index 0f891f8..13b2818 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using Godot; @@ -33,6 +34,9 @@ private Font _font; private GenerateDungeon _generateDungeon; + //房间内所有导航网格数据 + private List _roomNavDataList = new List(); + public override void _EnterTree() { //创建玩家 @@ -63,6 +67,10 @@ _dungeonTile.GenerateNavigationPolygon(DungeonTile.AisleFloorLayer); //挂载导航区域 _dungeonTile.MountNavigationPolygon(this); + _roomNavDataList.AddRange(_dungeonTile.GetPolygonData()); + //挂载所有导航区域 + _generateDungeon.EachRoom(MountNavFromRoomInfo); + GD.Print("生成地牢用时: " + (DateTime.Now.Ticks - nowTicks) / 10000 + "毫秒"); //播放bgm @@ -151,30 +159,42 @@ // DrawLine(new Vector2(-5000, 0), new Vector2(5000, 0), Colors.Green); //绘制ai寻路区域 - var polygonData = _dungeonTile.GetPolygonData(); - for (var i = 0; i < polygonData.Length; i++) - { - var item = polygonData[i]; - if (item.Points.Count >= 2) - { - var array = item.ConvertPointsToVector2Array().ToList(); - array.Add(array[0]); - if (item.Type == NavigationPolygonType.In) - { - DrawPolyline(array.ToArray(), Colors.Yellow); - } - else - { - DrawPolyline(array.ToArray(), Colors.Red); - } - } - } + Utils.DrawNavigationPolygon(this, _roomNavDataList.ToArray()); } //绘制房间区域 //DrawRoomInfo(_generateDungeon.StartRoom); } } + private void MountNavFromRoomInfo(RoomInfo roomInfo) + { + var polygonArray = roomInfo.RoomSplit.RoomInfo.NavigationList.ToArray(); + var polygon = new NavigationPolygon(); + for (var i = 0; i < polygonArray.Length; i++) + { + var navigationPolygonData = polygonArray[i]; + var polygonPointArray = navigationPolygonData.ConvertPointsToVector2Array(); + //这里的位置需要加上房间位置 + for (var j = 0; j < polygonPointArray.Length; j++) + { + polygonPointArray[j] = polygonPointArray[j] + (roomInfo.Position + Vector2I.One) * GenerateDungeon.TileCellSize; + } + polygon.AddOutline(polygonPointArray); + + //存入汇总列表 + _roomNavDataList.Add(new NavigationPolygonData() + { + Type = navigationPolygonData.Type, + Points = polygonPointArray.Select(point => new SerializeVector2(point)).ToList(), + }); + } + polygon.MakePolygonsFromOutlines(); + var navigationPolygon = new NavigationRegion2D(); + navigationPolygon.Name = "NavigationRegion" + (GetChildCount() + 1); + navigationPolygon.NavigationPolygon = polygon; + AddChild(navigationPolygon); + } + //绘制房间区域, debug 用 private void DrawRoomInfo(RoomInfo room) {