// Starts finding a path. The callback calls a method with the resulting path waypoints and success state. public void StartFindPath(Vector3 startPosition, Vector3 targetPosition, LayerMask allowedTerrain, Action <Waypoint[], PathStatus> callback) { Node startNode = _nodeNetwork.GetNodeFromWorldPosition(startPosition, allowedTerrain, true); Node targetNode = _nodeNetwork.GetNodeFromWorldPosition(targetPosition, int.MaxValue, true); if (startNode == null) { startNode = _nodeNetwork.GetShiftedNodeFromWorldPosition(startPosition, allowedTerrain, false); } StartFindPath(startNode, targetNode, allowedTerrain, callback); //StartCoroutine(FindPath(startPosition, targetPosition, allowedTerrain, callback, false)); }
/// <summary> /// Finds the nodes this gameobject overlaps, modifies their layer to the specified layer and returns all the nodes modified. /// </summary> /// <param name="nodeNetwork">NodeNetwork which will be modified</param> /// <param name="layer">The nodes their new layer</param> /// <returns>List of all modified nodes</returns> protected virtual List <Node> CreateCustomNodeNetwork(NodeNetwork nodeNetwork, int layer) { float spacing = nodeNetwork.Spacing; int innerNetworkSizeX = Mathf.Max(Mathf.RoundToInt(((transform.localScale.x)) / spacing), 1); int innerNetworkSizeY = Mathf.Max(Mathf.RoundToInt(((transform.localScale.y)) / spacing), 1); Vector3 size = new Vector3((transform.localScale.x), (transform.localScale.y), 0); Vector3 worldBottomLeft = transform.position - (size / 2); List <Node> innerNetworkNodes = new List <Node>(); for (int x = 0; x <= innerNetworkSizeX + 0; x++) { for (int y = 0; y <= innerNetworkSizeY; y++) { Vector3 worldPosition = worldBottomLeft + new Vector3(x * spacing, y * spacing, nodeNetwork.transform.position.z); Node node = nodeNetwork.GetNodeFromWorldPosition(worldPosition, int.MaxValue, true); if (node.LayerValue == NodeNetwork.UnwalkableLayer) { continue; } if (!innerNetworkNodes.Contains(node) && node.WorldPosition.z >= transform.position.z) { nodeNetwork.MofidyNode(node, layer); innerNetworkNodes.Add(node); } } } return(innerNetworkNodes); }