Beispiel #1
0
    private void Start()
    {
        _terrain = new Terrain((width, height));
        InitializeRenderCells(_terrain);

        _selectedCells = new List <Guid>();
    }
Beispiel #2
0
    private void InitializeRenderCells(Terrain terrain)
    {
        _renderedCells = new GameObject[terrain.Cells.Length];
        for (int y = 0; y < terrain.Cells.GetLength(1); y++)
        {
            for (int x = 0; x < terrain.Cells.GetLength(0); x++)
            {
                // Create Vector3 from cell
                Vector3 position = new Vector3(x, terrain.Cells[x, y].GetCellHeight(), y);

                // Create the cell Gameobject
                GameObject trCell = GameObject.Instantiate(cellPrefab, position, Quaternion.identity, transform);
                trCell.GetComponent <TRCell>().Initialize(terrain.Cells[x, y], topMaterial, sideMaterial);

                _renderedCells[x + terrain.Cells.GetLength(0) * y] = trCell;
                terrain.Cells[x, y].OnHeightChanged += OnHeightChanged;
            }
        }
    }