Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public struct Block
- {
- // only value types
- }
- public struct WorldData
- {
- public NativeHashMap<int, NativeArray<Block>> ChunkBlocks;
- //ctor with initialization
- }
- public struct GenerateBlocksForChunksJob : IJobParallelFor
- {
- public NativeArray<int> ChunkPositions;
- public NativeHashMap<int, NativeArray<byte>> ChunksBlocksList;
- public void Execute(int index)
- {
- var temp = new byte[Constants.ChunkSize * Constants.ChunkSize * Constants.ChunkSize];
- Vector3Int firstBlockPosition = ChunkPositions[index].ToBlockPosition();
- for (int i = 0; x < temp.Length; i++)
- {
- temp[i] = MagicFunctionToGenerateBlock(i, firstblockPosition);
- }
- ChunksBlocksList[index].CopyFrom(temp);
- }
- }
- public class World : MonoBehaviour
- {
- public Start()
- {
- // computing NativeArray<int> ChunkPositions
- var generateBlocksForChunksJob = new GenerateBlocksForChunksJob()
- {
- ChunksBlocksList = _worldData.ChunkBlocks,
- ChunkPositions = chunkPositions
- };
- // ArgumentException: Unity.Collections.NativeArray`1[System.Byte] used in native collection is not blittable, not primitive, or contains a type tagged as NativeContainer
- generateBlocksForChunksJob
- .Schedule(chunkPositions.Length, 1)
- .Complete();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement