要在主线程中安排作业,您必须: 实例化作业。 填充作业的数据。 调用Schedule方法。 调用Schedule将作业放入作业队列以便在适当的时间执行。一旦安排,你就不能打断工作。 注意:您只能Schedule从主线程调用。 安排工作的一个例子 NativeArray<float> result = new NativeArray<float>(1, Allocator.TempJob);// Set up the job dataMyJob jobData = new MyJob();jobData.a = 10;jobData.b = 10;jobData.result = result;// Schedule the jobJobHandle handle = jobData.Schedule();// Wait for the job to completehandle.Complete();// All copies of the NativeArray point to the same memory, you can access the result in "your" copy of the NativeArrayfloat aPlusB = result[0];// Free the memory allocated by the result arrayresult.Dispose(); 赞微海报分享
近期评论