Пример #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (m_Prefab == Entity.Null)
            {
                var prefabs       = GetSingleton <GhostPrefabCollectionComponent>();
                var serverPrefabs = EntityManager.GetBuffer <GhostPrefabBuffer>(prefabs.serverPrefabs);
                m_Prefab = serverPrefabs[AsteroidsGhostSerializerCollection.FindGhostType <ShipSnapshotData>()].Value;
                m_Radius = EntityManager.GetComponentData <CollisionSphereComponent>(m_Prefab).radius;
            }

            JobHandle levelHandle;
            var       spawnJob = new SpawnJob
            {
                commandBuffer           = barrier.CreateCommandBuffer(),
                playerStateFromEntity   = GetComponentDataFromEntity <PlayerStateComponentData>(),
                commandTargetFromEntity = GetComponentDataFromEntity <CommandTargetComponent>(),
                networkIdFromEntity     = GetComponentDataFromEntity <NetworkIdComponent>(),
                shipPrefab = m_Prefab,
                shipRadius = m_Radius,
                level      = m_LevelGroup.ToComponentDataArray <LevelComponent>(Allocator.TempJob, out levelHandle),
                rand       = new Unity.Mathematics.Random((uint)Stopwatch.GetTimestamp())
            };
            var handle = spawnJob.ScheduleSingle(this, JobHandle.CombineDependencies(inputDeps, levelHandle));

            barrier.AddJobHandleForProducer(handle);
            return(handle);
        }
Пример #2
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var heroTranslation = World.EntityManager.GetComponentData <Translation>(this.heroEntity);

        var carCatalogueParent = this.GetSingletonEntity <StreetCarPrefabsBuffer>();
        var streetCarModels    = this.EntityManager.GetBuffer <LinkedEntityGroup>(carCatalogueParent);
        var carDataFromEntity  = GetComponentDataFromEntity <CarComponent>();

        SpawnJob spwanJob = new SpawnJob
        {
            Time = Time.ElapsedTime,
            TimeBetweenBatches      = 0.7f,
            RandomObject            = DateTime.Now.Ticks,
            NumberOfGenerationSlots = Settings.NumberOfGenerationSlots,
            HeroZ               = heroTranslation.Value.z,
            CarModels           = streetCarModels,
            EntityCommandBuffer = entityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(),
            CarDataFromEntity   = carDataFromEntity,
            //ActiveCars = activeCars,
            SpawningDistance = Settings.SpawningDistanceAheadOfHero,
            MaxSpeed         = Settings.StreetCarMaxSpawnSpeed,
            MinSpeed         = Settings.StreetCarMinSpawnSpeed,
            CarCount         = Settings.TrafficCount,
        };

        return(spwanJob.Schedule(this, inputDeps));
    }
Пример #3
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        CheckDisposeTempData();

        // Compute index
        positionsMap        = new NativeHashMap <int, int>(m_PowderGroup.Length, Allocator.Temp);
        toDeleteEntities    = new NativeHashMap <int, int>(Mathf.Max(m_PowderGroup.Length / 10, 64), Allocator.Temp);
        m_TempDataAllocated = true;

        var computeHashJob = new HashCoordJob()
        {
            powders = m_PowderGroup.powders,
            hashMap = positionsMap
        };
        var previousJobHandle = computeHashJob.Schedule(m_PowderGroup.Length, 64, inputDeps);

        if ((Input.GetMouseButtonDown(0) || Input.GetMouseButton(0)) && PowderGame.IsInWorld(Input.mousePosition))
        {
            var coord    = PowderGame.ScreenToCoord(Input.mousePosition);
            var spawnJob = new SpawnJob()
            {
                hashMap    = positionsMap,
                coord      = coord,
                cmdBuffer  = m_Barrier.CreateCommandBuffer(),
                type       = PowderGame.currentPowder,
                isPainting = !Input.GetMouseButtonDown(0)
            };
            previousJobHandle = spawnJob.Schedule(previousJobHandle);
        }

        // Simulate
        if (PowderGame.simulate)
        {
            var simulateJob = new SimulateJob()
            {
                powders          = m_PowderGroup.powders,
                positions        = m_PowderGroup.positions,
                hashMap          = positionsMap,
                rand             = Rand.Create(),
                entities         = m_PowderGroup.entities,
                cmdBuffer        = m_Barrier.CreateCommandBuffer(),
                toDeleteEntities = toDeleteEntities
            };
            previousJobHandle = simulateJob.Schedule(m_PowderGroup.Length, 64, previousJobHandle);
        }

        var deleteEntitiesJob = new DeleteEntitiesJob()
        {
            entities         = m_PowderGroup.entities,
            cmdBuffer        = m_Barrier.CreateCommandBuffer(),
            toDeleteEntities = toDeleteEntities
        };

        previousJobHandle = deleteEntitiesJob.Schedule(m_PowderGroup.Length, 64, previousJobHandle);

        inputDeps = previousJobHandle;

        return(inputDeps);
    }
