Guest User

Untitled

a guest
Mar 9th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1. public class JobExample : MonoBehaviour
  2. {
  3.  
  4.     public int JobCount = 10;
  5.     public bool ParallelExecution;
  6.    
  7.    
  8.     void Update ()
  9.     {
  10.         var handles = new JobHandle[JobCount];
  11.         for (int i = 0; i < JobCount; i++)
  12.         {
  13.             DummyJob job = new DummyJob();
  14.             handles[i] = job.Schedule();
  15.             if (!ParallelExecution)
  16.             {
  17.                 handles[i].Complete(); 
  18.             }
  19.         }
  20.  
  21.         if (ParallelExecution)
  22.         {
  23.             for (int i = 0; i < JobCount; i++)
  24.             {
  25.                 handles[i].Complete();
  26.             }
  27.         }
  28.        
  29.        
  30.     }
  31. }
  32.  
  33.  
  34.  
  35. public struct DummyJob : IJob
  36. {
  37.     public void Execute()
  38.     {
  39.         Thread.Sleep(10);
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment