diff --git a/scripts/map/MapGenerator.cs b/scripts/map/MapGenerator.cs index dc5a91b..a2b6b44 100644 --- a/scripts/map/MapGenerator.cs +++ b/scripts/map/MapGenerator.cs @@ -241,7 +241,7 @@ public static class MapGenerator //If the room injection processor cannot be found, a print error occurs. //如果找不到房间注入处理器,那么打印错误。 LogCat.LogErrorWithFormat("room_injection_processor_does_not_exist", - LogCat.LogLabel.Default, LogCat.UploadFormat,injectionProcessorData.Id); + LogCat.LogLabel.Default, LogCat.UploadFormat, injectionProcessorData.Id); continue; } @@ -278,7 +278,7 @@ public static class MapGenerator if (roomPlacementData == null) { LogCat.LogWithFormat("failed_to_calculate_the_room_location", LogCat.LogLabel.Default, - LogCat.UploadFormat,roomNodeData.Id); + LogCat.UploadFormat, roomNodeData.Id); continue; } @@ -317,25 +317,26 @@ public static class MapGenerator //The input parameters are incomplete. //输入参数不全。 if (_roomPlacementStrategy == null || _mapRoot == null || string.IsNullOrEmpty(roomNodeDataId) || - roomPlacementData.Room == null) + roomPlacementData.NewRoom == null) { return false; } if (dictionary.ContainsKey(roomNodeDataId)) { - LogCat.LogWithFormat("place_existing_rooms", LogCat.LogLabel.Default, LogCat.UploadFormat,roomNodeDataId); + LogCat.LogWithFormat("place_existing_rooms", LogCat.LogLabel.Default, LogCat.UploadFormat, roomNodeDataId); return false; } if (!await _roomPlacementStrategy.PlaceRoom(_mapRoot, roomPlacementData)) { - LogCat.LogWarningWithFormat("room_placement_failed", LogCat.UploadFormat,LogCat.LogLabel.Default, roomNodeDataId); + LogCat.LogWarningWithFormat("room_placement_failed", LogCat.UploadFormat, LogCat.LogLabel.Default, + roomNodeDataId); return false; } - dictionary.Add(roomNodeDataId, roomPlacementData.Room); - LogCat.LogWithFormat("room_placement_information", LogCat.LogLabel.Default, LogCat.UploadFormat,roomNodeDataId, + dictionary.Add(roomNodeDataId, roomPlacementData.NewRoom); + LogCat.LogWithFormat("room_placement_information", LogCat.LogLabel.Default, LogCat.UploadFormat, roomNodeDataId, roomPlacementData.Position.ToString()); return true; } diff --git a/scripts/map/dateBean/RoomPlacementData.cs b/scripts/map/dateBean/RoomPlacementData.cs index 854a397..bda725e 100644 --- a/scripts/map/dateBean/RoomPlacementData.cs +++ b/scripts/map/dateBean/RoomPlacementData.cs @@ -14,18 +14,25 @@ public class RoomPlacementData /// 放置的位置 /// public Vector2? Position { get; set; } + /// /// Place the room template /// 放置的房间模板 /// - public Room? Room { get; set; } + public Room? NewRoom { get; set; } + /// + /// Parent room + /// 父级房间 + /// + public Room? ParentRoom { get; set; } + /// /// Parent room slot /// 父级房间的插槽 /// public RoomSlot? ParentRoomSlot { get; set; } - + /// /// A slot for the new room /// 新房间的插槽 diff --git a/scripts/map/dateBean/RoomSlot.cs b/scripts/map/dateBean/RoomSlot.cs index 3f050ec..a948b19 100644 --- a/scripts/map/dateBean/RoomSlot.cs +++ b/scripts/map/dateBean/RoomSlot.cs @@ -16,8 +16,34 @@ public class RoomSlot /// public bool Matched { get; set; } + /// + /// The starting position of the room slot + /// 房间插槽的开始位置 + /// + /// + ///As opposed to a tile map. Convert to local location please call + ///相对于瓦片地图而言的。转换为本地位置请调用 + /// public Vector2I StartPosition { get; set; } + + /// + /// The midpoint of the slot + /// 插槽的中点位置 + /// + /// + ///As opposed to a tile map. Convert to local location please call + ///相对于瓦片地图而言的。转换为本地位置请调用 + /// + public Vector2I MidpointPosition { get; set; } + /// + /// The end position of the room slot + /// 房间插槽的结束位置 + /// + /// + ///As opposed to a tile map. Convert to local location please call + ///相对于瓦片地图而言的。转换为本地位置请调用 + /// public Vector2I EndPosition { get; set; } /// diff --git a/scripts/map/room/Room.cs b/scripts/map/room/Room.cs index 8a497db..73b89db 100644 --- a/scripts/map/room/Room.cs +++ b/scripts/map/room/Room.cs @@ -194,10 +194,12 @@ public class Room //转为瓦片地图的坐标(中点) var tileMapStartPosition = tileMap.LocalToMap(startPosition); var tileMapEndPosition = tileMap.LocalToMap(endPosition); + var midpointPosition = tileMap.LocalToMap(midpointOfRoomSlots); var roomSlot = new RoomSlot { EndPosition = tileMapEndPosition, StartPosition = tileMapStartPosition, + MidpointPosition = midpointPosition, //Calculate the orientation of the slot (the midpoint of the room is the origin, the vector pointing to the midpoint of the slot) //计算槽位的方向(房间中点为原点,指向槽位中点的向量) DistanceToMidpointOfRoom = CoordinateUtils.VectorToOrientationArray(midpoint, midpointOfRoomSlots) diff --git a/scripts/map/roomPlacer/PatchworkRoomPlacementStrategy.cs b/scripts/map/roomPlacer/PatchworkRoomPlacementStrategy.cs index d6e138c..c7e77d5 100644 --- a/scripts/map/roomPlacer/PatchworkRoomPlacementStrategy.cs +++ b/scripts/map/roomPlacer/PatchworkRoomPlacementStrategy.cs @@ -98,19 +98,53 @@ public class PatchworkRoomPlacementStrategy : IRoomPlacementStrategy public Task PlaceRoom(Node mapRoot, RoomPlacementData roomPlacementData) { - if (roomPlacementData.Room == null || roomPlacementData.Position == null) + if (roomPlacementData.NewRoom == null || roomPlacementData.Position == null) { return Task.FromResult(false); } - if (roomPlacementData.Room.RootNode == null) + if (roomPlacementData.NewRoom.RootNode == null) { return Task.FromResult(false); } - var rootNode = roomPlacementData.Room.RootNode; - mapRoot.AddChild(rootNode); - rootNode.Position = roomPlacementData.Position.Value; + var newRootRootNode = roomPlacementData.NewRoom.RootNode; + mapRoot.AddChild(newRootRootNode); + newRootRootNode.Position = roomPlacementData.Position.Value; + //Place navigation Link + //放置导航Link + Vector2? navigationLink2DStartPosition = null; + if (roomPlacementData is { ParentRoom: not null, ParentRoomSlot: not null }) + { + var parentRoomTileMap = roomPlacementData.ParentRoom.TileMap; + var parentRoomRootNode = roomPlacementData.ParentRoom.RootNode; + if (parentRoomTileMap != null && parentRoomRootNode != null) + { + navigationLink2DStartPosition = parentRoomRootNode.Position + + parentRoomTileMap.MapToLocal(roomPlacementData.ParentRoomSlot + .EndPosition); + } + } + + Vector2? navigationLink2DEndPosition = null; + if (roomPlacementData.NewRoomSlot != null) + { + var newRoomTileMap = roomPlacementData.NewRoom.TileMap; + if (newRoomTileMap != null) + { + navigationLink2DEndPosition = newRootRootNode.Position + + newRoomTileMap.MapToLocal(roomPlacementData.NewRoomSlot.EndPosition); + } + } + + if (navigationLink2DStartPosition != null && navigationLink2DEndPosition != null) + { + var navigationLink2D = new NavigationLink2D(); + navigationLink2D.StartPosition = navigationLink2DStartPosition.Value; + navigationLink2D.EndPosition = navigationLink2DEndPosition.Value; + mapRoot.AddChild(navigationLink2D); + } + return Task.FromResult(true); } @@ -142,7 +176,7 @@ public class PatchworkRoomPlacementStrategy : IRoomPlacementStrategy //Saves all data in the room template that matches the parent room. //保存房间模板内所有与父房间匹配的数据。 - var useableRoomPlacementData = new List(); + var usableRoomPlacementData = new List(); foreach (var roomRes in roomResArray) { var newRoom = RoomFactory.CreateRoom(roomRes, newRoomNodeData.EnterRoomEventHandlerId, @@ -168,22 +202,23 @@ public class PatchworkRoomPlacementStrategy : IRoomPlacementStrategy if (position == null) continue; var roomPlacementData = new RoomPlacementData { - Room = newRoom, + NewRoom = newRoom, + ParentRoom = parentRoomNode, Position = position, ParentRoomSlot = mainRoomSlot, NewRoomSlot = newRoomSlot }; - useableRoomPlacementData.Add(roomPlacementData); + usableRoomPlacementData.Add(roomPlacementData); } - if (useableRoomPlacementData.Count == 0) + if (usableRoomPlacementData.Count == 0) { return null; } else { - var index = randomNumberGenerator.Randi() % useableRoomPlacementData.Count; - var roomPlacementData = useableRoomPlacementData[(int)index]; + var index = randomNumberGenerator.Randi() % usableRoomPlacementData.Count; + var roomPlacementData = usableRoomPlacementData[(int)index]; //Be sure to mark its slot as a match when you use it. //一定要在使用时,将其插槽标记为匹配。 if (roomPlacementData.ParentRoomSlot != null) @@ -217,7 +252,7 @@ public class PatchworkRoomPlacementStrategy : IRoomPlacementStrategy var index = randomNumberGenerator.Randi() % roomResArray.Length; var roomPlacementData = new RoomPlacementData { - Room = RoomFactory.CreateRoom(roomResArray[index], startRoomNodeData.EnterRoomEventHandlerId, + NewRoom = RoomFactory.CreateRoom(roomResArray[index], startRoomNodeData.EnterRoomEventHandlerId, startRoomNodeData.ExitRoomEventHandlerId), Position = Vector2.Zero };