using System.Collections.Generic; using UnityEngine; namespace _Project.Scripts.LevelGenerating { // ===================================================================== // НЕ ЗАБЫТЬ (напоминание себе): // Все координаты и размеры в Room хранятся в МОДУЛЯХ (1 модуль = 0.5 м), а не в метрах. // - В инспекторе WallsGenerator размеры задаются в метрах и переводятся в модули (x2). // - В мировые координаты переводить ТОЛЬКО через LevelGrid.ToWorld(...). // - Размеры комнат всегда ЧЁТНЫЕ в модулях (целые метры), иначе центровка по коридору // даст дробные позиции. Это обеспечивает WallsGenerator (метод Even). // ===================================================================== public static class LevelGrid { public const float Module = 0.5f; public const int PerMeter = 2; public static int FromMeters(int meters) => meters * PerMeter; public static Vector3 ToWorld(Vector2Int cell, float y = 0f) => new Vector3(cell.x * Module, y, cell.y * Module); public static Vector3 ToWorld(Vector2 cell, float y = 0f) => new Vector3(cell.x * Module, y, cell.y * Module); } public class Room { public Room(Vector2Int position, int width, int length, RoomType rt) : this() { Position = position; Width = width; Length = length; this.rt = rt; } public Room() { exits = new List(); } public Room(Vector2Int position, int width, int length, RoomType rt, EntranceToRoomType entrance) : this() { Position = position; Width = width; Length = length; this.rt = rt; this.entrance = entrance; } public Room(int width, int length, RoomType rt) : this() { Width = width; Length = length; this.rt = rt; } public Room(Vector2Int position, int width, int length, RoomType rt, bool isClipped, EntranceToRoomType entrance, List exits) { Position = position; Width = width; Length = length; this.rt = rt; this.entrance = entrance; this.isClipped = isClipped; this.exits = exits; } public int Width { get; set; } // по оси Z, в модулях public int Length { get; set; } // по оси X, в модулях public Vector2Int Position; // левый нижний угол, в модулях public RoomType rt { get; set; } public EntranceToRoomType entrance { get; set; } public bool isClipped { get; set; } public List exits { get; set; } public Vector2 Center => new Vector2(Position.x + Length / 2f, Position.y + Width / 2f); } }