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


namespace GarmentButton.PathFinding
{
    [BurstCompile]
    public partial struct DebugPathSystem : ISystem
    {

        [BurstCompile]
        public void OnCreate(ref SystemState state)
        {
            state.RequireForUpdate<Grid>();
            state.RequireForUpdate<PathElement>();
            state.RequireForUpdate<DebugPath>();
        }
        public void OnUpdate(ref SystemState state)
        {
            var grid = SystemAPI.GetSingleton<Grid>();
            var debug = new DebugBox();
            foreach (var pathElement in SystemAPI.Query<DynamicBuffer<PathElement>>())
            {
                float3 currentPosition = float3.zero;
                foreach (var element in pathElement)
                {
                    var point = grid.Value.Value.Array[element.IndexGrid];
                    var newPosition = new float3(point.X, point.Y, point.Z) / 10;
                    debug.Draw(newPosition, 0.6f, Color.red);
                    if (!currentPosition.Equals(float3.zero))
                    {
                        Debug.DrawLine(currentPosition + new float3(0, 0.5f, 0), newPosition + new float3(0, 0.5f, 0), Color.yellow);
                    }
                    currentPosition = newPosition;
                }
            }
        }
    }
}
#endif