Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Unity.Collections;
- using Unity.Entities;
- using Unity.Jobs;
- public struct SpatialDataShared : ISharedComponentData
- {
- public int Value;
- }
- public struct SpatialData : IComponentData
- {
- public int Value;
- }
- public class TempConsoleSystem : JobComponentSystem
- {
- private EntityQuery m_characterGroup;
- private EntityQuery m_consoleGroup;
- protected override void OnCreate()
- {
- base.OnCreate();
- m_characterGroup = GetEntityQuery(ComponentType.ReadOnly<SpatialDataShared>(), ComponentType.ReadOnly<SpatialData>()); // more character indicators
- m_consoleGroup = GetEntityQuery(ComponentType.ReadOnly<SpatialDataShared>(), ComponentType.ReadOnly<SpatialData>()); // More console indicators
- }
- struct TestJob : IJobChunk
- {
- [DeallocateOnJobCompletion]
- public NativeArray<ArchetypeChunk> charactersChunks;
- public ArchetypeChunkComponentType<SpatialData> spatialDataChunkType;
- public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
- {
- var consoleSpatialChunk = chunk.GetNativeArray(spatialDataChunkType);
- for (int k = 0; k < charactersChunks.Length; k++)
- {
- var characterSpatialChunk = chunk.GetNativeArray(spatialDataChunkType);
- if (consoleSpatialChunk[0].Value == characterSpatialChunk[0].Value)
- {
- if (true) // Check distances or other things
- {
- // Logic like cmndbuffer etc
- }
- }
- }
- }
- }
- protected override JobHandle OnUpdate(JobHandle inputDeps)
- {
- var chunk = m_characterGroup.CreateArchetypeChunkArray(Allocator.Temp);
- var testJob = new TestJob()
- {
- charactersChunks = chunk,
- spatialDataChunkType = GetArchetypeChunkComponentType<SpatialData>()
- };
- return testJob.Schedule(m_consoleGroup);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement