using Unity.Burst; using Unity.Collections; using Unity.Jobs; using UnityEngine; namespace ECSTest { public class TestIJobParallelForDefer { [BurstCompile] public struct PopulateJob : IJob { public NativeList input; public void Execute() { Debug.Log($"000===== length: {input.Length}"); for (int i = 0; i < 100; ++i) input.Add(i); } } [BurstCompile] public struct StatJob : IJob { public NativeList input; public void Execute() { Debug.Log($"111===== length: {input.Length}"); } } [BurstCompile] public struct ParallelJob : IJobParallelForDefer { [ReadOnly] public NativeList input; public void Execute(int index) { Debug.Log($"index: {index}, length: {input.Length}"); } } public static void Test() { var list = new NativeList(100, Allocator.TempJob); var handle = new PopulateJob() {input = list}.Schedule(); handle = new ParallelJob() { input = list }.Schedule(list, 16, handle); handle = new PopulateJob() {input = list}.Schedule(handle); handle = new ParallelJob() { input = list }.Schedule(list, 16, handle); handle.Complete(); list.Dispose(); } } }