Beispiel #1
0
        private void RegeneratePlant(GridData grid, NativeArray <bool> occupiedCells, NativeArray <bool> waterCells,
                                     bool landBased, bool waterBased, GameObject plant)
        {
            bool lookingForFreeTile = true;
            int  searchTries        = 0;

            while (lookingForFreeTile)
            {
                if (searchTries > Mathf.Sqrt(grid.Length))
                {
                    break;
                }
                searchTries += 1;

                int n = Random.Range(0, grid.Length);

                if ((waterCells[n] && !waterBased) ||
                    (!waterCells[n] && !landBased))
                {
                    continue;
                }
                if (occupiedCells[n])
                {
                    continue;
                }

                int2    gridPos  = grid.GetGridPositionFromIndex(n);
                Vector3 spawnPos = grid.GetWorldPosition(gridPos);
                spawnPos.y = 0f;

                Instantiate(plant, spawnPos, Quaternion.Euler(0, Random.Range(0, 360), 0));
                worldGridSystem.SetOccupiedCell(gridPos);

                lookingForFreeTile = false;
            }
        }
Beispiel #2
0
 public void SetBlockedCell(int x, int y)
 => worldGridSystem.SetOccupiedCell(new int2(x, y), true);