public Room FindRoom(Property.RoomFilter filter) { foreach (Room room in dicRoomList.Values) { if (filter.Check(room.RoomProp)) { return(room); } } return(null); }
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); }
public static void TransportToRoom(CharacterPawn pawn, ActorBase actor, string roomFilter) { Connector from = actor as Connector; if (from == null) { Debug.LogError("TransportToRoom: from null connector!"); } Property.RoomFilter filter = Resources.Load <Property.RoomFilter>(string.Format("Room/RoomFilter/{0}", roomFilter)); Room destRoom = GameLoader.Instance.FindRoom(filter); if (destRoom == null) { destRoom = GameLoader.Instance.CreateRoomByFilter(filter); } if (destRoom != null) { foreach (Connector conn in destRoom.ConnectorList) { if (conn.connectorProp.IsDynamic) { if (conn.TryGetThrough(pawn, from.LogicPosition)) { from.parentRoom.Show(false); return; } } } Debug.LogErrorFormat("Transport to {0} fail! Cannot connect to dest room!", roomFilter); } else { Debug.LogErrorFormat("Transport to {0} fail! No dest room", roomFilter); } }
public Room CreateRoomByFilter(Property.RoomFilter filter) { return(CreateRoomFromStack(filter, false, IntVector3.Zero, IntVector3.Zero)); }