private void BuildNeighborMeshLinks(NavMeshGraph from, NavMeshGraph to, Vector3 direction) { if (to == null) { Debug.LogError("To Null"); return; } if (from == null) { Debug.LogError("From Null"); return; } Int3 valueInt3 = (Int3)( GetCorner(from) + new Vector3( Mathf.Max(0, direction.x), Mathf.Max(0, direction.y), Mathf.Max(0, direction.z)) ); //Debug.DrawLine(GetCorner(from) + Vector3.one * .5f, GetCorner(from) + Vector3.one * .5f + direction * .5f, Color.red, 10); fromNodes = new List <TriangleMeshNode>(); toNodes = new List <TriangleMeshNode>(); from.GetNodes(node => { if (NodeHas2VerticesTouchingEdge(node as TriangleMeshNode, direction, valueInt3)) { fromNodes.Add(node as TriangleMeshNode); } }); to.GetNodes(node => { if (NodeHas2VerticesTouchingEdge(node as TriangleMeshNode, direction, valueInt3)) { toNodes.Add(node as TriangleMeshNode); } }); uint cost = 1000; foreach (TriangleMeshNode fromNode in fromNodes) { foreach (TriangleMeshNode toNode in toNodes) { if (Vector3.Distance(fromNode.ClosestPointOnNode((Vector3)toNode.position), toNode.ClosestPointOnNode((Vector3)fromNode.position)) <= maxStitchableGap) { cost = (uint)(Int3.Precision * Vector3.Distance((Vector3)toNode.position, (Vector3)fromNode.position)); fromNode.AddConnection(toNode, cost); toNode.AddConnection(fromNode, cost); } } } }
private void UnstitchFromNeighbors(NavMeshGraph myGraph) { myGraph.GetNodes(node => RemoveOffGraphConnections(node)); }