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

        public NativeList<float> speeds;

        public float deltaTime;

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

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.