Advertisement
Sajgoniarz

Damn You Unity!

Sep 9th, 2020
1,169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. public struct Block
  2. {
  3.     // only value types
  4. }
  5.  
  6. public struct WorldData
  7. {
  8.     public NativeHashMap<int, NativeArray<Block>> ChunkBlocks;
  9.    
  10.     //ctor with initialization
  11. }
  12.  
  13. public struct GenerateBlocksForChunksJob : IJobParallelFor
  14. {
  15.     public NativeArray<int> ChunkPositions;
  16.  
  17.     public NativeHashMap<int, NativeArray<byte>> ChunksBlocksList;
  18.  
  19.     public void Execute(int index)
  20.     {
  21.         var temp = new byte[Constants.ChunkSize * Constants.ChunkSize * Constants.ChunkSize];
  22.         Vector3Int firstBlockPosition = ChunkPositions[index].ToBlockPosition();
  23.  
  24.         for (int i = 0; x < temp.Length; i++)
  25.         {
  26.             temp[i] = MagicFunctionToGenerateBlock(i, firstblockPosition);
  27.         }
  28.  
  29.         ChunksBlocksList[index].CopyFrom(temp);
  30.     }
  31. }
  32.  
  33.  
  34. public class World : MonoBehaviour
  35. {
  36.     public Start()
  37.     {
  38.     // computing NativeArray<int> ChunkPositions
  39.  
  40.     var generateBlocksForChunksJob = new GenerateBlocksForChunksJob()
  41.         {
  42.             ChunksBlocksList = _worldData.ChunkBlocks,
  43.             ChunkPositions = chunkPositions
  44.         };
  45.  
  46.     // ArgumentException: Unity.Collections.NativeArray`1[System.Byte] used in native collection is not blittable, not primitive, or contains a type tagged as NativeContainer
  47.         generateBlocksForChunksJob
  48.             .Schedule(chunkPositions.Length, 1)
  49.             .Complete();
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement