Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created November 7, 2018 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/97f908be6330b027a747269cc6ee8979 to your computer and use it in GitHub Desktop.
Save tsubaki/97f908be6330b027a747269cc6ee8979 to your computer and use it in GitHub Desktop.
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