Esempio n. 1
0
    CellStack CreateCellStack(int x, int z, int height)
    {
        CellStack      cellStack        = ScriptableObject.CreateInstance <CellStack>();
        HexCoordinates coords           = HexCoordinates.FromOffsetCoordinates(x + (int)offsetOrigin.x, z + (int)offsetOrigin.y);
        Vector2Int     indexWithinChunk = new Vector2Int(x % size, z % size);

        cellStack.Init(coords, indexWithinChunk);
        cellStack.Push(CellType.Bedrock);

        int numStoneTiles = (int)(height * terrain.stoneHeightPercentage);

        // Generate terrian based on stack height
        for (int i = 0; i < height; i++)
        {
            CellType newCell;

            if (height >= terrain.waterLevel - 1 && i == height - 1)
            {
                newCell = CellType.Grass;
            }
            else if (i < numStoneTiles)
            {
                newCell = CellType.Stone;
            }
            else
            {
                newCell = CellType.Dirt;
            }

            cellStack.Push(newCell);
        }

        if (showCoordinates && gridCanvas != null)
        {
            Vector3 position = cellStack.coordinates.ToChunkPosition();
            position += HexMetrics.heightVector * (cellStack.Count() + 1);

            Text label = Instantiate <Text>(terrain.cellLabelPrefab);
            label.rectTransform.SetParent(gridCanvas.transform, false);
            label.rectTransform.anchoredPosition3D = new Vector3(position.x, position.z, -position.y);
            label.text = cellStack.coordinates.ToStringOnSeparateLines();
        }

        return(cellStack);
    }