Created
November 7, 2018 14:43
-
-
Save tsubaki/97f908be6330b027a747269cc6ee8979 to your computer and use it in GitHub Desktop.
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
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