示例#1
0
        // Update the neighbor in a given relative direction.
        private void UpdateNeighborAt(int deltaX, int deltaZ)
        {
            WallTile wallTile = WallTileAtDelta(deltaX, deltaZ);

            if (wallTile != null)
            {
                wallTile.UpdateWall();
            }
        }
示例#2
0
        // Updates the spawned wall being used, with regards to neighboring wall tiles.
        public void UpdateWall()
        {
            WallTile left  = WallTileAtDelta(-1, 0);
            WallTile right = WallTileAtDelta(1, 0);
            WallTile up    = WallTileAtDelta(0, 1);
            WallTile down  = WallTileAtDelta(0, -1);
            int      count =
                (left != null ? 1 : 0) + (right != null ? 1 : 0) +
                (up != null ? 1 : 0) + (down != null ? 1 : 0);

            float yRotation = 0.0f;

            switch (count)
            {
            case 0:
                // If by yourself, use a single tile.
                SpawnWall(SinglePrefab, 180.0f);
                break;

            case 1:
                // If only one neighbor, rotate so that the edge touches that neighbor.
                if (up != null)
                {
                    yRotation = 180.0f;
                }
                else if (left != null)
                {
                    yRotation = 90.0f;
                }
                else if (right != null)
                {
                    yRotation = 270.0f;
                }
                SpawnWall(SinglePrefab, yRotation);
                break;

            case 2:
                GameObject prefab;
                if (up == down || left == right)
                {
                    // If two neighbors, that are directly across from eachother,
                    // use a straight piece that connects the two.
                    prefab = SinglePrefab;
                    if (left != null)
                    {
                        yRotation = 90.0f;
                    }
                }
                else
                {
                    // Otherwise, use a corner piece, oriented to touch the two neighbors.
                    if (up != null)
                    {
                        if (left != null)
                        {
                            yRotation = 90.0f;
                        }
                        else
                        {
                            yRotation = 180.0f;
                        }
                    }
                    else if (right != null)
                    {
                        yRotation = 270.0f;
                    }
                    prefab = CornerPrefab;
                }
                SpawnWall(prefab, yRotation);
                break;

            case 3:
                // With three neighbors, orient so that the flat edge is towards the missing one.
                if (right == null)
                {
                    yRotation = 90.0f;
                }
                else if (down == null)
                {
                    yRotation = 180.0f;
                }
                else if (left == null)
                {
                    yRotation = 270.0f;
                }
                SpawnWall(TTurnPrefab, yRotation);
                break;

            case 4:
                // With four neighbors, connect to all four.
                SpawnWall(JunctionPrefab, yRotation);
                break;
            }
        }