コード例 #1
0
        private async UniTask <int> SumAsync(NativeArray <int> values)
        {
            // 初期化
            var results = new NativeArray <int>(1, Allocator.TempJob);

            // ジョブを作成
            var job = new SumJob()
            {
                Result = results,
                Values = values
            };

            var jobHandle = job.Schedule();


            // JobHandlerをawait
            await jobHandle;



            // 結果を格納
            var sum = job.Result[0];

            // Dispose
            job.Result.Dispose();
            job.Values.Dispose();

            return(sum);
        }
コード例 #2
0
            /// <summary> Get the total number of events of a specific type. </summary>
            /// <param name="handle"> Input dependencies. </param>
            /// <param name="count"> The output array. This must be length of at least 1 and the result will be stored in the index of 0. </param>
            /// <returns> The dependency handle. </returns>
            public JobHandle GetEventCount(JobHandle handle, NativeArray <int> count)
            {
                var readerCount = this._eventSystem.GetEventReadersCount <T>();

                if (readerCount != 0)
                {
                    var counter = new NativeArray <int>(readerCount, Allocator.TempJob);

                    handle = new CountJob {
                        Counter = counter
                    }
                    .ScheduleSimultaneous <CountJob, T>(this._eventSystem, handle);

                    handle = new SumJob {
                        Counter = counter, Count = count
                    }.Schedule(handle);

                    counter.Dispose(handle);
                }

                return(handle);
            }