using Unity.Burst; using Unity.Collections; using Unity.Entities; namespace GarmentButton.PathFinding { [BurstCompile] public partial struct CreationGridPathfindingSystem : ISystem { [BurstCompile] public void OnCreate(ref SystemState state) { var query = SystemAPI.QueryBuilder().WithAll().WithNone().Build(); state.RequireForUpdate(query); } public void OnDestroy(ref SystemState state) { if (!SystemAPI.TryGetSingletonRW(out var data)) return; data.ValueRW.Types.Dispose(); } [BurstCompile] public void OnUpdate(ref SystemState state) { var entity = SystemAPI.GetSingletonEntity(); var grid = SystemAPI.GetComponentRO(entity); var lenght = grid.ValueRO.Value.Value.Array.Length; var additionData = new NativeArray(lenght, Allocator.Persistent); state.EntityManager.AddComponentData(entity, new GridAdditionalData { Types = additionData, }); var updatePoints = new NativeArray(lenght, Allocator.Persistent); for (var i = 0; i < updatePoints.Length; i++) updatePoints[i] = (ushort)i; state.EntityManager.AddComponentData(entity, new UpdatePoints { Indexes = updatePoints, }); state.EntityManager.AddComponent(entity); } } }