Exemplo n.º 1
0
    public static void RecordEntityTrace(EntityManager entityManager, EntityManagerTrace trace)
    {
        int chunkI = 0;

        trace.GlobalSystemVersion = entityManager.GlobalSystemVersion;

        using (NativeArray <ArchetypeChunk> chunks = entityManager.GetAllChunks(Allocator.TempJob)) // needs to be temp job to preven unity error :(
        {
            for (int i = 0; i < chunks.Length; i++)
            {
                ArchetypeChunk chunk = chunks[i];

                while (chunkI >= trace.Chunks.Count)
                {
                    trace.Chunks.Add(s_chunkTracePool.Count > 0 ? s_chunkTracePool.Dequeue() : new ChunkTrace());
                }

                ChunkTrace chunkTrace = trace.Chunks[chunkI++];

                chunkTrace.OrderVersion = chunk.GetOrderVersion();
                chunkTrace.EntityCount  = chunk.ChunkEntityCount;
                chunkTrace.ComponentTraces.Clear();

                foreach (ComponentType componentType in chunk.Archetype.GetComponentTypes(Allocator.Temp))
                {
                    chunkTrace.ComponentTraces.Add(new ComponentTrace()
                    {
                        ComponentType = componentType,
                        Version       = chunk.GetComponentVersion(componentType)
                    });
                }
            }
        }

        int toRemove = trace.Chunks.Count - chunkI;

        for (int i = 0; i < toRemove; i++)
        {
            s_chunkTracePool.Enqueue(trace.Chunks.Pop());
        }
    }