Esempio n. 1
0
 public Vector2Int?CanInsertRoom(Room room, Vector2Int pos, Direction.to dir)
 {
     RoomDoor[] doorSort = room.Doors.OrderBy(x => Random.Range(0, room.Doors.Count())).ToArray();
     foreach (RoomDoor door in room.Doors)
     {
         if (Direction.GetOpposite(door.Dir) != dir)
         {
             continue;
         }
         room.From = door.Dir;
         Vector2Int roomPos = room.PosFromDoor(door, pos);
         Tilemap    tmp     = _grid.GetComponentsInChildren <Tilemap>().FirstOrDefault(t => t.gameObject.name == "Path");
         if (!TestCol(tmp, roomPos, room.Size))
         {
             continue;
         }
         tmp = _grid.GetComponentsInChildren <Tilemap>().FirstOrDefault(t => t.gameObject.name == "Ground");
         if (!TestCol(tmp, roomPos, room.Size))
         {
             continue;
         }
         return(roomPos);
     }
     return(null);
 }
Esempio n. 2
0
    public bool GenerateFromRoom(Grid room, float prob, Direction.to from)
    {
        if (Cap <= 0)
        {
            return(false);
        }
        if (room == null)
        {
            return(false);
        }
        Room theRoom = room.GetComponent <Room>();

        foreach (RoomDoor door in theRoom.Doors)
        {
            if (!(Random.Range(0, 100) < prob * 100) || door.Dir == room.GetComponent <Room>().From)
            {
                continue;
            }
            Cap--;
            if (Cap <= 0)
            {
                return(false);
            }
            Grid newRoom = GenerateFromDoor(door, room.GetComponent <Room>().DoorPos(door));
            AddToGrid(newRoom);
            GenerateFromRoom(newRoom, prob * Rate, from);
        }
        return(true);
    }
Esempio n. 3
0
 public void DrawPath(Vector2Int pos, int length, Direction.to dir)
 {
     for (int i = 0; i < length; i++)
     {
         Tilemap firstOrDefault = _grid.GetComponentsInChildren <Tilemap>()
                                  .FirstOrDefault(t => t.gameObject.name == "Path");
         if (firstOrDefault != null)
         {
             firstOrDefault
             .SetTile(new Vector3Int(pos.x, pos.y, 0), PathTile);
         }
         pos = Direction.GoAuto(new Vector2Int(pos.x, pos.y), 1, dir);
     }
 }