Beispiel #1
0
        protected override void OnUpdate()
        {
            //Create a native array to hold the intermediate sums
            int chunksInQuery = query.CalculateChunkCount();
            NativeArray <int> intermediateSums
                = new NativeArray <int>(chunksInQuery, Allocator.TempJob);

            //Schedule the first job to add all the buffer elements
            BuffersInChunks bufferJob = new BuffersInChunks();

            bufferJob.BufferType = GetArchetypeChunkBufferType <MyBufferElement>();
            bufferJob.sums       = intermediateSums;
            this.Dependency      = bufferJob.ScheduleParallel(query, this.Dependency);

            //Schedule the second job, which depends on the first
            SumResult finalSumJob = new SumResult();

            finalSumJob.sums = intermediateSums;
            NativeArray <int> finalSum = new NativeArray <int>(1, Allocator.Temp);

            finalSumJob.result = finalSum;
            this.Dependency    = finalSumJob.Schedule(this.Dependency);

            this.CompleteDependency();
            Debug.Log("Sum of all buffers: " + finalSum[0]);
            finalSum.Dispose();
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //Create a native array to hold the intermediate sums
            int chunksInQuery = query.CalculateChunkCount();
            NativeArray <int> intermediateSums
                = new NativeArray <int>(chunksInQuery, Allocator.TempJob);

            //Schedule the first job to add all the buffer elements
            BuffersInChunks bufferJob = new BuffersInChunks();

            bufferJob.BufferType = GetArchetypeChunkBufferType <MyBufferElement>();
            bufferJob.sums       = intermediateSums;
            JobHandle intermediateJob = bufferJob.Schedule(query, inputDeps);

            //Schedule the second job, which depends on the first
            SumResult finalSumJob = new SumResult();

            finalSumJob.sums = intermediateSums;
            return(finalSumJob.Schedule(intermediateJob));
        }