-
-
Save SetoKaiba/6accd474978e73490ee3990aa8cc8622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using Unity.Burst; | |
using Unity.Collections; | |
using Unity.Entities; | |
using Unity.Jobs; | |
using UnityEngine; | |
public class TestJobComponentSystem : JobComponentSystem | |
{ | |
//[BurstCompile] | |
struct TestJob : IJobChunk | |
{ | |
public ArchetypeChunkComponentType<TestComponentData> TestComponentDataType; | |
[ReadOnly] | |
public ArchetypeChunkSharedComponentType<TestSharedComponentData> TestSharedComponentDataType; | |
public ArchetypeChunkBufferType<TestDynamicBuffer> TestDynamicBufferType; | |
[ReadOnly] | |
public NativeHashMap<int, TestSharedComponentData> TSCDMap; | |
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) | |
{ | |
var chunkTestComponentData = chunk.GetNativeArray(TestComponentDataType); | |
var chunkTestDynamicBuffer = chunk.GetBufferAccessor(TestDynamicBufferType); | |
//var testSharedComponentData = chunk.GetSharedComponentData(TestSharedComponentDataType, World.Active.EntityManager); | |
var testSharedComponentDataIndex = chunk.GetSharedComponentIndex(TestSharedComponentDataType); | |
var testSharedComponentData = TSCDMap[testSharedComponentDataIndex]; | |
var instanceCount = chunk.Count; | |
var msg = "chunkIndex:" + chunkIndex + "\n"; | |
for (int i = 0; i < instanceCount; i++) | |
{ | |
var testComponentData = chunkTestComponentData[i]; | |
msg += "ComponentData:" + testComponentData.test + "\n"; | |
msg += "SharedComponentData:" + testSharedComponentData.test + "\n"; | |
var bufferCount = chunkTestDynamicBuffer[i].Length; | |
for (int j = 0; j < bufferCount; j++) | |
{ | |
msg += "DynamicBuffer:" + chunkTestDynamicBuffer[i][j].Value + "\n"; | |
} | |
} | |
//TSCDMap.Dispose(); | |
Debug.Log(msg); | |
} | |
} | |
ComponentGroup m_Group; | |
protected override void OnCreateManager() | |
{ | |
var query = new EntityArchetypeQuery | |
{ | |
All = new ComponentType[] { typeof(TestComponentData), typeof(TestDynamicBuffer), typeof(TestSharedComponentData) } | |
}; | |
m_Group = GetComponentGroup(query); | |
} | |
protected override JobHandle OnUpdate(JobHandle inputDeps) | |
{ | |
var testComponentDataType = GetArchetypeChunkComponentType<TestComponentData>(); | |
var testDynamicBufferType = GetArchetypeChunkBufferType<TestDynamicBuffer>(); | |
var testSharedComponentDataType = GetArchetypeChunkSharedComponentType<TestSharedComponentData>(); | |
var vList = new List<TestSharedComponentData>(); | |
var iList = new List<int>(); | |
EntityManager.GetAllUniqueSharedComponentData(vList, iList); | |
var TSCDMap = new NativeHashMap<int, TestSharedComponentData>(vList.Count, Allocator.TempJob); | |
for (var i = 0; i < vList.Count; i++) | |
{ | |
TSCDMap.TryAdd(iList[i], vList[i]); | |
} | |
var rotationsSpeedRotationJob = new TestJob | |
{ | |
TestComponentDataType = testComponentDataType, | |
TestDynamicBufferType = testDynamicBufferType, | |
TestSharedComponentDataType = testSharedComponentDataType, | |
TSCDMap = TSCDMap | |
}; | |
var jobHandle = rotationsSpeedRotationJob.Schedule(m_Group, inputDeps); | |
return jobHandle; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment