You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.5 KiB
57 lines
1.5 KiB
|
3 weeks ago
|
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();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|