bool AreAdjacentTilesBlocked(NavNode node, int offsetX, int offsetY) { Vector3Int adjIndex = new Vector3Int(node.GetIndex().x + offsetX, currentNavWrapper.node.GetIndex().y, Controls.GetTileZpf()); NavNode adjNode = pf.GetNode(adjIndex); if (adjNode == null || adjNode.IsBlocked()) { return(true); } adjIndex.x -= offsetX; adjIndex.y += offsetY; adjNode = pf.GetNode(adjIndex); if (adjNode == null || adjNode.IsBlocked()) { return(true); } return(false); }
// Gets the next point in the path point list based on the passed in index. // This point is returned by reference as a world position (nextPoint). Returns true if there is a valid next point. // If it reaches the end or the path has failed it returns false. // If the next point in the point list is blocked a new path is generated. public bool GetNextPointIndex(ref Vector3 nextPoint, ref int index) { //TODO make it so we can check multiple points ahead to regenerate a path if //there is a blockage coming sooner than the very next node // We couldn't generate a path OR we are still waiting for the path to be generated. if (!IsGenerated()) { return(false); } index++; if (index < pathpoints.Count) { // Check to see if this node is blocked at this point. Vector3 worldpos = GetPathPointWorld(index); NavNode node = pf.GetNode(worldpos); if (node.IsBlocked()) { // Create a new path if the previous path is no longe usuable. if (isdynamicflag) { CreatePath(GetPathPointWorld(index - 1), endpos, searchWithDiagonals, true); } else { CreatePath(startpos, endpos, searchWithDiagonals, false); } return(false); } else { // We successfully found the next point. nextPoint = worldpos; return(true); } } // We reached the end of our path. return(false); }
// Gets the previous point in the path point list based on the passed in index. // This point is returned by reference as a world position (previousPoint). Returns true if there is a valid next point. // If it reaches the end or the path has failed it returns false. // If the next point in the point list is blocked a new path is generated. public bool GetPreviousPointIndex(ref Vector3 previousPoint, ref int index) { // We couldn't generate a path OR we are still waiting for a path. if (!IsGenerated()) { return(false); } index--; if (index >= 0) { // Check to see if this node is blocked at this point. Vector3 worldpos = GetPathPointWorld(index); NavNode node = pf.GetNode(worldpos); if (node.IsBlocked()) // Create a new path if the previous path is no longer usuable. { if (isdynamicflag) { CreatePath(GetPathPointWorld(index + 1), startpos, searchWithDiagonals, true); } else { CreatePath(endpos, startpos, searchWithDiagonals, false); } return(false); } else { previousPoint = worldpos; return(true); } } return(false); }