Esempio n. 1
0
 public Room FindRoom(Property.RoomFilter filter)
 {
     foreach (Room room in dicRoomList.Values)
     {
         if (filter.Check(room.RoomProp))
         {
             return(room);
         }
     }
     return(null);
 }
Esempio n. 2
0
    private Room CreateRoomFromStack(Property.RoomFilter filter, bool specified, IntVector3 position, IntVector3 entry)
    {
        if (specified)
        {
            Debug.LogFormat("create room at {0},{1},{2}", position.x, position.y, position.z);
            Room result = null;
            if (dicRoomList.TryGetValue(position, out result) && result != null)
            {
                return(null);
            }
        }

        if (roomQueue.Count == 0)
        {
            RefillRoomQueue(15);
        }

        Property.Room roomProp = null;
        bool          isRoomGood;
        int           count = roomQueue.Count;

        do
        {
            if (--count < 0)
            {
                break;
            }

            roomProp   = roomQueue.Dequeue();
            isRoomGood = filter == null || filter.Check(roomProp);
            isRoomGood = isRoomGood && (specified ? roomProp.CanPlaceAt(position) : FindPlace(roomProp, out position, out entry));
            if (!isRoomGood)
            {
                roomQueue.Enqueue(roomProp);
                roomProp = null;
            }
        } while(!isRoomGood);

        Room roomInst = null;

        if (roomProp != null)
        {
            roomInst = new Room(roomProp);
            //make sure room has a connector to entry
            Rotation2D roomRot = roomInst.FaceTo(entry - position);
            //TODO: after we have position & rotation, check if this room can be placed in scene
            roomInst.Init(position, roomRot, Vector3.zero, Quaternion.identity);
        }

        return(roomInst);
    }