parent
d9b66edd89
commit
098cbfb696
4 changed files with 80 additions and 6 deletions
@ -0,0 +1,57 @@ |
||||
using Unity.Burst; |
||||
using Unity.Collections; |
||||
using Unity.Jobs; |
||||
using UnityEngine; |
||||
|
||||
namespace ECSTest |
||||
{ |
||||
public class TestIJobParallelForDefer |
||||
{ |
||||
[BurstCompile] |
||||
public struct PopulateJob : IJob |
||||
{ |
||||
public NativeList<int> 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<int> input; |
||||
|
||||
public void Execute() |
||||
{ |
||||
Debug.Log($"111===== length: {input.Length}"); |
||||
} |
||||
} |
||||
|
||||
|
||||
[BurstCompile] |
||||
public struct ParallelJob : IJobParallelForDefer |
||||
{ |
||||
[ReadOnly] public NativeList<int> input; |
||||
|
||||
public void Execute(int index) |
||||
{ |
||||
Debug.Log($"index: {index}, length: {input.Length}"); |
||||
} |
||||
} |
||||
|
||||
public static void Test() |
||||
{ |
||||
var list = new NativeList<int>(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(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,3 @@ |
||||
fileFormatVersion: 2 |
||||
guid: c02a6e16e5b349d3b07d50471da304c9 |
||||
timeCreated: 1766089200 |
||||
Loading…
Reference in new issue