Example #1
0
    //多个jobs依赖关系
    public void SchedulingTwoJobs()
    {
        NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob);
        MyJob jobData = new MyJob();

        jobData.a      = 10;
        jobData.b      = 10;
        jobData.result = result;
        // 设置第一个任务开关
        JobHandle firstHandle = jobData.Schedule();

        //设置第二个任务
        AddOneJob incJobData = new AddOneJob();

        incJobData.result = result;

        // UnityEngine.Debug.Log(result[0]);
        //设置依赖
        JobHandle secondHandle = incJobData.Schedule(firstHandle);

        //等待完成
        secondHandle.Complete();

        float aPlusB = result[0];

        UnityEngine.Debug.Log(aPlusB);

        //释放资源
        result.Dispose();
    }
Example #2
0
    private void Start()
    {
        // Create a native array of a single float to store the result in. This example waits for the job to complete
        NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob);

        // Setup the data for job #1
        MyJob jobData = new MyJob();

        jobData.a      = 10;
        jobData.b      = 10;
        jobData.result = result;

        // Schedule job #1
        JobHandle firstHandle = jobData.Schedule();

        // Setup the data for job #2
        AddOneJob incJobData = new AddOneJob();

        incJobData.result = result;

        // Schedule job #2
        JobHandle secondHandle = incJobData.Schedule(firstHandle);

        // Wait for job #2 to complete
        secondHandle.Complete();

        // All copies of the NativeArray point to the same memory, you can access the result in "your" copy of the NativeArray
        float aPlusB = result[0];

        // Free the memory allocated by the result array
        result.Dispose();

        Debug.Log($"O valor de sei la o que é {aPlusB}");
    }
Example #3
0
    public void jobTesting()
    {
        NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob);

        // Setup the data for job #1
        MyJob jobData = new MyJob();

        jobData.a      = 10;
        jobData.b      = 10;
        jobData.result = result;

        // Schedule job #1
        JobHandle firstHandle = jobData.Schedule();

        // Setup the data for job #2
        AddOneJob incJobData = new AddOneJob();

        incJobData.result = result;

        // Schedule job #2
        JobHandle secondHandle = incJobData.Schedule(firstHandle);

        // Wait for job #2 to complete
        secondHandle.Complete();

        // All copies of the NativeArray point to the same memory, you can access the result in "your" copy of the NativeArray
        float aPlusB = result[0];

        Debug.Log(aPlusB);
        // Free the memory allocated by the result array
        result.Dispose();
    }
    void ScheduleTestJob()
    {
        // Create a native array of a single float to store the result. This example waits for the job to complete for illustration purposes
        NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob);

        MyJob tempJob = new MyJob();

        tempJob.a      = 10;
        tempJob.b      = 10;
        tempJob.result = result;

        JobHandle tempJobHandle = tempJob.Schedule();

        // Setup the data for job #2
        AddOneJob addOneJob = new AddOneJob();

        addOneJob.result = result;

        JobHandle secondJobHandle = addOneJob.Schedule(tempJobHandle);

        secondJobHandle.Complete();

        float resultValue = result[0];

        Debug.Log("Result of the myJob: " + resultValue);

        result.Dispose();
    }