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 HexagonBlock(Vector2Int gridPos, Vector3 worldPosition, HexagonViewTempInfo viewInfo)
 {
     gridPosition      = gridPos;
     position          = worldPosition;
     blockSpritecomp   = viewInfo.blockSprite;
     blockHighlightref = viewInfo.highlightSprite;
     isFilled          = false;
     n1                      = -1;
     n2                      = -1;
     blockTypeIndex          = -1;//Not safe
     blockHighlightref.color = selectionColor = Color.clear;
 }