private void Update() { GridMaster gm = GridMaster.Instance; CalculateStartEndPosJob calcStartEndJob = new CalculateStartEndPosJob() { gridBoundsCenter = gm.Bounds.center, gridBoundsExtents = gm.Bounds.extents, nodeSize = GridMaster.NodeSize, isGridCreated = gm.IsGridCreated, gridWidth = gm.GridWidth, endPositionsToChooseFrom = endPositionsToChooseFrom, startPositionsIndices = new NativeArray <int>(quantity, Allocator.TempJob, NativeArrayOptions.UninitializedMemory), endPositionsIndices = new NativeArray <int>(quantity, Allocator.TempJob, NativeArrayOptions.UninitializedMemory), rand = new Random(0x6E624EB7u) }; JobHandle calcStartEndHandle = calcStartEndJob.Schedule(agentsTransAcc); FindPathJobParallel findPathsJob = new FindPathJobParallel(gm.GridWidth * gm.GridDepth, gm.GridWidth, 4, calcStartEndJob.startPositionsIndices, calcStartEndJob.endPositionsIndices, gm.NodesNeighbors, gm.NodesTypes, quantity); JobHandle findPathsHandle = findPathsJob.Schedule(quantity, 4, calcStartEndHandle); MoveAgentsJob moveJob = new MoveAgentsJob() { nodeIndicesDestinations = findPathsJob.nextNodesIndices, nodes = gm.NodesTransforms, speed = agentsSpeed, dt = Time.deltaTime }; JobHandle moveHandle = moveJob.Schedule(agentsTransAcc, findPathsHandle); UpdateCamPivot(); moveHandle.Complete(); findPathsJob.Dispose(); calcStartEndJob.Dispose(); if (Keyboard.current.escapeKey.wasPressedThisFrame) { Application.Quit(); } }
private void Update() { float dt = Time.deltaTime; GridMaster gm = GridMaster.Instance; CalculateStartEndPosJob calcStartEndJob = new CalculateStartEndPosJob() { gridBoundsCenter = gm.Bounds.center, gridBoundsExtents = gm.Bounds.extents, nodeSize = GridMaster.NodeSize, isGridCreated = gm.IsGridCreated, gridWidth = gm.GridWidth, rand = new Random(0x6E624EB7u), endPositionsToChooseFrom = endPositionsToChooseFrom, startPositionsIndices = new NativeArray <int>(quantity, Allocator.TempJob, NativeArrayOptions.UninitializedMemory), endPositionsIndices = new NativeArray <int>(quantity, Allocator.TempJob, NativeArrayOptions.UninitializedMemory) }; JobHandle calcStartEndHandle = calcStartEndJob.Schedule(agentsTransAcc); FindPathJobParallel findPathsJob = new FindPathJobParallel() { numNodes = gm.GridWidth * gm.GridDepth, gridWidth = gm.GridWidth, numNeighbors = GridMaster.NodeNeighbors, startNodesIndices = calcStartEndJob.startPositionsIndices, endNodeIndices = calcStartEndJob.endPositionsIndices, nodesNeighbors = gm.NodesNeighbors, nodesTypes = gm.NodesTypes, nextNodesIndices = new NativeArray <int>(quantity, Allocator.TempJob, NativeArrayOptions.UninitializedMemory), }; JobHandle findPathsHandle = findPathsJob.Schedule(quantity, 4, calcStartEndHandle); MoveAgentsJob moveJob = new MoveAgentsJob() { nodeIndicesDestinations = findPathsJob.nextNodesIndices, nodes = gm.NodesTransforms, speed = agentsSpeed, dt = dt }; JobHandle moveHandle = moveJob.Schedule(agentsTransAcc, findPathsHandle); UpdateCamPivot(dt); JobHandle disposeHandle = calcStartEndJob.startPositionsIndices.Dispose(findPathsHandle); disposeHandle = JobHandle.CombineDependencies(disposeHandle, calcStartEndJob.endPositionsIndices.Dispose(findPathsHandle)); disposeHandle = JobHandle.CombineDependencies(disposeHandle, findPathsJob.nextNodesIndices.Dispose(moveHandle)); JobHandle.CompleteAll(ref moveHandle, ref disposeHandle); #if !UNITY_EDITOR if (Keyboard.current.escapeKey.wasPressedThisFrame) { Application.Quit(); } #else if (Keyboard.current.escapeKey.wasPressedThisFrame) { EditorApplication.isPlaying = false; } #endif }