Protfolio-Emanuel-Polsky / Assets / _Project / Code / PathFinding / Debug / DebugPathCalculationSystem.cs
DebugPathCalculationSystem.cs
Raw
#if UNITY_EDITOR
using Unity.Burst;
using Unity.Entities;


namespace GarmentButton.PathFinding
{
    public partial struct DebugPathCalculationSystem : ISystem
    {

        [BurstCompile]
        public void OnCreate(ref SystemState state)
        {
            var query = SystemAPI.QueryBuilder().WithAll<Grid, DebugTextMesh>().Build();
            state.RequireForUpdate<PointsData>();
            state.RequireForUpdate<DebugAll>();
            state.RequireForUpdate(query);
        }




        public void OnUpdate(ref SystemState state)
        {
            var grid = SystemAPI.GetSingleton<Grid>().Value;
            var pointData = SystemAPI.GetSingletonBuffer<PointsData>();
            var entityPathFinder = SystemAPI.GetSingletonEntity<DebugAll>();
            var entity = SystemAPI.GetSingletonEntity<Grid>();
            var texts = state.EntityManager.GetComponentData<DebugTextMesh>(entity);
            state.Dependency.Complete();

            for (int i = 0; i < grid.Value.Array.Length; i++)
            {
                var text = texts.Text[i];
                text.text = $"{pointData[i].Cost}";

            }
            state.EntityManager.RemoveComponent<DebugAll>(entityPathFinder);
        }
    }
}
#endif