protected override void OnUpdate() { EntityQuery eq = GetEntityQuery(ComponentType.ReadOnly <ClickPoint>()); var ecb = ess.CreateCommandBuffer(); using (var clickPoints = eq.ToComponentDataArray <ClickPoint>(Allocator.TempJob)) { if (clickPoints.Length == 0) { return; } ClickPoint click = clickPoints[0]; int2 clickIndex = SpawnerMono.PositionToIndex(click.position); Entities.ForEach((Entity e, in JewelCell cell) => { if (cell.x == clickIndex.x && cell.y == clickIndex.y) { ecb.AddComponent(e, new JewelSelected()); } }).Run(); } }
protected override void OnUpdate() { var cb = createCommandBuffer(); Entities.WithoutBurst().ForEach((Entity e, in SpawnNeedComponent spawn) => { Entity jewelEntity = cb.Instantiate(JewelStaticPrefabs.heavy); float3 position = SpawnerMono.IndexToPosition(spawn.x, spawn.y); cb.AddComponent(jewelEntity, new Translation { Value = new float3(position.x, (5 + spawn.y) * (SpawnerMono.spacing + 1.2f), 0) }); cb.AddComponent(jewelEntity, new FallComponent { position = position, speed = 10 }); cb.AddComponent(jewelEntity, new JewelCell { x = spawn.x, y = spawn.y }); cb.DestroyEntity(e); }).Run(); //TODO: pass inputDeps to cb }
// i = x + width*y; // x = i % width; // y = i / width; protected override void OnUpdate() { var cb = createCommandBuffer(); EntityQuery eqCells = GetEntityQuery(ComponentType.ReadWrite <JewelCell>()); EntityQuery eqField = GetEntityQuery(ComponentType.ReadOnly <FieldComponent>()); FieldComponent fieldComponent = eqField.GetSingleton <FieldComponent>(); width = fieldComponent.width; height = fieldComponent.height; using (var cells = eqCells.ToEntityArray(Allocator.TempJob)) { NativeArray <Entity> cellsMatrix = new NativeArray <Entity>(fieldComponent.width * fieldComponent.height, Allocator.TempJob); //fill matrix foreach (var entity in cells) { JewelCell cell = EntityManager.GetComponentData <JewelCell>(entity); int index = GetIndex(cell.x, cell.y); cellsMatrix[index] = entity; } for (int x = 0; x < width; x++) { int emptyY = -1; for (int y = height - 1; y >= 0; y--) { int index = GetIndex(x, y); if (emptyY == -1 && cellsMatrix[index] == Entity.Null) { emptyY = y; } if (cellsMatrix[index] != Entity.Null && emptyY != -1) { Entity e = cellsMatrix[index]; JewelCell cell = EntityManager.GetComponentData <JewelCell>(e); cb.SetComponent(e, new JewelCell { x = cell.x, y = emptyY }); cb.AddComponent(e, new FallComponent { position = SpawnerMono.IndexToPosition(cell.x, emptyY), speed = 10 }); emptyY--; } } if (emptyY < height - 1 && emptyY != -1) { for (int sy = emptyY; sy >= 0; sy--) { Debug.Log($"SPAWN FOR: {x},{sy}"); var entity = cb.CreateEntity(); cb.AddComponent(entity, new SpawnNeedComponent { x = x, y = sy }); } } } cellsMatrix.Dispose(); } }