Пример #4
0
        protected override JobHandle HandleMessage(JobHandle handle, EntityCommandBuffer commandBuffer)
        {
            var spawnJob = new SpawnJob {
                CommandBuffer = commandBuffer,
                Receivers     = Receivers,
            };

            return(spawnJob.Schedule(this, handle));
        }
Пример #5
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new SpawnJob {
            commandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer(),
        }.ScheduleSingle(this, inputDeps);

        m_EntityCommandBufferSystem.AddJobHandleForProducer(job);
        return(job);
    }
Пример #6
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new SpawnJob
        {
            CommandBuffer = bufferSystem.CreateCommandBuffer()
        };

        return(job.Schedule(this, inputDeps));
    }
Пример #7
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)      //Run the job. Similar to the "Update" function in object-based Unity
    {
        var job = new SpawnJob
        {
            CommandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer()
        }.ScheduleSingle(this, inputDeps);

        m_EntityCommandBufferSystem.AddJobHandleForProducer(job);
        return(job);
    }
Пример #8
0
        protected override JobHandle HandleMessage(JobHandle handle, EntityCommandBuffer commandBuffer)
        {
            var spawnJob = new SpawnJob {
                CommandBuffer = commandBuffer,
                Receivers     = Receivers,
                RandomNumber  = random.NextFloat(4f) - 1f,
            };

            return(spawnJob.Schedule(this, handle));
        }
Пример #9
0
    /// <summary>
    /// 如果有新地图,则启动任务
    /// </summary>
    /// <param name="inputDeps">依赖</param>
    /// <returns>任务句柄</returns>
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var spawnJob = new SpawnJob
        {
            CommandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent()
        }.Schedule(m_Spawner, inputDeps);

        m_EntityCommandBufferSystem.AddJobHandleForProducer(spawnJob);

        return(spawnJob);
    }
Пример #10
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //Debug.Log("unit spawner on update");
        JobHandle job = new SpawnJob
        {
            commandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent()
        }.ScheduleSingle(this, inputDeps);

        m_EntityCommandBufferSystem.AddJobHandleForProducer(job);

        return(job);
    }
Пример #11
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        // Schedule the job that will add Instantiate commands to the EntityCommandBuffer.
        var job = new SpawnJob
        {
            CommandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent()
        }.Schedule(this, inputDependencies);

        m_EntityCommandBufferSystem.AddJobHandleForProducer(job);

        return(job);
    }
Пример #12
0
        protected override JobHandle OnUpdate(JobHandle inputDependencies)
        {
            // Schedule job run:
            var job = new SpawnJob
            {
                CommandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent()
            }.Schedule(this, inputDependencies);

            // Add handle to play back the commands up the chain.
            m_EntityCommandBufferSystem.AddJobHandleForProducer(job);

            return(job);
        }
Пример #13
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var jobHandle = new SpawnJob
        {
            DeltaTime     = Time.deltaTime,
            CommandBuffer = _commandBufferSystem.CreateCommandBuffer().ToConcurrent(),
            RandomNumber  = _random.NextInt(0, 4)
        }.Schedule(this, inputDeps);

        _commandBufferSystem.AddJobHandleForProducer(jobHandle);

        return(jobHandle);
    }
