A more complex example

Spawning a job just to sum two numbers is definitely not an example of optimal programming. Unity created jobs to run thousands of them to lift hard work into the multithreading domain.

Therefore, we will now modify our previous spinning cubes example so that the actual spinning is performed by jobs. The first thing we want to do is to create our job, as follows:

using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Jobs;


namespace JobSystem
{

    public struct RotatorJob : IJobParallelForTransform
    {

        [ReadOnly]
        public NativeList<float> speeds;

        [ReadOnly]
        public float deltaTime;

        public void Execute(int index, TransformAccess transform) { Vector3 currentRotation ...

Get Unity Game Optimization - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.