Im trying to learn ECS and Jobs. So far so good. Ive been able to get a simple Icosahedron build into ECS using ComponentSystem, JobComponentSystem and now trying IJobs. But im confused on how to access my entities without GetEntityQuery and Entities.With(_query).ForEach inside my Execute(). Please help and thank you in advance.
/// <summary>
/// Start this instance.
/// </summary>
protected void Start()
{
//
// Gee ref to EntityManager
_entityManager = World.Active.EntityManager;
//
// Define Archetype
tileArchetype = _entityManager.CreateArchetype( typeof(VertexComponent),
typeof(VertexTrianglesComponent),
typeof(VertexSubdivisionComponent));
//
// Create Entities
NativeArray<Entity> entityArray = new NativeArray<Entity>(12, Allocator.Temp);
_entityManager.CreateEntity(tileArchetype, entityArray);
//
// Create and Schedule Job
BuildIcosahedronJob job = new BuildIcosahedronJob()
{
icosahedronPosBuffer = new NativeArray<float3>(icosahedronPosData, Allocator.TempJob)
};
_jobHandle = job.Schedule();
}
/// <summary>
/// Lates the update.
/// </summary>
public void LateUpdate()
{
_jobHandle.Complete();
}
/// <summary>
/// Ons the destroy.
/// </summary>
private void OnDestroy()
{
icosahedronPosBuffer.Dispose();
}
#region JOBS -----------------------------------------------------------
[BurstCompile]
struct BuildIcosahedronJob : IJob
{
[DeallocateOnJobCompletion]
public NativeArray<float3> icosahedronPosBuffer;
public void Execute()
{
// TODO : Loop Over Entities !! But How ??
//v.position = icosahedronPos[index];
//v.index = index;
//t.connectedTriA = -1;
//t.connectedTriB = -1;
//t.connectedTriC = -1;
//t.connectedTriD = -1;
//t.connectedTriE = -1;
//t.connectedTriF = -1;
//s.divisionLevel = 0;
}
}
#endregion