Created
August 21, 2020 23:52
-
-
Save jeffvella/16033b6182ee7758ccf609b67f3f6ea0 to your computer and use it in GitHub Desktop.
DynamicBufferTestSystem
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
public class DynamicBufferTestSystem : SystemBase | |
{ | |
private EntityQuery _query; | |
private Entity _entity; | |
protected override void OnCreate() | |
{ | |
_query = GetEntityQuery(ComponentType.ReadWrite<MyBufferData>()); | |
_entity = EntityManager.CreateEntity(ComponentType.ReadWrite<MyBufferData>()); | |
EntityManager.GetBuffer<MyBufferData>(_entity).Add(default); | |
} | |
protected override void OnUpdate() | |
{ | |
Debug.Log($"{EntityManager.GetBuffer<MyBufferData>(_entity)[0].Value}"); | |
Dependency = new ChunkJob | |
{ | |
MyBufferDataType = GetArchetypeChunkBufferType<MyBufferData>(), | |
}.Schedule(_query); | |
} | |
public struct MyBufferData : IBufferElementData | |
{ | |
public int Value; | |
} | |
public struct ChunkJob : IJobChunk | |
{ | |
public ArchetypeChunkBufferType<MyBufferData> MyBufferDataType; | |
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex) | |
{ | |
var bufferAccessor = chunk.GetBufferAccessor(MyBufferDataType); | |
for (int i = 0; i < bufferAccessor.Length; i++) | |
{ | |
var buffer = bufferAccessor[i]; | |
for (int j = 0; j < buffer.Length; j++) | |
{ | |
var element = buffer[j]; | |
element.Value += 1; | |
buffer[j] = element; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment