protected override JobHandle OnUpdate(JobHandle inputDeps) { var asteroidMoveJob = new AsteroidMoveJob() { DeltaTime = Time.deltaTime, UnscaledTime = Time.unscaledTime }; return(asteroidMoveJob.Schedule(this, inputDeps)); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { ArchetypeChunkComponentType <Position> positionRW = GetArchetypeChunkComponentType <Position>(false); ArchetypeChunkComponentType <Rotation> rotationRW = GetArchetypeChunkComponentType <Rotation>(false); ArchetypeChunkComponentType <AsteroidMoveData> asteroidMoveDataRO = GetArchetypeChunkComponentType <AsteroidMoveData>(true); ArchetypeChunkComponentType <EntityBoundCenterData> boundCenterDataRW = GetArchetypeChunkComponentType <EntityBoundCenterData>(false); ArchetypeChunkComponentType <EntityBoundMinMaxData> boundMinMaxDataRW = GetArchetypeChunkComponentType <EntityBoundMinMaxData>(false); ArchetypeChunkComponentType <EntityBoundOffsetData> boundOffsetDataRO = GetArchetypeChunkComponentType <EntityBoundOffsetData>(true); ArchetypeChunkComponentType <EntityBoundExtendData> boundExtendDataRO = GetArchetypeChunkComponentType <EntityBoundExtendData>(true); //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; NativeArray <ArchetypeChunk> asteroidMoveDataChunk = asteroidMoveDataComponentGroup.CreateArchetypeChunkArray(Allocator.TempJob, out createChunckArrayJobHandle); //Special case when our query return no chunk at all if (asteroidMoveDataChunk.Length == 0) { createChunckArrayJobHandle.Complete(); asteroidMoveDataChunk.Dispose(); return(inputDeps); } //Make sure our movejob is dependent on the job filling the array has completed JobHandle moveJobDependency = JobHandle.CombineDependencies(inputDeps, createChunckArrayJobHandle); AsteroidMoveJob moveJob = new AsteroidMoveJob { chunks = asteroidMoveDataChunk, positionRW = positionRW, rotationRW = rotationRW, asteroidMoveDataRO = asteroidMoveDataRO, boundCenterDataRW = boundCenterDataRW, boundMinMaxDataRW = boundMinMaxDataRW, boundOffsetDataRO = boundOffsetDataRO, boundExtendDataRO = boundExtendDataRO, deltaTime = Time.deltaTime, }; return(moveJob.Schedule(asteroidMoveDataChunk.Length, MonoBehaviourECSBridge.Instance.GetJobBatchCount(asteroidMoveDataChunk.Length), moveJobDependency)); }