internal void Destroy() { if (this.nodes.Length > 0) { int tileIndex = NavmeshBase.GetTileIndex(this.nodes[0].GetVertexIndex(0)); uint graphIndex = this.nodes[0].GraphIndex; for (int i = 0; i < this.nodes.Length; i++) { TriangleMeshNode triangleMeshNode = this.nodes[i]; if (triangleMeshNode.connections != null) { for (int j = 0; j < triangleMeshNode.connections.Length; j++) { TriangleMeshNode triangleMeshNode2 = triangleMeshNode.connections[j].node as TriangleMeshNode; if (triangleMeshNode2 != null && triangleMeshNode2.GraphIndex == graphIndex && NavmeshBase.GetTileIndex(triangleMeshNode2.GetVertexIndex(0)) == tileIndex) { triangleMeshNode.connections[j].node = null; } } } } for (int k = 0; k < this.nodes.Length; k++) { this.nodes[k].Destroy(); } } this.nodes = null; ObjectPool <BBTree> .Release(ref this.bbTree); }
internal void Destroy() { if (nodes.Length > 0) { // Get this tile's index from the first node var tileIndex = NavmeshBase.GetTileIndex(nodes[0].GetVertexIndex(0)); var graphIndex = nodes[0].GraphIndex; // Destroy the nodes // To avoid removing connections one by one, which is very inefficient // we set all connections to other nodes in the same tile to null since // we already know that their connections will be destroyed as well. // This reduces the time it takes to destroy the nodes by approximately 50% for (int i = 0; i < nodes.Length; i++) { var node = nodes[i]; if (node.connections != null) { for (int j = 0; j < node.connections.Length; j++) { var otherMesh = node.connections[j].node as TriangleMeshNode; // Check if the nodes are in the same graph and the same tile if (otherMesh != null && otherMesh.GraphIndex == graphIndex && NavmeshBase.GetTileIndex(otherMesh.GetVertexIndex(0)) == tileIndex) { node.connections[j].node = null; } } } } // This will also remove old connections for (int i = 0; i < nodes.Length; i++) { nodes[i].Destroy(); } } nodes = null; graph = null; ObjectPool <BBTree> .Release(ref bbTree); }