/// <summary> /// Adds the nodes debugging. /// </summary> public void RecalculateDebug() { DisposeDebugNativeDatastructures(); int numNodes = gridDepth * gridWidth; // prepare the job that calculates the vertices for the neighbor connection lines int arrayLength = numNodes * NodeNeighbors * 2; connectionsMeshVertices = new NativeArray <Vector3>(arrayLength, Allocator.Persistent); connectionsMeshIndices = new NativeArray <int>(arrayLength, Allocator.Persistent); CalculateConnectionMeshJob calcConnectionsMeshJob = new CalculateConnectionMeshJob(NodeNeighbors, nodesTransforms, nodesNeighbors, connectionsMeshVertices, connectionsMeshIndices); JobHandle calcConnectionMeshHandle = calcConnectionsMeshJob.Schedule(numNodes, 8); // do other required stuff before calling complete so we have actual parallelism MeshRenderer mr = Utils.GetOrAddComponent <MeshRenderer>(transform, out bool createdRenderer); mr.shadowCastingMode = ShadowCastingMode.Off; mr.sharedMaterial = nodeConnectionsMaterial; mr.lightProbeUsage = LightProbeUsage.Off; mr.reflectionProbeUsage = ReflectionProbeUsage.Off; mr.enabled = showNodesConnections; MeshFilter filter = Utils.GetOrAddComponent <MeshFilter>(transform, out bool createdFilter); filter.sharedMesh = connectionsMesh; // the nodes themselves nodeBatcher.Clear(); if (showNodes) { for (int i = 0; i < numNodes; i++) { NodeTransform nt = nodesTransforms[i]; NodeType nodeType = nodesTypes[i]; Color32 c; if (nodeType == NodeType.Invalid) { c = invalidNodeColor; } else if (nodeType == NodeType.OccupiedByObstacle) { c = nonWalkableNodeColor; } else { c = walkableNodeColor; } Vector3 pos = nt.Pos + (nt.Up * NodeVisualNormalOffset); Matrix4x4 trs = Matrix4x4.TRS(pos, nt.GetRotation(), Vector3.one); // batch each node quad debug nodeBatcher.AddItem(c, trs); } } calcConnectionMeshHandle.Complete(); // set the mesh using the results of the job connectionsMesh.SetVertices(calcConnectionsMeshJob.vertices); connectionsMesh.SetIndices(calcConnectionsMeshJob.indices, MeshTopology.Lines, 0); }