Пример #14
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var spawnJob = new SpawnJob
            {
                commandBuffer         = barrier.CreateCommandBuffer(),
                playerStateFromEntity = GetComponentDataFromEntity <PlayerStateComponentData>(),
                connectionFromEntity  = GetComponentDataFromEntity <NetworkStreamConnection>()
            };
            var handle = spawnJob.ScheduleSingle(this, inputDeps);

            barrier.AddJobHandleForProducer(handle);
            return(handle);
        }
Пример #15
0
        protected override JobHandle OnUpdate(JobHandle pInputDeps)
        {
            SpawnJob _job = new SpawnJob(
                m_bufferSystem.CreateCommandBuffer().ToConcurrent(),
                new Random((uint)UnityEngine.Random.Range(0, int.MaxValue)),
                UnityEngine.Time.deltaTime
                );

            JobHandle _jobHandle = _job.Schedule(this, pInputDeps);

            m_bufferSystem.AddJobHandleForProducer(_jobHandle);

            return(_jobHandle);
        }
Пример #16
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new SpawnJob {
            commandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer(),
            random        = new Unity.Mathematics.Random()
        };

        job.random.InitState((uint)System.DateTime.Now.ToBinary());
        var jobHandle = job.ScheduleSingle(this, inputDeps);

        m_EntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);

        return(jobHandle);
    }
Пример #17
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //计算准备
        var concurrent = bufferSystem.CreateCommandBuffer().ToConcurrent();
        //给Job赋值
        var spawnJob = new SpawnJob();

        spawnJob.concurrent = concurrent;
        //挂载句柄
        var handle = spawnJob.Schedule(this, inputDeps);

        bufferSystem.AddJobHandleForProducer(handle);
        return(handle);
    }
Пример #18
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        SpawnJob spawningJob = new SpawnJob()
        {
            entityCommandBuffer = beginInitializationEntityCommandBuffer.CreateCommandBuffer().ToConcurrent(),
            destinations        = GetComponentDataFromEntity <DestinationData>(true),
            inputs    = GetComponentDataFromEntity <InputData>(true),
            deltaTime = Time.DeltaTime
        };
        JobHandle jobHandle = spawningJob.Schedule(this, inputDeps);

        beginInitializationEntityCommandBuffer.AddJobHandleForProducer(jobHandle);
        return(jobHandle);
    }
Пример #19
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var commandBuffer = _bufferSystem.CreateCommandBuffer().ToConcurrent();
            var spawnJob      = new SpawnJob
            {
                UpdateCommands = commandBuffer,
                Agents         = GetComponentDataFromEntity <AgentInt>(),
                ConTraffics    = GetComponentDataFromEntity <ConnectionTraffic>(),
#if CITY_DEBUG
                ConLens = GetComponentDataFromEntity <ConnectionLengthInt>(),
#endif
            }.Schedule(this, inputDeps);

            spawnJob.Complete();
            return(spawnJob);
        }
Пример #20
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (m_connectionGroup.IsEmptyIgnoreFilter)
            {
                // No connected players, just destroy all asteroids to save CPU
                inputDeps.Complete();
                World.EntityManager.DestroyEntity(asteroidGroup);
                return(default(JobHandle));
            }

            var settings = GetSingleton <ServerSettings>();

            if (m_Prefab == Entity.Null)
            {
                m_useStaticAsteroid = settings.staticAsteroidOptimization;
                var prefabs       = GetSingleton <GhostPrefabCollectionComponent>();
                var serverPrefabs = EntityManager.GetBuffer <GhostPrefabBuffer>(prefabs.serverPrefabs);
                for (int i = 0; i < serverPrefabs.Length; ++i)
                {
                    if (EntityManager.HasComponent <AsteroidTagComponentData>(serverPrefabs[i].Value) && (EntityManager.HasComponent <StaticAsteroid>(serverPrefabs[i].Value) == m_useStaticAsteroid))
                    {
                        m_Prefab = serverPrefabs[i].Value;
                    }
                }
                m_Radius = EntityManager.GetComponentData <CollisionSphereComponent>(m_Prefab).radius;
            }
            var maxAsteroids = settings.numAsteroids;

            JobHandle levelHandle;
            var       spawnJob = new SpawnJob
            {
                commandBuffer     = barrier.CreateCommandBuffer(),
                count             = asteroidGroup.CalculateEntityCountWithoutFiltering(),
                targetCount       = maxAsteroids,
                asteroidPrefab    = m_Prefab,
                asteroidRadius    = m_Radius,
                asteroidVelocity  = settings.asteroidVelocity,
                level             = m_LevelGroup.ToComponentDataArrayAsync <LevelComponent>(Allocator.TempJob, out levelHandle),
                rand              = new Unity.Mathematics.Random((uint)Stopwatch.GetTimestamp()),
                useStaticAsteroid = m_useStaticAsteroid,
                tick              = m_ServerSimulationSystemGroup.ServerTick
            };
            var handle = spawnJob.Schedule(JobHandle.CombineDependencies(inputDeps, levelHandle));

            barrier.AddJobHandleForProducer(handle);
            return(handle);
        }
