81 lines
3.3 KiB
C#
81 lines
3.3 KiB
C#
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<ExitsInRoomType>();
|
||
}
|
||
|
||
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 isWallable,
|
||
EntranceToRoomType entrance, List<ExitsInRoomType> exits)
|
||
{
|
||
Position = position;
|
||
Width = width;
|
||
Length = length;
|
||
this.rt = rt;
|
||
this.entrance = entrance;
|
||
this.isWallable = isWallable;
|
||
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 isWallable { get; set; } // по факту: комнату ужали об границу карты (стоит переименовать)
|
||
public List<ExitsInRoomType> exits { get; set; }
|
||
|
||
public Vector2 Center => new Vector2(Position.x + Length / 2f, Position.y + Width / 2f);
|
||
}
|
||
} |