Ejemplo n.º 1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            EntityArray boltSpawnerEntityDataArray = boltSpawnerEntityDataGroup.GetEntityArray();

            if (boltSpawnerEntityDataArray.Length == 0)
            {
                return(inputDeps);
            }

            BoltSpawnerEntityData boltSpawnerEntityData = GetComponentDataFromEntity <BoltSpawnerEntityData>()[boltSpawnerEntityDataArray[0]];

            ArchetypeChunkEntityType entityTypeRO = GetArchetypeChunkEntityType();
            ArchetypeChunkComponentType <PlayerInputData>     playerInputDataRO     = GetArchetypeChunkComponentType <PlayerInputData>(true);
            ArchetypeChunkComponentType <PlayerMoveData>      playerMoveDataRO      = GetArchetypeChunkComponentType <PlayerMoveData>(true);
            ArchetypeChunkComponentType <Position>            positionRO            = GetArchetypeChunkComponentType <Position>(true);
            ArchetypeChunkComponentType <PlayerSpawnBoltData> playerSpawnBoltDataRW = GetArchetypeChunkComponentType <PlayerSpawnBoltData>(false);


            //CreateArchetypeChunkArray runs inside a job, we can use a job handle to make dependency on that job
            //A NativeArray<ArchetypeChunk> is allocated with the correct size on the main thread and that's what is returned, we are responsible for de-allocating it (In this case using [DeallocateOnJobCompletion] in the move job)
            //The job scheduled by CreateArchetypeChunkArray fill that array with correct chunk information
            JobHandle createChunckArrayJobHandle = new JobHandle();
            NativeArray <ArchetypeChunk> playerSpawnBoltDataChunks = playerSpawnBoltDataGroup.CreateArchetypeChunkArray(Allocator.TempJob, out createChunckArrayJobHandle);

            //Special case when our query return no chunk at all
            if (playerSpawnBoltDataChunks.Length == 0)
            {
                createChunckArrayJobHandle.Complete();
                playerSpawnBoltDataChunks.Dispose();
                return(inputDeps);
            }

            //Make sure our movejob is dependent on the job filling the array has completed
            JobHandle spawnJobDependency = JobHandle.CombineDependencies(inputDeps, createChunckArrayJobHandle);

            PlayerSpawnBoltJob playerSpawnBoltJob = new PlayerSpawnBoltJob
            {
                chunks                = playerSpawnBoltDataChunks,
                entityTypeRO          = entityTypeRO,
                playerInputDataRO     = playerInputDataRO,
                playerMoveDataRO      = playerMoveDataRO,
                positionRO            = positionRO,
                playerSpawnBoltDataRW = playerSpawnBoltDataRW,
                spawnBoltEntityQueue  = boltSpawnerEntityData.playerBoltSpawnQueueConcurrent,
                currentTime           = Time.time,
            };

            return(playerSpawnBoltJob.Schedule(playerSpawnBoltDataChunks.Length,
                                               MonoBehaviourECSBridge.Instance.GetJobBatchCount(playerSpawnBoltDataChunks.Length),
                                               spawnJobDependency));
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            PlayerSpawnBoltJob playerSpawnBoltJob = new PlayerSpawnBoltJob
            {
                entityArray              = playerMoveSpawnBoltDataGroup.entityArray,
                playerInputDataArray     = playerMoveSpawnBoltDataGroup.playerInputDataArray,
                playerMoveDataArray      = playerMoveSpawnBoltDataGroup.playerMoveDataArray,
                playerSpawnBoltDataArray = playerMoveSpawnBoltDataGroup.playerSpawnBoltDataArray,
                spawnBoltEntityQueue     = boltSpawnerEntityDataGroup.boltSpawnerEntityData[0].playerBoltSpawnQueueConcurrent,
                currentTime              = Time.time,
            };


            return(playerSpawnBoltJob.Schedule(playerMoveSpawnBoltDataGroup.Length,
                                               MonoBehaviourECSBridge.Instance.GetJobBatchCount(playerMoveSpawnBoltDataGroup.Length),
                                               inputDeps));
        }