Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using Unity.Collections;
  2. using Unity.Entities;
  3. using Unity.Jobs;
  4.  
  5. public struct SpatialDataShared : ISharedComponentData
  6. {
  7.     public int Value;
  8. }
  9. public struct SpatialData : IComponentData
  10. {
  11.     public int Value;
  12. }
  13.  
  14. public class TempConsoleSystem : JobComponentSystem
  15. {
  16.     private EntityQuery m_characterGroup;
  17.     private EntityQuery m_consoleGroup;
  18.  
  19.     protected override void OnCreate()
  20.     {
  21.         base.OnCreate();
  22.         m_characterGroup = GetEntityQuery(ComponentType.ReadOnly<SpatialDataShared>(), ComponentType.ReadOnly<SpatialData>()); // more character indicators
  23.         m_consoleGroup = GetEntityQuery(ComponentType.ReadOnly<SpatialDataShared>(), ComponentType.ReadOnly<SpatialData>()); // More console indicators
  24.     }
  25.  
  26.     struct TestJob : IJobChunk
  27.     {
  28.         [DeallocateOnJobCompletion]
  29.         public NativeArray<ArchetypeChunk> charactersChunks;
  30.  
  31.         public ArchetypeChunkComponentType<SpatialData> spatialDataChunkType;
  32.        
  33.         public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
  34.         {
  35.             var consoleSpatialChunk = chunk.GetNativeArray(spatialDataChunkType);
  36.            
  37.             for (int k = 0; k < charactersChunks.Length; k++)
  38.             {
  39.                 var characterSpatialChunk = chunk.GetNativeArray(spatialDataChunkType);
  40.  
  41.                 if (consoleSpatialChunk[0].Value == characterSpatialChunk[0].Value)
  42.                 {
  43.                     for (int i = 0; i < consoleSpatialChunk.Length; i++)
  44.                     {
  45.                         for (int j = 0; j < characterSpatialChunk.Length; j++)
  46.                         {
  47.                             if (true) // Check distances or other things
  48.                             {
  49.                                 // Logic like cmndbuffer etc
  50.                             }
  51.                         }
  52.                     }
  53.                 }
  54.             }
  55.         }
  56.     }
  57.    
  58.     protected override JobHandle OnUpdate(JobHandle inputDeps)
  59.     {
  60.         var chunk  = m_characterGroup.CreateArchetypeChunkArray(Allocator.Temp);
  61.  
  62.         var testJob = new TestJob()
  63.         {
  64.             charactersChunks = chunk,
  65.             spatialDataChunkType = GetArchetypeChunkComponentType<SpatialData>()
  66.         };
  67.        
  68.        
  69.         return testJob.Schedule(m_consoleGroup);
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement