Esempio n. 1
0
    /// <summary>
    /// Return an array with tiles that connect sideways
    /// </summary>
    /// <param name="levelTiles"></param>
    /// <returns></returns>
    public GameObject[] FindPossibleCorner(ref GameObject[] levelTiles)
    {
        List <GameObject> cornerBlocksList = new List <GameObject>();
        List <GameObject> levelBlocksList  = new List <GameObject>();

        for (int i = 0; i < levelTiles.Count(); i++)
        {
            GridLevelBlock b = levelTiles[i].GetComponentInChildren <GridLevelBlock>();
            if (b.frontTopLeft || b.frontTop || b.frontTopRight || b.frontMidLeft || b.frontMid || b.frontMidRight ||
                b.frontBottomLeft || b.frontBottom || b.frontBottomRight || b.backTopLeft || b.backTop || b.backTopRight ||
                b.backMidLeft || b.backMid || b.backMidRight || b.backBottomLeft || b.backBottom || b.backBottomRight)
            {
                if (b.leftTopLeft || b.leftTop || b.leftTopRight || b.leftMidLeft || b.leftMid || b.leftMidRight ||
                    b.leftBottomLeft || b.leftBottom || b.leftBottomRight || b.rightTopLeft || b.rightTop || b.rightTopRight ||
                    b.rightMidLeft || b.rightMid || b.rightMidRight || b.rightBottomLeft || b.rightBottom || b.rightBottomRight)
                {
                    cornerBlocksList.Add(levelTiles[i]);
                }
                else
                {
                    levelBlocksList.Add(levelTiles[i]);
                }
            }
            else
            {
                levelBlocksList.Add(levelTiles[i]);
            }
        }

        levelTiles = levelBlocksList.ToArray();
        return(cornerBlocksList.ToArray());
    }
