本文整理汇总了C#中Room.ConnectRoom方法的典型用法代码示例。如果您正苦于以下问题:C# Room.ConnectRoom方法的具体用法?C# Room.ConnectRoom怎么用?C# Room.ConnectRoom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Room
的用法示例。
在下文中一共展示了Room.ConnectRoom方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRoomsToDepth
void AddRoomsToDepth( Room startingRoom, int depth )
{
foreach ( var currentRoomConnection in startingRoom.GetConnections() ) {
Room exitRoom;
if ( currentRoomConnection.isConnected )
exitRoom = currentRoomConnection.connectedTo;
else {
var nextRoomPrefab = GetRoomToConnectWith( currentRoomConnection.connectionType );
// instance the next room
exitRoom = (Room)Instantiate( nextRoomPrefab );
exitRoom.gameObject.SetActive( true );
// need to find the connection point
var cps = exitRoom.GetConnections();
cps.Shuffle();
ConnectionPoint newRoomConnectionPoint = null;
foreach ( var otherConn in cps ) {
if ( otherConn.doorType != ConnectionPoint.DoorType.EXIT &&
( currentRoomConnection.connectionType == ConnectionPoint.ConnectionType.ANY || otherConn.connectionType == ConnectionPoint.ConnectionType.ANY || otherConn.connectionType == currentRoomConnection.connectionType ) ) {
newRoomConnectionPoint = otherConn;
break;
}
}
if ( newRoomConnectionPoint == null )
Debug.LogError( "No valid connections found" );
// get a connector
Connector connectorPrefab;
if ( currentRoomConnection.connectionType != ConnectionPoint.ConnectionType.ANY )
connectorPrefab = GetConnectorForConnectionType( currentRoomConnection.connectionType ); // make sure connector can go with connections
else
connectorPrefab = GetConnectorForConnectionType( newRoomConnectionPoint.connectionType );
var connector = (Connector)Instantiate( connectorPrefab );
Transform connectorEndTransform = connector.end1 != null ? connector.end1 : connector.end2;
Transform connectorOtherEndTransform = connector.end2 != null ? connector.end2 : connector.end1;
// rotate / translate the new room and connector to match the transform of the existing exit
Transform newRoomConnectionTransform = newRoomConnectionPoint.transform;
currentRoomConnection.transform.Rotate( 0, 180, 0 );
// need to do this a few times to make sure all the axis line up
// end with the up axis, as that is the most important one. I can't help but feel like there is a better way to handle this
exitRoom.transform.rotation *= Quaternion.FromToRotation( newRoomConnectionTransform.forward, currentRoomConnection.transform.forward );
connector.transform.rotation *= Quaternion.FromToRotation( connectorEndTransform.forward, currentRoomConnection.transform.forward );
exitRoom.transform.rotation *= Quaternion.FromToRotation( newRoomConnectionTransform.right, currentRoomConnection.transform.right );
connector.transform.rotation *= Quaternion.FromToRotation( connectorEndTransform.right, currentRoomConnection.transform.right );
exitRoom.transform.rotation *= Quaternion.FromToRotation( newRoomConnectionTransform.up, currentRoomConnection.transform.up );
connector.transform.rotation *= Quaternion.FromToRotation( connectorEndTransform.up, currentRoomConnection.transform.up );
// unrotate the point
currentRoomConnection.transform.Rotate( 0, 180, 0 );
// move the new room such that the transform matches with the last connection point
connector.transform.position += ( currentRoomConnection.transform.position - connectorEndTransform.position );
exitRoom.transform.position += ( connectorOtherEndTransform.position - newRoomConnectionTransform.position );
// newRoomConnectionPoint.renderer.enabled = false;
// link up the rooms in the room tree
startingRoom.ConnectRoom( currentRoomConnection, connector, exitRoom );
exitRoom.ConnectRoom( newRoomConnectionPoint, connector, startingRoom );
}
if (depth > 0)
AddRoomsToDepth( exitRoom, depth - 1 );
}
}
示例2: JoinRooms
private static void JoinRooms(Room room, Room room1)
{
room.ConnectRoom(room1);
List<Point> path = pathFinder.findPath(new Point(room.x + room.width / 2, room.y + room.height / 2),new Point(room1.x + room1.width/2, room1.y + room1.height/2),getPathingValueFunc);
foreach (var point in path)
{
tilePlacements[point.x, point.y] = 2;
for (int x = -1; x < 2; x++)
{
for (int y = -1; y < 2; y++)
{
if(point.x + x >= 0 && point.x + x < tilePlacements.GetLength(0) && point.y + y >= 0 && point.y + y < tilePlacements.GetLength(1))
{
if(tilePlacements[point.x + x, point.y + y] == 0)
tilePlacements[point.x + x, point.y + y] = 1;
}
}
}
}
}
示例3: AddRoomsToDepth
void AddRoomsToDepth( Room startingRoom, int depth )
{
foreach ( var currentRoomConnection in startingRoom.GetConnections() ) {
Room exitRoom;
if ( currentRoomConnection.isConnected )
exitRoom = currentRoomConnection.connectedTo;
else {
// instance the next room
exitRoom = (Room)Instantiate( GetRoom() );
exitRoom.gameObject.SetActive( true );
// need to find the connection point
var cps = exitRoom.GetConnections();
Doorway newRoomConnectionPoint = cps[Random.Range( 0, cps.Length )];
// rotate / translate the new room and connector to match the transform of the existing exit
Transform newRoomConnectionTransform = newRoomConnectionPoint.transform;
currentRoomConnection.transform.Rotate( 0, 180, 0 );
// need to do this a few times to make sure all the axis line up
// end with the up axis, as that is the most important one. I can't help but feel like there is a better way to handle this
exitRoom.transform.rotation *= Quaternion.FromToRotation( newRoomConnectionTransform.forward, currentRoomConnection.transform.forward );
exitRoom.transform.rotation *= Quaternion.FromToRotation( newRoomConnectionTransform.right, currentRoomConnection.transform.right );
exitRoom.transform.rotation *= Quaternion.FromToRotation( newRoomConnectionTransform.up, currentRoomConnection.transform.up );
// move the new room such that the transform matches with the last connection point
exitRoom.transform.position += ( currentRoomConnection.transform.position - newRoomConnectionTransform.position );
// get a connector, sometimes
Connector connector = null;
if ( Random.value < .5f ) {
connector = (Connector)Instantiate( GetConnector() );
bool startEnd1 = Random.value < .5f;
Transform connectorEndTransform = startEnd1 ? connector.end1 : connector.end2;
Transform connectorOtherEndTransform = startEnd1 ? connector.end2 : connector.end1;
connector.transform.rotation *= Quaternion.FromToRotation( connectorEndTransform.forward, currentRoomConnection.transform.forward );
connector.transform.rotation *= Quaternion.FromToRotation( connectorEndTransform.right, currentRoomConnection.transform.right );
connector.transform.rotation *= Quaternion.FromToRotation( connectorEndTransform.up, currentRoomConnection.transform.up );
connector.transform.position += ( currentRoomConnection.transform.position - connectorEndTransform.position );
exitRoom.transform.position += ( connectorOtherEndTransform.position - newRoomConnectionTransform.position );
}
exitRoom.CalcBounds();
// unrotate the point
currentRoomConnection.transform.Rotate( 0, 180, 0 );
// newRoomConnectionPoint.renderer.enabled = false;
// link up the rooms in the room tree
startingRoom.ConnectRoom( currentRoomConnection, connector, exitRoom );
exitRoom.ConnectRoom( newRoomConnectionPoint, connector, startingRoom );
}
if (depth > 0)
AddRoomsToDepth( exitRoom, depth - 1 );
}
}