Пример #21
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var settings        = GetSingleton <SettingsComponent>();
            var singletonEntity = GetSingletonEntity <SettingsComponent>();

            if (_positionsQuery.CalculateEntityCount() == settings.Width * settings.Height)
            {
                return(inputDeps);
            }

            var helper = new ArrayHelper(settings.Width, settings.Height);

            var cachedEntities = new NativeArray <Entity>(settings.Width * settings.Height, Allocator.TempJob);
            var randomValues   = new NativeArray <int>(settings.Width * settings.Height, Allocator.TempJob);

            for (var i = 0; i < settings.Width * settings.Height; ++i)
            {
                randomValues[i] = Random.Range(0, settings.SetSize);
            }

            var cacheJob = new CacheJob
            {
                CachedEntities = cachedEntities,
                Entities       = _positionsQuery.ToEntityArray(Allocator.TempJob),
                Positions      = _positionsQuery.ToComponentDataArray <PositionComponent>(Allocator.TempJob),
                Helper         = helper
            };

            var spawnJob = new SpawnJob
            {
                CachedEntities  = cachedEntities,
                RandomValues    = randomValues,
                GemSet          = GetBufferFromEntity <GemSet>(true),
                CommandBuffer   = _commandBuffer.CreateCommandBuffer(),
                SingletonEntity = singletonEntity,
                Helper          = helper
            };

            var spawnHandler = cacheJob.Schedule(_positionsQuery.CalculateEntityCount(), 32, inputDeps);

            spawnHandler = spawnJob.Schedule(spawnHandler);

            _commandBuffer.AddJobHandleForProducer(spawnHandler);

            return(spawnHandler);
        }
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //Instead of performing structural changes directly, a Job can add a command to an EntityCommandBuffer to perform such changes on the main thread after the Job has finished.
        //Command buffers allow you to perform any, potentially costly, calculations on a worker thread, while queuing up the actual insertions and deletions for later.

        // Schedule the job that will add Instantiate commands to the EntityCommandBuffer.
        var job = new SpawnJob
        {
            CommandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer()
        }.ScheduleSingle(this, inputDeps);

        // SpawnJob runs in parallel with no sync point until the barrier system executes.
        // When the barrier system executes we want to complete the SpawnJob and then play back the commands (Creating the entities and placing them).
        // We need to tell the barrier system which job it needs to complete before it can play back the commands.
        m_EntityCommandBufferSystem.AddJobHandleForProducer(job);

        return(job);
    }
Пример #23
0
    void Start()
    {
        var world         = World.DefaultGameObjectInjectionWorld;
        var entityManager = world.EntityManager;

        EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.TempJob);

        // Create a RenderMeshDescription using the convenience constructor
        // with named parameters.
        var desc = new RenderMeshDescription(
            Mesh,
            Material,
            shadowCastingMode: ShadowCastingMode.Off,
            receiveShadows: false);

        // Create empty base entity
        var prototype = entityManager.CreateEntity();

        // Call AddComponents to populate base entity with the components required
        // by Hybrid Renderer
        RenderMeshUtility.AddComponents(
            prototype,
            entityManager,
            desc);
        entityManager.AddComponentData(prototype, new LocalToWorld());

        // Spawn most of the entities in a Burst job by cloning a pre-created prototype entity,
        // which can be either a Prefab or an entity created at run time like in this sample.
        // This is the fastest and most efficient way to create entities at run time.
        var spawnJob = new SpawnJob
        {
            Prototype   = prototype,
            Ecb         = ecb.AsParallelWriter(),
            EntityCount = EntityCount,
        };

        var spawnHandle = spawnJob.Schedule(EntityCount, 128);

        spawnHandle.Complete();

        ecb.Playback(entityManager);
        ecb.Dispose();
        entityManager.DestroyEntity(prototype);
    }
