Room.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using UnityEngine;
  4. namespace MazeGen
  5. {
  6. public enum RoomKind
  7. {
  8. Start,
  9. Normal,
  10. Hallway,
  11. Exit
  12. }
  13. /// <summary>
  14. /// A single node in the maze graph. Rooms are NOT tied to a grid - Position is a free
  15. /// world-space point derived from the exit direction + spacing of whichever exit spawned it.
  16. /// </summary>
  17. public class Room
  18. {
  19. public readonly int Id;
  20. public readonly RoomKind Kind;
  21. public readonly Vector2 Position;
  22. public readonly float Radius;
  23. public readonly int DepthFromStart;
  24. public readonly List<Exit> Exits = new List<Exit>();
  25. /// <summary>
  26. /// Set only on Hallway rooms created as a 90-degree elbow connector between two
  27. /// known doors (both straight extension and bend cases). World-space polyline the
  28. /// corridor should be rendered along - [doorA, corner, doorB] for a bend, or left
  29. /// null for hallway rooms whose far exit isn't resolved yet (ordinary lazy hallways).
  30. /// </summary>
  31. public Vector2[] CorridorWaypoints;
  32. public Room(int id, RoomKind kind, Vector2 position, float radius, int depthFromStart)
  33. {
  34. Id = id;
  35. Kind = kind;
  36. Position = position;
  37. Radius = radius;
  38. DepthFromStart = depthFromStart;
  39. }
  40. public IEnumerable<Exit> UnusedExits => Exits.Where(e => !e.IsUsed);
  41. public bool HasUnusedExits => Exits.Any(e => !e.IsUsed);
  42. }
  43. }