void CreateGridEntities() { var gridSize = _gridUtils.GetSize(); var gridInitializer = _entityFactory.BuildEntity <GridEntityDescriptor>(0, GridGroups.Grid); var walkableGrid = NativeDynamicArray.Alloc <bool>(Allocator.Persistent, gridSize.x * gridSize.y); for (uint x = 0; x < gridSize.x; x++) { for (uint y = 0; y < gridSize.y; y++) { var cellPosition = new uint2(x, y); var cellIndex = _gridUtils.CellToEntityId(cellPosition); var isLand = _gridLand.IsLand(cellPosition); // note: it is probable that we don't need to create the land cells at all, // unless there is some gameplay feature that needs them. var initializer = _entityFactory.BuildEntity <GridCellEntityDescriptor>( cellIndex, isLand ? GridGroups.GridLandGroup : GridGroups.GridWaterGroup ); initializer.Init(new GridCellComponent { Position = cellPosition, WorldCenter = _gridUtils.CellToCenterPosition(cellPosition) }); walkableGrid.Set(cellIndex, !isLand); } } gridInitializer.Init(new GridComponent { WalkableGrid = walkableGrid }); }