//Просто спавнить непрерывно энтити по префабу /*protected override JobHandle OnUpdate(JobHandle inputDeps) * { * var SpawnerJob = new SpawnerJob( * endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(), * new unityMath.Random((uint)UnityEngine.Random.Range(0,int.MaxValue)) * ); * * JobHandle jobHandle = SpawnerJob.Schedule(this, inputDeps); * * endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle); * * return jobHandle; * }*/ //Спавнить энтити по префабу, когда список объектов с DeleteTag не пустой (всратый, но рабочий пока что костыль, нужно переписывать!) protected override JobHandle OnUpdate(JobHandle inputDeps) { bool trigger = false; var jobHandle = new JobHandle(); Entities .WithAll <DeleteTag>() .WithoutBurst() .ForEach((Entity entity) => { var SpawnerJob = new SpawnerJob( endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(), new unityMath.Random((uint)UnityEngine.Random.Range(0, int.MaxValue))); jobHandle = SpawnerJob.Schedule(this, inputDeps); endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle); trigger = true; }).Run(); if (trigger) { return(jobHandle); } else { return(default);
//Run the SpawnerJob protected override JobHandle OnUpdate(JobHandle inputDeps) { var spawner_job = new SpawnerJob(endSimulationEntityCommand.CreateCommandBuffer().ToConcurrent(), new Random((uint)UnityEngine.Random.Range(0, int.MaxValue)), Time.DeltaTime); JobHandle job_handle = spawner_job.Schedule(this, inputDeps); endSimulationEntityCommand.AddJobHandleForProducer(job_handle); return job_handle; }
/// <summary> /// This is where you would create the jobs themselves and schedule them. The job then takes commands and adds them to the command buffer, which will be executed on various threads /// </summary> /// <param name="inputDeps"></param> /// <returns></returns> protected override JobHandle OnUpdate(JobHandle inputDeps) { ///create the job that needs to be scheduled var job = new SpawnerJob { CommandBuffer = EntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent() }.Schedule(this, inputDeps); EntityCommandBufferSystem.AddJobHandleForProducer(job); return(job); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { sinceLastUpdate += Time.DeltaTime; if (sinceLastUpdate < updateEvery) { return(inputDeps); } sinceLastUpdate = 0; SpawnerJob job = new SpawnerJob { CommandBuffer = commandBufferSystem.CreateCommandBuffer().ToConcurrent(), random = new Random((uint)UnityEngine.Random.Range(1, 100000)), prefabs = GetSingleton <PrefabContainer>(), blinks = GetComponentDataFromEntity <BlinkMovement>(true) }; JobHandle handle = job.Schedule(this, inputDeps); commandBufferSystem.AddJobHandleForProducer(handle); return(handle); }
// Create the ScoreBox entities and assign the corresponding components private void AddScoreBoxes() { // Create Entity Command Buffer for parallel writing var commandBuffer = CommandBufferSystem.CreateCommandBuffer().AsParallelWriter(); NativeArray <Entity> entities = new NativeArray <Entity>(EntityCount, Allocator.TempJob); // Convert our ScoreBox GameObject Prefab into an Entity prefab Entity prefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(EntityPrefab, Settings); Manager.Instantiate(prefab, entities); spawned += entities.Length; // Generate Random with default seed var generator = new Unity.Mathematics.Random((uint)System.DateTime.Now.ToBinary()); // Create the SpawnerJob to randomly spawn ScoreBox entities var spawnerJob = new SpawnerJob() { CommandBuffer = commandBuffer, Entities = entities, Generator = generator, spawnRadius = SpawnRadius, RSpeed = RotationSpeed, spawnCenter = SpawnCenter }; // Schedule the job to run in parallel JobHandle spawnerJobHandle = new JobHandle(); JobHandle sheduleParralelJobHandle = spawnerJob.ScheduleParallel(entities.Length, 64, spawnerJobHandle); // Ensure the job is completed sheduleParralelJobHandle.Complete(); entities.Dispose(); }