Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using Unity.Entities;
using Unity.Transforms;
public class DrawLineSystem : ComponentSystem {
private ComponentGroup group;
protected override void OnCreateManager()
{
group = GetComponentGroup(ComponentType.ReadOnly<EntityBuffer>());
}
protected override void OnUpdate()
{
BufferArray<EntityBuffer> entityBuffer = group.GetBufferArray<EntityBuffer>();
EntityArray entities = group.GetEntityArray();
for(int entityIndex=0; entityIndex<entities.Length; entityIndex++)
{
DrawLine(entities[entityIndex], entityBuffer[entityIndex].Reinterpret<Entity>());
}
}
void DrawLine(Entity entity, DynamicBuffer<Entity> buffer)
{
Position entityOwnerPos = EntityManager.GetComponentData<Position>(entity);
for (int i = 0; i < buffer.Length; i++)
{
Position targetPos = EntityManager.GetComponentData<Position>(buffer[i]);
Debug.DrawLine(entityOwnerPos.Value, targetPos.Value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment