当前位置: 首页>>代码示例>>C#>>正文


C# Room.ConnectRoom方法代码示例

本文整理汇总了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 );
        }
    }
开发者ID:EddieCameron,项目名称:ManyRoomsTemplate,代码行数:67,代码来源:LevelGen.cs

示例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;
                    }
                }
            }

        }
    }
开发者ID:spiderdj,项目名称:Procedual,代码行数:22,代码来源:Generator.cs

示例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 );
        }
    }
开发者ID:jonbro,项目名称:ManyRoomsTemplate,代码行数:57,代码来源:LevelGen.cs


注:本文中的Room.ConnectRoom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。