// Token: 0x060026BB RID: 9915 RVA: 0x001AC704 File Offset: 0x001AA904 protected bool ValidateLine(GraphNode n1, GraphNode n2, Vector3 v1, Vector3 v2) { if (this.useRaycasting) { if (this.use2DPhysics) { if (this.thickRaycast && this.thickRaycastRadius > 0f && Physics2D.CircleCast(v1 + this.raycastOffset, this.thickRaycastRadius, v2 - v1, (v2 - v1).magnitude, this.mask)) { return(false); } if (Physics2D.Linecast(v1 + this.raycastOffset, v2 + this.raycastOffset, this.mask)) { return(false); } } else { if (this.thickRaycast && this.thickRaycastRadius > 0f && Physics.SphereCast(new Ray(v1 + this.raycastOffset, v2 - v1), this.thickRaycastRadius, (v2 - v1).magnitude, this.mask)) { return(false); } if (Physics.Linecast(v1 + this.raycastOffset, v2 + this.raycastOffset, this.mask)) { return(false); } } } if (this.useGraphRaycasting) { bool flag = n1 != null && n2 != null; if (n1 == null) { n1 = AstarPath.active.GetNearest(v1).node; } if (n2 == null) { n2 = AstarPath.active.GetNearest(v2).node; } if (n1 != null && n2 != null) { NavGraph graph = n1.Graph; NavGraph graph2 = n2.Graph; if (graph != graph2) { return(false); } IRaycastableGraph raycastableGraph = graph as IRaycastableGraph; GridGraph gridGraph = graph as GridGraph; if (flag && gridGraph != null) { return(!gridGraph.Linecast(n1 as GridNodeBase, n2 as GridNodeBase)); } if (raycastableGraph != null) { return(!raycastableGraph.Linecast(v1, v2, n1)); } } } return(true); }
/// <summary> /// Check if a straight path between v1 and v2 is valid. /// If both n1 and n2 are supplied it is assumed that the line goes from the center of n1 to the center of n2 and a more optimized graph linecast may be done. /// </summary> protected bool ValidateLine(GraphNode n1, GraphNode n2, Vector3 v1, Vector3 v2) { if (useRaycasting) { // Use raycasting to check if a straight path between v1 and v2 is valid if (use2DPhysics) { if (thickRaycast && thickRaycastRadius > 0 && Physics2D.CircleCast(v1 + raycastOffset, thickRaycastRadius, v2 - v1, (v2 - v1).magnitude, mask)) { return(false); } if (Physics2D.Linecast(v1 + raycastOffset, v2 + raycastOffset, mask)) { return(false); } } else { // Perform a thick raycast (if enabled) if (thickRaycast && thickRaycastRadius > 0 && Physics.SphereCast(new Ray(v1 + raycastOffset, v2 - v1), thickRaycastRadius, (v2 - v1).magnitude, mask)) { return(false); } // Perform a normal raycast // This is done even if a thick raycast is also done because thick raycasts do not report collisions for // colliders that overlapped the (imaginary) sphere at the origin of the thick raycast. // If this raycast was not done then some obstacles could be missed. if (Physics.Linecast(v1 + raycastOffset, v2 + raycastOffset, mask)) { return(false); } } } if (useGraphRaycasting) { bool betweenNodeCenters = n1 != null && n2 != null; if (n1 == null) { n1 = AstarPath.active.GetNearest(v1).node; } if (n2 == null) { n2 = AstarPath.active.GetNearest(v2).node; } if (n1 != null && n2 != null) { // Use graph raycasting to check if a straight path between v1 and v2 is valid NavGraph graph = n1.Graph; NavGraph graph2 = n2.Graph; if (graph != graph2) { return(false); } var rayGraph = graph as IRaycastableGraph; GridGraph gg = graph as GridGraph; if (betweenNodeCenters && gg != null) { // If the linecast is exactly between the centers of two nodes on a grid graph then a more optimized linecast can be used. // This method is also more stable when raycasting along a diagonal when the line just touches an obstacle. // The normal linecast method may or may not detect that as a hit depending on floating point errors // however this method never detect it as an obstacle (and that is very good for this component as it improves the simplification). return(!gg.Linecast(n1 as GridNodeBase, n2 as GridNodeBase)); } else if (rayGraph != null) { return(!rayGraph.Linecast(v1, v2, n1)); } } } return(true); }
/// <summary> /// Check if a straight path between v1 and v2 is valid. /// If both n1 and n2 are supplied it is assumed that the line goes from the center of n1 to the center of n2 and a more optimized graph linecast may be done. /// </summary> protected bool ValidateLine(GraphNode n1, GraphNode n2, Vector3 v1, Vector3 v2, System.Func <GraphNode, bool> filter, NNConstraint nnConstraint) { if (useRaycasting) { // Use raycasting to check if a straight path between v1 and v2 is valid if (use2DPhysics) { if (thickRaycast && thickRaycastRadius > 0 && Physics2D.CircleCast(v1 + raycastOffset, thickRaycastRadius, v2 - v1, (v2 - v1).magnitude, mask)) { return(false); } if (Physics2D.Linecast(v1 + raycastOffset, v2 + raycastOffset, mask)) { return(false); } } else { // Perform a normal raycast // This is done even if a thick raycast is also done because thick raycasts do not report collisions for // colliders that overlapped the (imaginary) sphere at the origin of the thick raycast. // If this raycast was not done then some obstacles could be missed. // This is done before the normal raycast for performance. // Normal raycasts are cheaper, so if it can be used to rule out a line earlier that's good. if (Physics.Linecast(v1 + raycastOffset, v2 + raycastOffset, mask)) { return(false); } // Perform a thick raycast (if enabled) if (thickRaycast && thickRaycastRadius > 0) { // Sphere cast doesn't detect collisions which are inside the start position of the sphere. // That's why we do an additional check sphere which is slightly ahead of the start and which will catch most // of these omissions. It's slightly ahead to avoid false positives that are actuall behind the agent. if (Physics.CheckSphere(v1 + raycastOffset + (v2 - v1).normalized * thickRaycastRadius, thickRaycastRadius, mask)) { return(false); } if (Physics.SphereCast(new Ray(v1 + raycastOffset, v2 - v1), thickRaycastRadius, (v2 - v1).magnitude, mask)) { return(false); } } } } if (useGraphRaycasting) { #if !ASTAR_NO_GRID_GRAPH bool betweenNodeCenters = n1 != null && n2 != null; #endif if (n1 == null) { n1 = AstarPath.active.GetNearest(v1, nnConstraint).node; } if (n2 == null) { n2 = AstarPath.active.GetNearest(v2, nnConstraint).node; } if (n1 != null && n2 != null) { // Use graph raycasting to check if a straight path between v1 and v2 is valid NavGraph graph = n1.Graph; NavGraph graph2 = n2.Graph; if (graph != graph2) { return(false); } var rayGraph = graph as IRaycastableGraph; #if !ASTAR_NO_GRID_GRAPH GridGraph gg = graph as GridGraph; if (betweenNodeCenters && gg != null) { // If the linecast is exactly between the centers of two nodes on a grid graph then a more optimized linecast can be used. // This method is also more stable when raycasting along a diagonal when the line just touches an obstacle. // The normal linecast method may or may not detect that as a hit depending on floating point errors // however this method never detect it as an obstacle (and that is very good for this component as it improves the simplification). return(!gg.Linecast(n1 as GridNodeBase, n2 as GridNodeBase, filter)); } else #endif if (rayGraph != null) { return(!rayGraph.Linecast(v1, v2, out GraphHitInfo _, null, filter)); } } } return(true); }