Esempio n. 2
0
    private void GenerateSpawnTile(GameObject[,,] levelLayout, Vector3[,,] layoutPositions)
    {
        GameObject[] randomSpawnTiles = pathValidator.GetRandomSortedArray(spawnTiles);
        foreach (GameObject spawnTile in randomSpawnTiles)
        {
            GridLevelBlock spawn = spawnTile.GetComponentInChildren <GridLevelBlock>();
            if (!spawn.backTopLeft && !spawn.backTop && !spawn.backTopRight &&
                !spawn.backMidLeft && !spawn.backMid && !spawn.backMidRight &&
                !spawn.backBottomLeft && !spawn.backBottom && !spawn.backBottomRight)
            {
                continue;
            }
            else
            {
                levelLayout[0, 0, 0]     = spawnTile;
                layoutPositions[0, 0, 0] = new Vector3(blockSize * 0, blockSize * 0, blockSize * 0);
                break;
            }
        }

        if (levelLayout[0, 0, 0] == null)
        {
            Debug.LogError("Spawn point must have an exit on 'Back' face with rotation '0'");
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Validates if the current block can be accessed through the previous block
    /// </summary>
    /// <param name="previousBlock">The block in the previous position of the grid</param>
    /// <param name="currentBlock">The block we are currently validating</param>
    /// <returns></returns>
    public bool ValidateRowPath(GridLevelBlock previousBlock, GridLevelBlock currentBlock, GridLevelBlock nextBlock)
    {
        bool pathBackwards;
        bool pathForward;

        if (ValidatePathForward(previousBlock, currentBlock))
        {
            pathBackwards = true;
        }
        else
        {
            pathBackwards = false;
        }

        if (nextBlock == null)
        {
            pathForward = true;
        }
        else
        {
            if (ValidatePathForward(currentBlock, nextBlock))
            {
                pathForward = true;
            }
            else
            {
                pathForward = false;
            }
        }

        return(pathBackwards && pathForward);
    }
Esempio n. 4
0
    private void GenerateRows(GameObject[,,] levelLayout, Vector3[,,] layoutPositions)
    {
        for (int y = 0; y < sizeY; y++)
        {
            for (int x = 0; x < sizeX; x++)
            {
                for (int z = 0; z < sizeZ; z++)
                {
                    if (levelLayout[x, y, z] == null)
                    {
                        GameObject     previousObject = levelLayout[x - 1, y, z];
                        GridLevelBlock previousBlock  = previousObject.GetComponentInChildren <GridLevelBlock>();
                        GameObject     nextObj        = levelLayout[x + 1, y, z];
                        GridLevelBlock nextBlock      = null;
                        if (nextObj != null)
                        {
                            nextBlock = nextObj.GetComponentInChildren <GridLevelBlock>();
                        }

                        GameObject[] randomLevelTiles = pathValidator.GetRandomSortedArray(levelTiles);
                        foreach (GameObject levelTile in randomLevelTiles)
                        {
                            GridLevelBlock levelBlock = levelTile.GetComponentInChildren <GridLevelBlock>();

                            if (pathValidator.ValidateRowPath(previousBlock, levelBlock, nextBlock))
                            {
                                levelLayout[x, y, z]     = levelTile;
                                layoutPositions[x, y, z] = new Vector3(blockSize * x, blockSize * y, blockSize * z);
                                break;
                            }
                            else
                            {
                                continue;
                            }
                        }

                        if (levelLayout[x, y, z] == null)
                        {
                            if (nextBlock != null)
                            {
                                Debug.LogError("Could not find a valid path forward between " + previousObject.name + " and " + nextObj.name);
                            }
                            else
                            {
                                Debug.LogError("Could not find a valid path forward after " + previousObject.name);
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 5
0
 /// <summary>
 /// Validates if there is a way forward between 2 tiles
 /// </summary>
 /// <param name="bottomBlock"></param>
 /// <param name="upperBlock"></param>
 /// <returns></returns>
 public bool ValidatePathUpwards(GridLevelBlock bottomBlock, GridLevelBlock upperBlock)
 {
     if ((bottomBlock.topTopLeft && upperBlock.bottomTopRight) || (bottomBlock.topTop && upperBlock.bottomTop) || (bottomBlock.topTopRight && upperBlock.bottomTopLeft) ||
         (bottomBlock.topMidLeft && upperBlock.bottomMidRight) || (bottomBlock.topMid && upperBlock.bottomMid) || (bottomBlock.topMidRight && upperBlock.bottomMidLeft) ||
         (bottomBlock.topBottomLeft && upperBlock.bottomBottomRight) || (bottomBlock.topBottom && upperBlock.bottomBottom) || (bottomBlock.topBottomRight && upperBlock.bottomBottomLeft))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Validates if a corner block has path to the right connecting to the previous block
 /// </summary>
 /// <param name="previousBlock">The block in the previous position of the grid</param>
 /// <param name="currentBlock">The block we are currently validating</param>
 /// <param name="oddRow">Defines whether we should go right or left</param>
 /// <returns></returns>
 public bool ValidatePathSideways(GridLevelBlock previousBlock, GridLevelBlock currentBlock)
 {
     if ((previousBlock.leftTopLeft && currentBlock.rightTopRight) || (previousBlock.leftTop && currentBlock.rightTop) || (previousBlock.leftTopRight && currentBlock.rightTopLeft) ||
         (previousBlock.leftMidLeft && currentBlock.rightMidRight) || (previousBlock.leftMid && currentBlock.rightMid) || (previousBlock.leftMidRight && currentBlock.rightMidLeft) ||
         (previousBlock.leftBottomLeft && currentBlock.rightBottomRight) || (previousBlock.leftBottom && currentBlock.rightBottom) || (previousBlock.leftBottomRight && currentBlock.rightBottomLeft))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Validates if there is a foward connection between two tiles
 /// </summary>
 /// <param name="currentTile"></param>
 /// <param name="nextTile"></param>
 /// <returns></returns>
 private bool ValidatePathForward(GridLevelBlock currentTile, GridLevelBlock nextTile)
 {
     if ((currentTile.backTopLeft && nextTile.frontTopRight) || (currentTile.backTop && nextTile.frontTop) || (currentTile.backTopRight && nextTile.frontTopLeft) ||
         (currentTile.backMidLeft && nextTile.frontMidRight) || (currentTile.backMid && nextTile.frontMid) || (currentTile.backMidRight && nextTile.frontMidLeft) ||
         (currentTile.backBottomLeft && nextTile.frontBottomRight) || (currentTile.backBottom && nextTile.frontBottom) || (currentTile.backBottomRight && nextTile.frontBottomLeft))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 8
0
    /// <summary>
    /// Return an array with tiles that have a path down
    /// </summary>
    /// <param name="levelTiles">Array containing all tiles</param>
    /// <returns></returns>
    public GameObject[] FindPossibleWayDown(ref GameObject[] levelTiles)
    {
        List <GameObject> downBlocksList  = new List <GameObject>();
        List <GameObject> levelBlocksList = new List <GameObject>();

        for (int i = 0; i < levelTiles.Count(); i++)
        {
            GridLevelBlock b = levelTiles[i].GetComponentInChildren <GridLevelBlock>();
            if (b.bottomTopLeft || b.bottomTop || b.bottomTopRight ||
                b.bottomMidLeft || b.bottomMid || b.bottomMidRight ||
                b.bottomBottomLeft || b.bottomBottom || b.bottomBottomRight)
            {
                downBlocksList.Add(levelTiles[i]);
            }
            else
            {
                levelBlocksList.Add(levelTiles[i]);
            }
        }

        levelTiles = levelBlocksList.ToArray();
        return(downBlocksList.ToArray());
    }
Esempio n. 9
0
    private void GenerateCorners(GameObject[,,] levelLayout, Vector3[,,] layoutPositions)
    {
        int x = sizeX - 1;

        for (int y = 0; y < sizeY; y++)
        {
            for (int z = 0; z < sizeZ; z++)
            {
                if (z % 2 == 0)
                {
                    if (levelLayout[0, y, z] == null)
                    {
                        GameObject[] randomCornerTiles = pathValidator.GetRandomSortedArray(cornerTiles);
                        foreach (GameObject cornerTile in randomCornerTiles)
                        {
                            GridLevelBlock tile = cornerTile.GetComponentInChildren <GridLevelBlock>();
                            if (!tile.backTopLeft && !tile.backTop && !tile.backTopRight &&
                                !tile.backMidLeft && !tile.backMid && !tile.backMidRight &&
                                !tile.backBottomLeft && !tile.backBottom && !tile.backBottomRight)
                            {
                                continue;
                            }
                            else
                            {
                                if (!tile.rightTopLeft && !tile.rightTop && !tile.rightTopRight &&
                                    !tile.rightMidLeft && !tile.rightMid && !tile.rightMidRight &&
                                    !tile.rightBottomLeft && !tile.rightBottom && !tile.rightBottomRight)
                                {
                                    continue;
                                }
                                else
                                {
                                    GridLevelBlock previousTile = levelLayout[0, y, z - 1].GetComponentInChildren <GridLevelBlock>();

                                    if (pathValidator.ValidatePathSideways(previousTile, tile))
                                    {
                                        levelLayout[0, y, z]     = cornerTile;
                                        layoutPositions[0, y, z] = new Vector3(0, blockSize * y, blockSize * z);
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (levelLayout[x, y, z] == null)
                    {
                        GameObject[] randomCornerTiles = pathValidator.GetRandomSortedArray(cornerTiles);
                        foreach (GameObject cornerTile in randomCornerTiles)
                        {
                            GridLevelBlock tile = cornerTile.GetComponentInChildren <GridLevelBlock>();
                            if (!tile.frontTopLeft && !tile.frontTop && !tile.frontTopRight &&
                                !tile.frontMidLeft && !tile.frontMid && !tile.frontMidRight &&
                                !tile.frontBottomLeft && !tile.frontBottom && !tile.frontBottomRight)
                            {
                                continue;
                            }
                            else
                            {
                                if (!tile.leftTopLeft && !tile.leftTop && !tile.leftTopRight &&
                                    !tile.leftMidLeft && !tile.leftMid && !tile.leftMidRight &&
                                    !tile.leftBottomLeft && !tile.leftBottom && !tile.leftBottomRight)
                                {
                                    continue;
                                }
                                else
                                {
                                    levelLayout[x, y, z]     = cornerTile;
                                    layoutPositions[x, y, z] = new Vector3(blockSize * x, blockSize * y, blockSize * z);
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (levelLayout[0, y, z] == null)
                    {
                        GameObject[] randomCornerTiles = pathValidator.GetRandomSortedArray(cornerTiles);
                        foreach (GameObject cornerTile in randomCornerTiles)
                        {
                            GridLevelBlock tile = cornerTile.GetComponentInChildren <GridLevelBlock>();
                            if (!tile.backTopLeft && !tile.backTop && !tile.backTopRight &&
                                !tile.backMidLeft && !tile.backMid && !tile.backMidRight &&
                                !tile.backBottomLeft && !tile.backBottom && !tile.backBottomRight)
                            {
                                continue;
                            }
                            else
                            {
                                if (!tile.leftTopLeft && !tile.leftTop && !tile.leftTopRight &&
                                    !tile.leftMidLeft && !tile.leftMid && !tile.leftMidRight &&
                                    !tile.leftBottomLeft && !tile.leftBottom && !tile.leftBottomRight)
                                {
                                    continue;
                                }
                                else
                                {
                                    levelLayout[0, y, z]     = cornerTile;
                                    layoutPositions[0, y, z] = new Vector3(0, blockSize * y, blockSize * z);
                                    break;
                                }
                            }
                        }
                    }

                    if (levelLayout[x, y, z] == null)
                    {
                        GameObject[] randomCornerTiles = pathValidator.GetRandomSortedArray(cornerTiles);
                        foreach (GameObject cornerTile in randomCornerTiles)
                        {
                            GridLevelBlock cornerBlock = cornerTile.GetComponentInChildren <GridLevelBlock>();
                            if (!cornerBlock.frontTopLeft && !cornerBlock.frontTop && !cornerBlock.frontTopRight &&
                                !cornerBlock.frontMidLeft && !cornerBlock.frontMid && !cornerBlock.frontMidRight &&
                                !cornerBlock.frontBottomLeft && !cornerBlock.frontBottom && !cornerBlock.frontBottomRight)
                            {
                                continue;
                            }
                            else
                            {
                                if (!cornerBlock.rightTopLeft && !cornerBlock.rightTop && !cornerBlock.rightTopRight &&
                                    !cornerBlock.rightMidLeft && !cornerBlock.rightMid && !cornerBlock.rightMidRight &&
                                    !cornerBlock.rightBottomLeft && !cornerBlock.rightBottom && !cornerBlock.rightBottomRight)
                                {
                                    continue;
                                }
                                else
                                {
                                    GridLevelBlock previousTile = levelLayout[x, y, z - 1].GetComponentInChildren <GridLevelBlock>();

                                    if (pathValidator.ValidatePathSideways(previousTile, cornerBlock))
                                    {
                                        levelLayout[x, y, z]     = cornerTile;
                                        layoutPositions[x, y, z] = new Vector3(blockSize * x, blockSize * y, blockSize * z);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 10
0
    private void GenerateWayUp(GameObject[,,] levelLayout, Vector3[,,] layoutPositions)
    {
        int x = sizeX - 1;
        int z = sizeZ - 1;

        for (int i = 0; i < sizeY; i++)
        {
            if (i % 2 == 0)
            {
                if (z % 2 == 0 && levelLayout[x, i, z] == null)
                {
                    GameObject[] randomWayUpTiles   = pathValidator.GetRandomSortedArray(wayUpTiles);
                    GameObject[] randomWayDownTiles = pathValidator.GetRandomSortedArray(wayDownTiles);

                    foreach (GameObject wayUpTile in randomWayUpTiles)
                    {
                        if (levelLayout[x, i, z] != null && levelLayout[x, i + 1, z] != null)
                        {
                            break;
                        }

                        GridLevelBlock bottomTile = wayUpTile.GetComponentInChildren <GridLevelBlock>();

                        if (bottomTile.frontTopLeft || bottomTile.frontTop || bottomTile.frontTopRight ||
                            bottomTile.frontMidLeft || bottomTile.frontMid || bottomTile.frontMidRight ||
                            bottomTile.frontBottomLeft || bottomTile.frontBottom || bottomTile.frontBottomRight)
                        {
                            foreach (GameObject wayDownTiles in randomWayDownTiles)
                            {
                                GridLevelBlock upperTile = wayDownTiles.GetComponentInChildren <GridLevelBlock>();

                                if (upperTile.frontTopLeft || upperTile.frontTop || upperTile.frontTopRight ||
                                    upperTile.frontMidLeft || upperTile.frontMid || upperTile.frontMidRight ||
                                    upperTile.frontBottomLeft || upperTile.frontBottom || upperTile.frontBottomRight)
                                {
                                    if (pathValidator.ValidatePathUpwards(bottomTile, upperTile))
                                    {
                                        levelLayout[x, i, z]     = wayUpTile;
                                        layoutPositions[x, i, z] = new Vector3(blockSize * x, blockSize * i, blockSize * z);

                                        levelLayout[x, i + 1, z]     = wayDownTiles;
                                        layoutPositions[x, i + 1, z] = new Vector3(blockSize * x, blockSize * (i + 1), blockSize * z);
                                    }
                                }
                            }
                        }
                    }

                    if (levelLayout[x, i, z] == null || levelLayout[x, i + 1, z] == null)
                    {
                        Debug.LogError("Failed to find a way upwards for position X:" + x + " Y:" + i + " Z:" + z);
                    }
                }
                else if (z % 2 != 0 && levelLayout[0, i, z] == null)
                {
                    GameObject[] randomWayUpBlocks   = pathValidator.GetRandomSortedArray(wayUpTiles);
                    GameObject[] randomWayDownBlocks = pathValidator.GetRandomSortedArray(wayDownTiles);

                    foreach (GameObject wayUpBlock in randomWayUpBlocks)
                    {
                        if (levelLayout[0, i, z] != null && levelLayout[0, i + 1, z] != null)
                        {
                            break;
                        }

                        GridLevelBlock bottomTile = wayUpBlock.GetComponentInChildren <GridLevelBlock>();

                        if (bottomTile.backTopLeft || bottomTile.backTop || bottomTile.backTopRight ||
                            bottomTile.backMidLeft || bottomTile.backMid || bottomTile.backMidRight ||
                            bottomTile.backBottomLeft || bottomTile.backBottom || bottomTile.backBottomRight)
                        {
                            foreach (GameObject wayDownBlock in randomWayDownBlocks)
                            {
                                GridLevelBlock upperTile = wayDownBlock.GetComponentInChildren <GridLevelBlock>();

                                if (upperTile.backTopLeft || upperTile.backTop || upperTile.backTopRight ||
                                    upperTile.backMidLeft || upperTile.backMid || upperTile.backMidRight ||
                                    upperTile.backBottomLeft || upperTile.backBottom || upperTile.backBottomRight)
                                {
                                    if (pathValidator.ValidatePathUpwards(bottomTile, upperTile))
                                    {
                                        levelLayout[0, i, z]     = wayUpBlock;
                                        layoutPositions[0, i, z] = new Vector3(0, blockSize * i, blockSize * z);

                                        levelLayout[0, i + 1, z]     = wayDownBlock;
                                        layoutPositions[0, i + 1, z] = new Vector3(0, blockSize * (i + 1), blockSize * z);
                                    }
                                }
                            }
                        }
                    }

                    if (levelLayout[0, i, z] == null || levelLayout[0, i + 1, z] == null)
                    {
                        Debug.LogError("Failed to find a way upwards for position X:" + x + " Y:" + i + " Z:" + z);
                    }
                }
            }
            else
            {
                if (levelLayout[0, i, 0] == null)
                {
                    GameObject[] randomWayUpBlocks   = pathValidator.GetRandomSortedArray(wayUpTiles);
                    GameObject[] randomWayDownBlocks = pathValidator.GetRandomSortedArray(wayDownTiles);

                    foreach (GameObject wayUpBlock in randomWayUpBlocks)
                    {
                        if (levelLayout[0, i, 0] != null && levelLayout[0, i + 1, 0] != null)
                        {
                            break;
                        }

                        GridLevelBlock bottomTile = wayUpBlock.GetComponentInChildren <GridLevelBlock>();

                        if (bottomTile.backTopLeft || bottomTile.backTop || bottomTile.backTopRight ||
                            bottomTile.backMidLeft || bottomTile.backMid || bottomTile.backMidRight ||
                            bottomTile.backBottomLeft || bottomTile.backBottom || bottomTile.backBottomRight)
                        {
                            foreach (GameObject wayDownBlock in randomWayDownBlocks)
                            {
                                GridLevelBlock upperTile = wayDownBlock.GetComponentInChildren <GridLevelBlock>();

                                if (upperTile.backTopLeft || upperTile.backTop || upperTile.backTopRight ||
                                    upperTile.backMidLeft || upperTile.backMid || upperTile.backMidRight ||
                                    upperTile.backBottomLeft || upperTile.backBottom || upperTile.backBottomRight)
                                {
                                    if (pathValidator.ValidatePathUpwards(bottomTile, upperTile))
                                    {
                                        levelLayout[0, i, 0]     = wayUpBlock;
                                        layoutPositions[0, i, 0] = new Vector3(0, blockSize * i, 0);

                                        levelLayout[0, i + 1, 0]     = wayDownBlock;
                                        layoutPositions[0, i + 1, 0] = new Vector3(0, blockSize * (i + 1), 0);
                                    }
                                }
                            }
                        }
                    }

                    if (levelLayout[0, i, 0] == null || levelLayout[0, i + 1, 0] == null)
                    {
                        Debug.LogError("Failed to find a way upwards for position X:" + x + " Y:" + i + " Z:" + z);
                    }
                }
            }
        }
    }
Esempio n. 11
0
    private void GenerateGoalTile(GameObject[,,] levelLayout, Vector3[,,] layoutPositions)
    {
        //int randomEnd = rnd.Next(endBlocks.Count());
        //GridLevelTile endPoint = endBlocks[randomEnd].GetComponentInChildren<GridLevelTile>();
        int x = sizeX - 1;
        int y = sizeY - 1;
        int z = sizeZ - 1;

        if (sizeY == 0)
        {
            //No roof for end point
            if (z % 2 == 0)
            {
                //Even row for end point
                GameObject[] randomGoalTiles = pathValidator.GetRandomSortedArray(goalTiles);
                foreach (GameObject goalTile in randomGoalTiles)
                {
                    GridLevelBlock goal = goalTile.GetComponentInChildren <GridLevelBlock>();
                    if (!goal.frontTopLeft && !goal.frontTop && !goal.frontTopRight &&
                        !goal.frontMidLeft && !goal.frontMid && !goal.frontMidRight &&
                        !goal.frontBottomLeft && !goal.frontBottom && !goal.frontBottomRight)
                    {
                        continue;
                    }
                    else
                    {
                        levelLayout[x, y, z]     = goalTile;
                        layoutPositions[x, y, z] = new Vector3(blockSize * x, blockSize * y, blockSize * z);
                    }
                }

                if (levelLayout[x, y, z] == null)
                {
                    Debug.LogError("Failed to find a valid goal tile");
                }
            }
            else
            {
                //Odd row for end point
                GameObject[] randomGoalTiles = pathValidator.GetRandomSortedArray(goalTiles);
                foreach (GameObject goalTile in randomGoalTiles)
                {
                    GridLevelBlock goal = goalTile.GetComponentInChildren <GridLevelBlock>();
                    if (!goal.backTopLeft && !goal.backTop && !goal.backTopRight &&
                        !goal.backMidLeft && !goal.backMid && !goal.backMidRight &&
                        !goal.backBottomLeft && !goal.backBottom && !goal.backBottomRight)
                    {
                        continue;
                    }
                    else
                    {
                        levelLayout[0, y, z]     = goalTile;
                        layoutPositions[0, y, z] = new Vector3(0, blockSize * y, blockSize * z);
                        break;
                    }
                }

                if (levelLayout[0, y, z] == null)
                {
                    Debug.LogError("Failed to find a valid goal tile");
                }
            }
        }
        else if (sizeY % 2 == 0)
        {
            //Even roof for end point
            GameObject[] randomGoalTiles = pathValidator.GetRandomSortedArray(goalTiles);
            foreach (GameObject goalTile in randomGoalTiles)
            {
                GridLevelBlock goal = goalTile.GetComponentInChildren <GridLevelBlock>();
                if (!goal.backTopLeft && !goal.backTop && !goal.backTopRight &&
                    !goal.backMidLeft && !goal.backMid && !goal.backMidRight &&
                    !goal.backBottomLeft && !goal.backBottom && !goal.backBottomRight)
                {
                    continue;
                }
                else
                {
                    levelLayout[0, y, 0]     = goalTile;
                    layoutPositions[0, y, 0] = new Vector3(0, blockSize * y, 0);
                    break;
                }
            }

            if (levelLayout[0, y, 0] == null)
            {
                Debug.LogError("Failed to find a valid goal tile");
            }
        }
        else
        {
            //Odd roof for end point
            if (z % 2 == 0)
            {
                //Even row for end point
                GameObject[] randomGoalTiles = pathValidator.GetRandomSortedArray(goalTiles);
                foreach (GameObject goalTile in randomGoalTiles)
                {
                    GridLevelBlock goal = goalTile.GetComponentInChildren <GridLevelBlock>();
                    if (!goal.frontTopLeft && !goal.frontTop && !goal.frontTopRight &&
                        !goal.frontMidLeft && !goal.frontMid && !goal.frontMidRight &&
                        !goal.frontBottomLeft && !goal.frontBottom && !goal.frontBottomRight)
                    {
                        continue;
                    }
                    else
                    {
                        levelLayout[x, y, z]     = goalTile;
                        layoutPositions[x, y, z] = new Vector3(blockSize * x, blockSize * y, blockSize * z);
                        break;
                    }
                }
            }
            else
            {
                //Odd row for end point
                GameObject[] randomGoalTiles = pathValidator.GetRandomSortedArray(goalTiles);
                foreach (GameObject goalTile in randomGoalTiles)
                {
                    GridLevelBlock goal = goalTile.GetComponentInChildren <GridLevelBlock>();
                    if (!goal.backTopLeft && !goal.backTop && !goal.backTopRight &&
                        !goal.backMidLeft && !goal.backMid && !goal.backMidRight &&
                        !goal.backBottomLeft && !goal.backBottom && !goal.backBottomRight)
                    {
                        GenerateGoalTile(levelLayout, layoutPositions);
                    }
                    else
                    {
                        levelLayout[0, y, z]     = goalTile;
                        layoutPositions[0, y, z] = new Vector3(0, blockSize * y, blockSize * z);
                    }
                }
            }
        }
    }
Esempio n. 12
0
 private void OnEnable()
 {
     levelBlock          = target as GridLevelBlock;
     soLevelBlock        = new SerializedObject(levelBlock);
     soSelectedLevelType = soLevelBlock.FindProperty("selectedLevelType");
     soSelectedBlockType = soLevelBlock.FindProperty("selectedBlockType");
     #region Front Face
     spFrontTopLeft     = soLevelBlock.FindProperty("frontTopLeft");
     spFrontTop         = soLevelBlock.FindProperty("frontTop");
     spFrontTopRight    = soLevelBlock.FindProperty("frontTopRight");
     spFrontMidLeft     = soLevelBlock.FindProperty("frontMidLeft");
     spFrontMid         = soLevelBlock.FindProperty("frontMid");
     spFrontMidRight    = soLevelBlock.FindProperty("frontMidRight");
     spFrontBottomLeft  = soLevelBlock.FindProperty("frontBottomLeft");
     spFrontBottom      = soLevelBlock.FindProperty("frontBottom");
     spFrontBottomRight = soLevelBlock.FindProperty("frontBottomRight");
     #endregion
     #region Back Face
     spBackTopLeft     = soLevelBlock.FindProperty("backTopLeft");
     spBackTop         = soLevelBlock.FindProperty("backTop");
     spBackTopRight    = soLevelBlock.FindProperty("backTopRight");
     spBackMidLeft     = soLevelBlock.FindProperty("backMidLeft");
     spBackMid         = soLevelBlock.FindProperty("backMid");
     spBackMidRight    = soLevelBlock.FindProperty("backMidRight");
     spBackBottomLeft  = soLevelBlock.FindProperty("backBottomLeft");
     spBackBottom      = soLevelBlock.FindProperty("backBottom");
     spBackBottomRight = soLevelBlock.FindProperty("backBottomRight");
     #endregion
     #region Left Face
     spLeftTopLeft     = soLevelBlock.FindProperty("leftTopLeft");
     spLeftTop         = soLevelBlock.FindProperty("leftTop");
     spLeftTopRight    = soLevelBlock.FindProperty("leftTopRight");
     spLeftMidLeft     = soLevelBlock.FindProperty("leftMidLeft");
     spLeftMid         = soLevelBlock.FindProperty("leftMid");
     spLeftMidRight    = soLevelBlock.FindProperty("leftMidRight");
     spLeftBottomLeft  = soLevelBlock.FindProperty("leftBottomLeft");
     spLeftBottom      = soLevelBlock.FindProperty("leftBottom");
     spLeftBottomRight = soLevelBlock.FindProperty("leftBottomRight");
     #endregion
     #region Right Face
     spRightTopLeft     = soLevelBlock.FindProperty("rightTopLeft");
     spRightTop         = soLevelBlock.FindProperty("rightTop");
     spRightTopRight    = soLevelBlock.FindProperty("rightTopRight");
     spRightMidLeft     = soLevelBlock.FindProperty("rightMidLeft");
     spRightMid         = soLevelBlock.FindProperty("rightMid");
     spRightMidRight    = soLevelBlock.FindProperty("rightMidRight");
     spRightBottomLeft  = soLevelBlock.FindProperty("rightBottomLeft");
     spRightBottom      = soLevelBlock.FindProperty("rightBottom");
     spRightBottomRight = soLevelBlock.FindProperty("rightBottomRight");
     #endregion
     #region Top Face
     spTopTopLeft     = soLevelBlock.FindProperty("topTopLeft");
     spTopTop         = soLevelBlock.FindProperty("topTop");
     spTopTopRight    = soLevelBlock.FindProperty("topTopRight");
     spTopMidLeft     = soLevelBlock.FindProperty("topMidLeft");
     spTopMid         = soLevelBlock.FindProperty("topMid");
     spTopMidRight    = soLevelBlock.FindProperty("topMidRight");
     spTopBottomLeft  = soLevelBlock.FindProperty("topBottomLeft");
     spTopBottom      = soLevelBlock.FindProperty("topBottom");
     spTopBottomRight = soLevelBlock.FindProperty("topBottomRight");
     #endregion
     #region Bottom Face
     spBottomTopLeft     = soLevelBlock.FindProperty("bottomTopLeft");
     spBottomTop         = soLevelBlock.FindProperty("bottomTop");
     spBottomTopRight    = soLevelBlock.FindProperty("bottomTopRight");
     spBottomMidLeft     = soLevelBlock.FindProperty("bottomMidLeft");
     spBottomMid         = soLevelBlock.FindProperty("bottomMid");
     spBottomMidRight    = soLevelBlock.FindProperty("bottomMidRight");
     spBottomBottomLeft  = soLevelBlock.FindProperty("bottomBottomLeft");
     spBottomBottom      = soLevelBlock.FindProperty("bottomBottom");
     spBottomBottomRight = soLevelBlock.FindProperty("bottomBottomRight");
     #endregion
 }