Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 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.                     if (true) // Check distances or other things
  44.                     {
  45.                         // Logic like cmndbuffer etc
  46.                     }
  47.                 }
  48.             }
  49.         }
  50.     }
  51.    
  52.     protected override JobHandle OnUpdate(JobHandle inputDeps)
  53.     {
  54.         var chunk  = m_characterGroup.CreateArchetypeChunkArray(Allocator.Temp);
  55.  
  56.         var testJob = new TestJob()
  57.         {
  58.             charactersChunks = chunk,
  59.             spatialDataChunkType = GetArchetypeChunkComponentType<SpatialData>()
  60.         };
  61.        
  62.        
  63.         return testJob.Schedule(m_consoleGroup);
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement