Пример #1
0
    private void SpawnHexes(int rows, int cols, float radius = 1f, float height = 1f, float minHeight = 1f, float maxHeight = 1f)
    {
        if (hexes.Count > 0)
        {
            ClearHexes();
        }

        for (int row = 0; row < rows; row++)
        {
            hexes.Add(new List <Hex>());
            for (int col = 0; col < cols; col++)
            {
                if (cols % 2 != 0 && col == cols - 1 && row % 2 == 0)
                {
                    continue;
                }

                GameObject newGo = Instantiate(
                    original: hexPrefab,
                    position: new Vector3(
                        x: radius * 3 * col + Get_X_Offset(row, radius),
                        y: UnityEngine.Random.Range(minHeight, maxHeight),
                        z: row * Apothem(radius)
                        ),
                    rotation: Quaternion.identity,
                    parent: transform
                    );

                Hex newHex = newGo.GetComponent <Hex>();

                newHex.transform.localScale = new Vector3(
                    x: newHex.transform.localScale.x * radius,
                    y: newHex.transform.localScale.y * height,
                    z: newHex.transform.localScale.z * radius
                    );

                newHex.AssignIndex(new Index(row, col));
                newHex.SetOutlineColor(outlineColor);
                newHex.ToggleSelect();
                newHex.SetOutlineThickness(0.01f);

                hexes[row].Add(newHex);
                newHex.SetColor(color);
            }
        }
    }
Пример #2
0
    private void SpawnHexes()
    {
        if (hexes.Count > 0)
        {
            ClearHexes();
        }

        for (int row = 0; row < hexGrid.rows; row++)
        {
            hexes.Add(new List <Hex>());
            for (int col = 0; col < hexGrid.cols; col++)
            {
                Hex newHex = Instantiate(
                    original: hexPrefab,
                    position: new Vector3(
                        x: hexGrid.radius * 3 * col + Get_X_Offset(row),
                        y: UnityEngine.Random.Range(hexGrid.minHeight, hexGrid.maxHeight),
                        z: row * hexGrid.Apothem
                        ),
                    rotation: Quaternion.identity,
                    parent: transform
                    );

                newHex.transform.localScale = new Vector3(
                    x: newHex.transform.localScale.x * hexGrid.radius,
                    y: newHex.transform.localScale.y * hexGrid.height,
                    z: newHex.transform.localScale.z * hexGrid.radius
                    );

                newHex.AssignIndex(new Index(row, col));
                hexes[row].Add(newHex);

                RandomizeHexColor(newHex.GetComponent <MeshRenderer>());
            }
        }
    }