public void ForEachJobHandleDependency() { // A useful general test (that a dependency works between a Job and a JobForEach) // but specifically testing that (when this is written) DOTS-RT has a single threaded // JobForEach and a multi-threaded Job. const int N = 10000; var entity = m_Manager.CreateEntity(typeof(EcsTestData)); m_Manager.SetComponentData(entity, new EcsTestData(-1)); NativeArray <int> arr = new NativeArray <int>(N, Allocator.TempJob); ArrayJob arrayJob = new ArrayJob() { arr = arr }; ProcessArrayJob processArrayJob = new ProcessArrayJob() { arr = arr }; JobHandle handle = arrayJob.Schedule(); // long running JobHandle handle2 = processArrayJob.Schedule(EmptySystem, handle); // super fast handle2.Complete(); Assert.AreEqual(N, m_Manager.GetComponentData <EcsTestData>(entity).value); Assert.AreEqual(2, arr[0]); Assert.AreEqual(1, arr[1]); arr.Dispose(); }
void Update() { float time = Time.realtimeSinceStartup; #region IJobParallelFor NativeArray <float> posYarray = new NativeArray <float>(enemy.Length, ALlocator.TempJob); for (int i = 0; i < enemy.Length; i++) { posYarray[i] = enemy[i].position.y; } ArrayJob arrayJob = new ArrayJob { deltaTime = Time.deltaTime, posY = posYarray }; JobHandle arrayJobHandle = arrayJob.Schedule(enemy.Length, 10); arrayJobHandle.Complete(); for (int i = 0; i < enemy.Length; i++) { enemy[i].position += new Vector3(0, posYarray[i], 0); } posYarray.Dispose(); #endregion #region IJobParallelForTransform TransformAccessArray transformAccess = new TransformAccessArray(enemy.Length); for (int i = 0; i < enemy.Length; i++) { transformAccess.Add(enemy[i]); } transformJob tJob = new transformJob { deltaTime = Time.deltaTime, }; JobHandle jobHandle = tJob.Schedule(transformAccess); jobHandle.Complete(); transformAccess.Dispose(); #endregion Debug.Log((Time.realtimeSinceStartup - time) * 1000f + " ms"); }