Планирование заданий

Unity · Версия 2020.3 LTS · Manual

Планирование заданий

Чтобы запланировать задание в основном потоке, необходимо:

  • Создайте экземпляр задания.
  • Заполните данные задания.
  • Вызовите метод Schedule.

Вызов Schedule помещает задание в очередь заданий для выполнения в соответствующее время. После планирования вы не можете прервать задание.

Примечание. Вызывать Schedule можно только из основного потока.

Пример планирования задания

// Create a native array of a single float to store the result. This example waits for the job to complete for illustration purposes
NativeArray result = new NativeArray(1, Allocator.TempJob);

// Set up the job data
MyJob jobData = new MyJob();
jobData.a = 10;
jobData.b = 10;
jobData.result = result;

// Schedule the job
JobHandle handle = jobData.Schedule();

// Wait for the job to complete
handle.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();

Обновлено 17 ноября 2026 г.