Пример #24
0
    protected override JobHandle OnUpdate(JobHandle inputDependencies)
    {
        var commandBuffer = _bufferSystem.CreateCommandBuffer().ToConcurrent();

        //Create New Maps
        var createJob = Entities.WithAll <WorldMapViewData>().WithNone <WorldMapViewSystemData>().ForEach((int nativeThreadIndex, Entity entity) =>
        {
            commandBuffer.AddComponent(nativeThreadIndex, entity, new WorldMapViewSystemData());
        }).Schedule(inputDependencies);

        _bufferSystem.AddJobHandleForProducer(createJob);

        //Clean Up Destroyed Maps
        var destroyJob = Entities.WithAll <WorldMapViewSystemData>().WithNone <WorldMapViewData>().ForEach((int nativeThreadIndex, Entity entity) =>
        {
            //Cleanup Destroyed Maps
            commandBuffer.RemoveComponent <WorldMapViewSystemData>(nativeThreadIndex, entity);
        }).Schedule(createJob);

        _bufferSystem.AddJobHandleForProducer(destroyJob);

        var tileArchetype = _tileArchetype;

        var cleanupJob = new CleanupJob
        {
            commandBuffer = _bufferSystem.CreateCommandBuffer().ToConcurrent(),
            mapViews      = worldMapViewDataQuery.ToComponentDataArray <WorldMapViewData>(Allocator.TempJob)
        };

        var cleanupJobHandle = cleanupJob.Schedule(worldMapTiles, destroyJob);

        _bufferSystem.AddJobHandleForProducer(cleanupJobHandle);

        var spawnJob = new SpawnJob()
        {
            CommandBuffer  = _bufferSystem.CreateCommandBuffer().ToConcurrent(),
            OutOfViewTiles = outOfViewQuery.ToEntityArray(Allocator.TempJob),
            TileArchetype  = tileArchetype
        }.Schedule(viewChangedQuery, cleanupJobHandle);

        _bufferSystem.AddJobHandleForProducer(spawnJob);

        return(spawnJob);
    }
Пример #25
0
    // Update is called once per frame
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var spawnJob = new SpawnJob
        {
            dt         = Time.deltaTime,
            fortresses = spawnings.fortresses,
            spawners   = spawnings.spawners
        };
        var overloadJob = new OverloadJob
        {
            dt         = Time.deltaTime,
            fortresses = overloadings.fortresses,
            overloads  = overloadings.overloads
        };
        var spawnFence    = spawnJob.Schedule(spawnings.Length, SimulationState.TinyBatchSize, inputDeps);
        var overloadFence = overloadJob.Schedule(overloadings.Length, SimulationState.TinyBatchSize, spawnFence);

        return(JobHandle.CombineDependencies(spawnFence, overloadFence));
    }
Пример #26
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var       settings = GetSingleton <ServerSettings>();
            JobHandle levelHandle;
            var       spawnJob = new SpawnJob
            {
                commandBuffer         = barrier.CreateCommandBuffer(),
                playerStateFromEntity = GetComponentDataFromEntity <PlayerStateComponentData>(),
                networkIdFromEntity   = GetComponentDataFromEntity <NetworkIdComponent>(),
                shipArchetype         = settings.shipArchetype,
                playerRadius          = settings.playerRadius,
                level = m_LevelGroup.ToComponentDataArray <LevelComponent>(Allocator.TempJob, out levelHandle),
                rand  = new Unity.Mathematics.Random((uint)Stopwatch.GetTimestamp())
            };
            var handle = spawnJob.ScheduleSingle(this, JobHandle.CombineDependencies(inputDeps, levelHandle));

            barrier.AddJobHandleForProducer(handle);
            return(handle);
        }
