From 3a3f1ea763b8b110cf1441cafe3d1129eacbfd91 Mon Sep 17 00:00:00 2001 From: vladislove Date: Thu, 1 Oct 2026 18:01:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=20=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D1=82=D1=8C=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8E=20=D0=BA=D0=BE=D0=BC=D0=BD=D0=B0=D1=82=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=BA=D0=BE=D1=80=D0=B8=D0=B4=D0=BE=D1=80=D0=B0?= =?UTF-8?q?,=20=D0=B4=D0=BE=20=D0=B8=D0=B8=20=D1=84=D1=83=D0=BD=D0=BA?= =?UTF-8?q?=D1=86=D0=B8=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/LevelGenerating/LevelManager.cs | 6 ++ .../_Project/Scripts/LevelGenerating/Room.cs | 12 ++++ .../Scripts/LevelGenerating/WallsGenerator.cs | 64 +++++++++++++++---- 3 files changed, 71 insertions(+), 11 deletions(-) diff --git a/Assets/_Project/Scripts/LevelGenerating/LevelManager.cs b/Assets/_Project/Scripts/LevelGenerating/LevelManager.cs index c67ef56..a3e16b6 100644 --- a/Assets/_Project/Scripts/LevelGenerating/LevelManager.cs +++ b/Assets/_Project/Scripts/LevelGenerating/LevelManager.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using _Project.Scripts.Utilities; using NUnit.Framework; using UnityEngine; @@ -14,5 +15,10 @@ namespace _Project.Scripts.LevelGenerating { Rooms.Add(room); } + + public Room GetLastRoom() + { + return Rooms.LastOrDefault(); + } } } \ No newline at end of file diff --git a/Assets/_Project/Scripts/LevelGenerating/Room.cs b/Assets/_Project/Scripts/LevelGenerating/Room.cs index 58572a0..f5791dc 100644 --- a/Assets/_Project/Scripts/LevelGenerating/Room.cs +++ b/Assets/_Project/Scripts/LevelGenerating/Room.cs @@ -35,10 +35,22 @@ namespace _Project.Scripts.LevelGenerating this.rt = rt; } + public Room(Vector2 position, int wigth, int length, RoomType rt, bool isWalling, EntranceToRoomType entrance, List exits) + { + Position = position; + Wigth = wigth; + Length = length; + this.rt = rt; + this.isWalling = isWalling; + this.entrance = entrance; + this.exits = exits; + } + public int Wigth { get; set; } public int Length { get; set; } public Vector2 Position; public RoomType rt { get; set; } + public bool isWalling {get; set;} //примыкает ли комната к стене public EntranceToRoomType entrance { get; set; } public List exits { get; set; } diff --git a/Assets/_Project/Scripts/LevelGenerating/WallsGenerator.cs b/Assets/_Project/Scripts/LevelGenerating/WallsGenerator.cs index 323875c..bb2774a 100644 --- a/Assets/_Project/Scripts/LevelGenerating/WallsGenerator.cs +++ b/Assets/_Project/Scripts/LevelGenerating/WallsGenerator.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.ComponentModel.Design.Serialization; using System.Linq; using UnityEngine; @@ -35,30 +36,35 @@ namespace _Project.Scripts.LevelGenerating LevelManager.Rooms.Add(new Room(Vector2.zero,lengthStartRoom, lengthStartRoom,RoomType.Start)); } - - void CreateCorridor(Vector2 posRoom, int Length, int Wigth, ExitsInRoomType exitType) + Room CreateCorridor(Vector2 posRoom, int Length, int Wigth, ExitsInRoomType exitType) { Vector2 corridorPos = Vector2.zero; int cLength = 0; int cWidth = 0; - + EntranceToRoomType entranceToRoomType = EntranceToRoomType.Null; + List exitsInRoomType = new List(); switch (exitType) { // Выход направо (+X) case ExitsInRoomType.XAxisP: // Начинается у правой стены комнаты (posRoom.x + Length) // Центрируем коридор по высоте/оси Z: смещаем на половину разницы ширин + exitsInRoomType.Add (ExitsInRoomType.XAxisP); + entranceToRoomType = EntranceToRoomType.XAxisN; corridorPos = new Vector2( posRoom.x + Length, posRoom.y + (Wigth - corridorWigth) / 2f ); cLength = corridorLength; cWidth = corridorWigth; + break; // Выход налево (-X) case ExitsInRoomType.XAxisN: // Начинается слева от комнаты, отступая на длину коридора + exitsInRoomType .Add (ExitsInRoomType.XAxisN); + entranceToRoomType = EntranceToRoomType.XAxisP; corridorPos = new Vector2( posRoom.x - corridorLength, posRoom.y + (Wigth - corridorWigth) / 2f @@ -69,6 +75,9 @@ namespace _Project.Scripts.LevelGenerating // Выход вперед/вверх (+Z / в Vector2 это Y) case ExitsInRoomType.ZAxisP: + entranceToRoomType = EntranceToRoomType.ZAxisN; + + exitsInRoomType.Add (ExitsInRoomType.ZAxisP); // Начинается у верхней стены комнаты (posRoom.y + Wigth) // Центрируем коридор по горизонтали/оси X: corridorPos = new Vector2( @@ -82,6 +91,9 @@ namespace _Project.Scripts.LevelGenerating // Выход назад/вниз (-Z / в Vector2 это Y) case ExitsInRoomType.ZAxisN: + entranceToRoomType = EntranceToRoomType.ZAxisP; + + exitsInRoomType.Add (ExitsInRoomType.ZAxisN); // Начинается ниже комнаты, отступая на длину коридора corridorPos = new Vector2( posRoom.x + (Length - corridorWigth) / 2f, @@ -93,11 +105,11 @@ namespace _Project.Scripts.LevelGenerating } // Создаем коридор как отдельную комнату - // (Убедись, что в enum RoomType добавлен тип Corridor, либо используй Normal) - Room corridor = new Room(cLength, cWidth, RoomType.Corridor); - // Либо через твой конструктор с позицией: - // Room corridor = new Room(corridorPos, cLength, cWidth, RoomType.Normal); - + + Room corridor = new Room(corridorPos, + cLength, cWidth, RoomType.Corridor,false, + EntranceToRoomType.Null,exitsInRoomType); + LevelManager.Rooms.Add(corridor); // Визуализация коридора (расставляем маркеры по углам коридора для наглядности) @@ -105,15 +117,41 @@ namespace _Project.Scripts.LevelGenerating Instantiate(GameObjectB, new Vector3(corridorPos.x + cLength, 0, corridorPos.y), Quaternion.identity); Instantiate(GameObjectB, new Vector3(corridorPos.x + cLength, 0, corridorPos.y + cWidth), Quaternion.identity); Instantiate(GameObjectB, new Vector3(corridorPos.x, 0, corridorPos.y + cWidth), Quaternion.identity); + return corridor; } - void CreateRoom() + + void TryPlaceRoom(Room corridor) + { + + // Room lastCorridor = LevelManager.Instance.GetLastRoom(); + if (corridor != null && corridor.exits.Count == 1) + { + switch (corridor.exits.Last()) + { + case ExitsInRoomType.XAxisP: + { + if ((lengthFloor - (corridor.Position.x + corridorLength + lengthWallMin) > 0) + && (lengthFloor - (corridor.Position.y + corridorWigth + lengthWallMin) > 0)) + { + Room newRoom = GenerateRandomRoom(); + if() + } + + break; + } + + } + } + + } + Room GenerateRandomRoom() { int a = Random.Range(lengthWallMin, lengthWallMax); int b = Random.Range(lengthWallMin, lengthWallMax); Room room = new Room(); room.Length = a; room.Wigth = b; - + return room; } void CreateStartRoom() @@ -190,7 +228,11 @@ namespace _Project.Scripts.LevelGenerating Instantiate(GameObjectB, new Vector3(xR,0,zR+lengthStartRoom), Quaternion.identity); CreateCorridor(new Vector2Int(xR, zR),lengthStartRoom,lengthStartRoom,room.exits.First()); - + Room firstCorridor = CreateCorridor(new Vector2(xR, zR), lengthStartRoom, lengthStartRoom, room.exits.First()); + if (firstCorridor != null) + { + TryPlaceRoom(firstCorridor); + } } }