public HexagonGridGenerator(DataSO.LevelDataSO levelData, ref HexagonBlock[] hexagonBlocks, ref Bounds gridBounds)
        {
            gridBounds    = new Bounds(Vector3.zero, Vector3.zero);
            hexagonBlocks = new HexagonBlock[levelData.gridDimentions.x * levelData.gridDimentions.y];
            GameObject hexblockPrefab      = levelData.hexagonPrefab;
            GameObject gridsContainer      = new GameObject("GridContainer");
            Vector3    newRow              = Vector3.zero;// gridStartposition;
            Vector3    position            = newRow;
            int        generationDirection = (int)GenerationDirection.Top2Botton;

            for (int row = 0; row < levelData.gridDimentions.x; row++)
            {
                position = newRow;
                for (int column = 0; column < levelData.gridDimentions.y; column++)
                {
                    position = GetEdge(position, 0, levelData.uniformBlockscale, HexCalculation.Edge);
                    GameObject block = Object.Instantiate(hexblockPrefab, position, Quaternion.identity, gridsContainer.transform);
                    block.transform.localScale = Vector3.one * levelData.uniformBlockscale;
                    string debugString = "(" + row + "," + column + ")";
                    block.name = debugString;
                    int index = GetIndex(row, column, levelData.gridDimentions.x);

                    HexagonViewTempInfo viewinfo     = block.GetComponent <HexagonViewTempInfo>().GetInfo(ref gridBounds, debugString);
                    HexagonBlock        hexagonBlock = new HexagonBlock(new Vector2Int(row, column), block.transform.position, viewinfo);

                    hexagonBlocks[index] = hexagonBlock;
                }

                float angleDeg = row % 2 == 0 ? 120.0f : 60.0f;// 60 + 60 * row % 2;//ToDo:This can be randomized
                newRow = GetEdge(newRow, angleDeg * generationDirection, levelData.uniformBlockscale, HexCalculation.Edge);
            }

            SetUpNeighbours(ref hexagonBlocks, levelData.gridDimentions);
            gridsContainer.AddComponent <OptimizationSystem.CombineMesh>();
        }
示例#2
0
 public bool IsBlockSame(ref HexagonBlock block)
 {
     return(block.blockSpritecomp.sprite == blockSpritecomp.sprite);
 }
示例#3
0
 public void SetBlock(BlockType[] blockTypes, ref HexagonBlock block)
 {
     SetBlock(blockTypes[block.BlockTypeIndex], block.BlockTypeIndex);
     block.SetBlock(null, -1);
     blockSpritecomp.transform.position = block.GetWorldPosition;
 }