本文整理汇总了C#中Room.GetConnections方法的典型用法代码示例。如果您正苦于以下问题:C# Room.GetConnections方法的具体用法?C# Room.GetConnections怎么用?C# Room.GetConnections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Room
的用法示例。
在下文中一共展示了Room.GetConnections方法的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 {
// 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 );
}
}
示例2: 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 );
}
}
示例3: SetLayersOnTree
void SetLayersOnTree(Room current, int distance)
{
visited.Add( current );
var unvisitedConnections = new List<ConnectionPoint>();
foreach ( var connection in current.GetConnections() ) {
if ( !visited.Contains( connection.connectedTo ) )
unvisitedConnections.Add( connection );
}
current.gameObject.name = "distance: " + distance;
current.gameObject.SetActive( true );
int layer;
if ( distance == 0 )
layer = nearLayer;
else if ( distance == 1 )
layer = farLayer;
else
layer = far2Layer;
SetLayerRecursively( current.gameObject, layer );
SetColliderState( current.gameObject, distance < 2 );
foreach ( var connection in unvisitedConnections ) {
if ( connection.isConnected ) {
if ( distance <= depthToPreGen ) {
SetLayerRecursively( connection.connector.gameObject, layer );
SetColliderState( connection.connector.gameObject, distance < 2 );
SetLayersOnTree( connection.connectedTo, distance + 1 );
}
else {
current.DisconnectRoom( connection.connectedTo );
Destroy( connection.connectedTo );
}
}
}
}