コード例 #1
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new AddJob()
        {
            Adders = _adderGroup.GetComponentDataArray <Adder>()
        };

        return(job.Schedule(_adderGroup.CalculateLength(), 64, inputDeps));
    }
コード例 #2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var job = new AddJob();

            job.commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent();
            inputDeps         = job.Schedule(this, inputDeps);
            m_Barrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
コード例 #3
0
    // Start is called before the first frame update
    void Start()
    {
        var beforeTime1 = Time.realtimeSinceStartup;;
        // 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
        AddJob jobData = new AddJob();

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

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

        // Setup the data for job #2
        MulResultJob mulJobData = new MulResultJob();

        mulJobData.value  = 5;
        mulJobData.result = result;

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

        // job #3
        AddResultJob addJobData = new AddResultJob();

        addJobData.value  = 9;
        addJobData.result = result;
        JobHandle thirdHandle = addJobData.Schedule(secondHandle);//secondHandle

        // Wait for job #3 to complete
        thirdHandle.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("Result:" + aPlusB);
        text.text += aPlusB + " ";
        // Free the memory allocated by the result array
        result.Dispose();

        Debug.Log("cost " + (Time.realtimeSinceStartup - beforeTime1));
        text.text  += Time.realtimeSinceStartup - beforeTime1 + " ";
        beforeTime1 = Time.realtimeSinceStartup;

        int a = 10;
        int b = 10;
        int c = a + b;

        c *= 5;
        c += 9;
        Debug.Log("cost " + (Time.realtimeSinceStartup - beforeTime1));
        text.text += Time.realtimeSinceStartup - beforeTime1 + " ";
    }
コード例 #4
0
    // Start is called before the first frame update
    void Start()
    {
        var a = 10;
        var b = 15;

        NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob);
        var job = new AddJob
        {
            m_a      = a,
            m_b      = b,
            m_result = result
        };

        JobHandle jobHandle = job.Schedule();

        jobHandle.Complete();

        print(result[0]);
        result.Dispose();
    }
コード例 #5
0
ファイル: Test_AddJob.cs プロジェクト: rito15/UnityStudy2
    private void Start()
    {
        // 1. 결과 배열 생성
        NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob);

        // 잡 생성
        AddJob jobData = new AddJob {
            a = 15, b = 20, result = result
        };

        // 스케줄링
        JobHandle handle = jobData.Schedule();

        // 대기
        handle.Complete();

        // 결과 확인
        float aPlusB = result[0];

        // 해제
        result.Dispose();
    }
コード例 #6
0
    private static void TestIJob()
    {
        ExecuteJobOrJobParallelFor((values1, values2, results) =>
        {
            AddAllJob addAllJob1       = new AddAllJob();
            addAllJob1.adder           = 1;
            addAllJob1.values          = values1;
            JobHandle addAllJob1Handle = addAllJob1.Schedule();

            AddAllJob addAllJob2       = new AddAllJob();
            addAllJob2.adder           = 1;
            addAllJob2.values          = values2;
            JobHandle addAllJob2Handle = addAllJob2.Schedule();

            AddJob addJob = new AddJob();
            addJob.a      = values1;
            addJob.b      = values2;
            addJob.result = results;

            return(addJob.Schedule(JobHandle.CombineDependencies(addAllJob1Handle, addAllJob2Handle)));
        });
    }
    // Update is called once per frame
    void Update()
    {
        var powJob = new PowJob
        {
            dataSize = dataSize,
            dataIn   = dataA[READ],
            dataOut  = dataB[WRITE]
        };

        powJobHndl = powJob.Schedule();


        var addJob = new AddJob
        {
            dataSize = dataSize,
            dataIn   = dataB[READ],
            dataOut  = dataC[WRITE]
        };

        addJobHndl = addJob.Schedule();

        JobHandle.ScheduleBatchedJobs();
    }
コード例 #8
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var job = new AddJob();

        return(job.Schedule(this, inputDeps));
    }