Пример #27
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        NativeArray<Entity> enemiesArray = new NativeArray<Entity>(0, Allocator.TempJob);

        if (Time.time - timer > cooldownTime)
        {
            EntityQuery enemyQuery = GetEntityQuery(ComponentType.ReadOnly<Enemy>(), ComponentType.ReadOnly<Disabled>());

            NativeArray<Entity> tempArray = enemyQuery.ToEntityArray(Allocator.TempJob);




            NativeSlice<Entity> nativeSlice = tempArray.Slice(0, math.min(enemyQuery.CalculateLength(), multiplier * 2));


            enemiesArray.Dispose();

            enemiesArray = new NativeArray<Entity>(nativeSlice.Length, Allocator.TempJob);

            nativeSlice.CopyTo(enemiesArray);
            tempArray.Dispose();

            timer = Time.time;
            multiplier++;
        }



        SpawnJob spawnJob = new SpawnJob
        {
            commandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(),
            enemiesArray = enemiesArray
        };

        JobHandle jobHandle = spawnJob.Schedule(inputDeps);
        endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);
        jobHandle.Complete();

        enemiesArray.Dispose();
        return jobHandle;
    }
Пример #28
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        //取代直接执行结构的改变,一个任务可以添加一个命令到EntityCommandBuffer(实体命令缓存),从而在主线程上完成其任务后执行这些改变
        //命令缓存允许在工作线程上执行任何潜在消耗大的计算,同时把实际的增删排到之后把将要添加实例化命令到EntityCommandBuffer的任务加入计划
        var job = new SpawnJob
        {
            commandBuffer = m_BeginInitializationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(),
            delatime      = Time.deltaTime,
            position      = UnityEngine.Random.insideUnitSphere * 50
        };
        JobHandle jobHandle = job.Schedule(this, inputDeps);

        //Debug.Log("场景实体个数===" + EntityManager.EntityCapacity);   错误
        ///生成任务并行且没有同步机会直到阻塞系统执行
        ///当阻塞系统执行时,我们想完成生成任务,然后再执行那些命令(创建实体并放置到指定位置)
        /// 我们需要告诉阻塞系统哪个任务需要在它能回放命令之前完成
        m_BeginInitializationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);

        return(jobHandle);
    }
Пример #29
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (queue.IsEmpty)
            {
                return(inputDeps);
            }

            var job = inputDeps;

            for (var i = 0; i < spawnBatchCount; ++i)
            {
                job = new SpawnJob
                {
                    CommandBuffer = barrier.CreateCommandBuffer().AsParallelWriter()
                }.Schedule(job);

                barrier.AddJobHandleForProducer(job);
            }

            return(job);
        }
Пример #30
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (m_connectionGroup.IsEmptyIgnoreFilter)
            {
                // No connected players, just destroy all asteroids to save CPU
                inputDeps.Complete();
                World.GetExistingManager <EntityManager>().DestroyEntity(asteroidGroup);
                return(default(JobHandle));
            }
            var settings     = GetSingleton <ServerSettings>();
            var maxAsteroids = settings.numAsteroids;

            JobHandle gatherJob;
            var       countJob = new CountJob
            {
                chunks     = asteroidGroup.CreateArchetypeChunkArray(Allocator.TempJob, out gatherJob),
                count      = count,
                entityType = GetArchetypeChunkEntityType()
            };

            inputDeps = countJob.Schedule(JobHandle.CombineDependencies(inputDeps, gatherJob));

            JobHandle levelHandle;
            var       spawnJob = new SpawnJob
            {
                commandBuffer     = barrier.CreateCommandBuffer(),
                count             = count,
                targetCount       = maxAsteroids,
                asteroidArchetype = settings.asteroidArchetype,
                asteroidRadius    = settings.asteroidRadius,
                asteroidVelocity  = settings.asteroidVelocity,
                level             = m_LevelGroup.ToComponentDataArray <LevelComponent>(Allocator.TempJob, out levelHandle),
                rand = new Unity.Mathematics.Random((uint)Stopwatch.GetTimestamp())
            };
            var handle = spawnJob.Schedule(JobHandle.CombineDependencies(inputDeps, levelHandle));

            barrier.AddJobHandleForProducer(handle);
            return(handle);
        }