本文整理汇总了C#中Room.makeSpatialConnection方法的典型用法代码示例。如果您正苦于以下问题:C# Room.makeSpatialConnection方法的具体用法?C# Room.makeSpatialConnection怎么用?C# Room.makeSpatialConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Room
的用法示例。
在下文中一共展示了Room.makeSpatialConnection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: createAreaConnections
protected void createAreaConnections()
{
if (_startArea == null || !_areaRooms.ContainsKey(_startArea))
throw new UnityException("No start area!");
_startRoom = _areaRooms[_startArea];
// Create a grid of rooms to organize everything
Room[,] roomGrid = new Room[MAX_MAP_SIZE, MAX_MAP_SIZE];
// Also keep a record of area positions in the grid
Dictionary<string, Vector2> areaPositions = new Dictionary<string, Vector2>();
// Place the start room in the center of the grid
roomGrid[MAX_MAP_SIZE/2, MAX_MAP_SIZE/2] = _startRoom;
areaPositions[_startArea] = new Vector2((int)(MAX_MAP_SIZE/2), (int)(MAX_MAP_SIZE)/2);
// Branch off from the rooms one by one
Queue<string> agenda = new Queue<string>();
agenda.Enqueue(_startArea);
while (agenda.Count > 0) {
string areaName = agenda.Dequeue();
Vector2 areaPosition = areaPositions[areaName];
Room areaRoom = _areaRooms[areaName];
if (!_areaConnections.ContainsKey(areaName))
continue;
foreach (string neighbor in _areaConnections[areaName]) {
// Create a connection to this area
// Decide how many filler rooms we'll make
int numFillerRooms = Random.Range(MIN_FILLER_ROOMS, MAX_FILLER_ROOMS+1);
Room currentRoom = areaRoom;
Vector2 currentPos = areaPosition;
uint dir;
for (int i = 0; i < numFillerRooms; i++) {
// Choose a direction to expand
dir = expandRoom(currentRoom, currentPos, roomGrid);
Vector2 newRoomPos = pointFromDir(dir, currentPos);
Room newRoom = new Room();
newRoom.floorTilesName = currentRoom.floorTilesName;
// Connect our rooms
currentRoom.makeSpatialConnection(dir, newRoom);
newRoom.makeSpatialConnection(oppositeDir(dir), currentRoom);
// Add some goblins to the room
newRoom.addMonsters();
// Update the grid
roomGrid[(int)newRoomPos.x, (int)newRoomPos.y] = newRoom;
currentRoom = newRoom;
currentPos = newRoomPos;
}
// Finally, create the neighboring room at the next location.
Room neighborRoom = _areaRooms[neighbor];
dir = expandRoom(currentRoom, currentPos, roomGrid);
Vector2 neighborPos = pointFromDir(dir, currentPos);
currentRoom.makeSpatialConnection(dir, neighborRoom);
neighborRoom.makeSpatialConnection(oppositeDir(dir), currentRoom);
roomGrid[(int)neighborPos.x, (int)neighborPos.y] = neighborRoom;
areaPositions[neighbor] = neighborPos;
agenda.Enqueue(neighbor);
}
// Now, the locked doors
foreach (AreaConnectionRelationship lockedRel in _lockedAreaConnections[areaName]) {
string neighbor = lockedRel.secondAreaName;
// Spawn a lock
SpawnedPuzzleItem lockedDoor = spawnLockedDoor();
// Add the locked door relationship to our map
// Figure out what our actual key name is
string keyName = lockedRel.keyName;
DBItem dbKey = Database.Instance.getItem(keyName);
if (dbKey.propertyExists("keyname"))
keyName = dbKey.getProperty("keyname") as string;
_itemNames.Add(keyName);
if (!_relationshipMap.ContainsKey(keyName))
_relationshipMap[keyName] = new Dictionary<string, IRelationship>();
_relationshipMap[keyName][lockedDoor.itemName] = lockedRel;
if (!_relationshipMap.ContainsKey(lockedDoor.itemName))
_relationshipMap[lockedDoor.itemName] = new Dictionary<string, IRelationship>();
_relationshipMap[lockedDoor.itemName][keyName] = lockedRel;
// Decide how many filler rooms we'll make
int numFillerRooms = Random.Range(MIN_FILLER_ROOMS, MAX_FILLER_ROOMS+1);
Room currentRoom = areaRoom;
Vector2 currentPos = areaPosition;
uint dir;
for (int i = 0; i < numFillerRooms; i++) {
// Choose a direction to expand
dir = expandRoom(currentRoom, currentPos, roomGrid);
Vector2 newRoomPos = pointFromDir(dir, currentPos);
Room newRoom = new Room();
newRoom.floorTilesName = currentRoom.floorTilesName;
// Connect our rooms
if (i == 0) {
int doorIndex = currentRoom.makeLockedConnection(dir, newRoom, lockedDoor);
newRoom.makeLockedConnection(oppositeDir(dir), currentRoom, doorIndex);
}
else {
currentRoom.makeSpatialConnection(dir, newRoom);
newRoom.makeSpatialConnection(oppositeDir(dir), currentRoom);
}
//.........这里部分代码省略.........