Exemple #1
0
        protected virtual Wall[] CreateConnectingWall(HallwayComponent hallway, Vector3 wallCenter)
        {
            // Prep maths
            Vector3    diff = this.transform.position - hallway.transform.position;
            Directions relativeDirection = GetRelativeDirection(hallway, diff);
            Vector2    openingSize       = hallway.GetExitSize(relativeDirection);
            float      wallWidth         = GetWallWidth(relativeDirection);

            float sideGapAdjustment = openingSize.x / 2 - Wall.THICKNESS;
            float sidePieceWidth    = (wallWidth - openingSize.x) / 2 + Wall.THICKNESS;
            float doorPieceHeight   = this.Height - openingSize.y;
            float centerPieceHeight = Height - hallway.Height;



            // Create piece and take ownership
            var leftPiece   = new Wall(this, sidePieceWidth, Height);
            var rightPiece  = new Wall(this, sidePieceWidth, Height);
            var centerPiece = new Wall(this, hallway.Width - Wall.THICKNESS * 2, centerPieceHeight);

            TakeOwnershipOfChildren(leftPiece, rightPiece, centerPiece);



            // Position pieces
            leftPiece.Instance.transform.Rotate(new Vector3(0, 90, 0));
            leftPiece.SetLocalPosition(-sideGapAdjustment - sidePieceWidth / 2, wallWidth / 2 - Wall.THICKNESS / 2);

            rightPiece.Instance.transform.Rotate(new Vector3(0, 90, 0));
            rightPiece.SetLocalPosition(sideGapAdjustment + sidePieceWidth / 2, wallWidth / 2 - Wall.THICKNESS / 2);

            centerPiece.SetLocalPosition(0, Height - Wall.THICKNESS, wallWidth / 2 - Wall.THICKNESS / 2, 90);



            // rotate this shit
            switch (relativeDirection)
            {
            case Directions.North:
                leftPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, 180);
                rightPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, 180);
                centerPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, 180);
                break;

            case Directions.East:
                leftPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, -90);
                rightPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, -90);
                centerPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, -90);
                break;

            case Directions.West:
                leftPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, 90);
                rightPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, 90);
                centerPiece.Instance.transform.RotateAround(this.transform.position, Vector3.up, 90);
                break;
            }

            return(new Wall[] {
                leftPiece, rightPiece, centerPiece
            });
        }