public bool CheckForBlock(Vector3 pos) { float gridSize = BuildManager.GetGridSize(); NodeTD targetNode = PathFinder.GetNearestNode(pos, nodeGraph); for (int i = 0; i < subPathList.Count; i++) { SubPath subPath = subPathList[i]; if (Vector3.Distance(pos, subPath.startN.pos) < gridSize / 2) { return(true); } if (Vector3.Distance(pos, subPath.endN.pos) < gridSize / 2) { return(true); } if (subPath.IsNodeInPath(targetNode)) { subPath.altPath = PathFinder.ForceSearch(subPath.startN, subPath.endN, targetNode, nodeGraph); if (subPath.altPath.Count == 0) { return(true); } } } nextBuildNode = targetNode; return(false); }
public List <Vector3> altPath = new List <Vector3>(); //for checking if there's any block public void Init(PlatformTD platform) { parentPlatform = platform; startN = PathFinder.GetNearestNode(connectStart.position, platform.GetNodeGraph()); endN = PathFinder.GetNearestNode(connectEnd.position, platform.GetNodeGraph()); path.Add((connectStart.position + connectEnd.position) / 2); SearchNewPath(platform.GetNodeGraph()); }
void ResetSubPath(SubPath platformSubPath) { if (dummyT == null) { dummyT = new GameObject().transform; } Quaternion rot = Quaternion.LookRotation(subPath[subWaypointID] - thisT.position); dummyT.rotation = rot; dummyT.position = thisT.position; Vector3 pos = dummyT.TransformPoint(0, 0, BuildManager.GetGridSize() / 2); NodeTD startN = PathFinder.GetNearestNode(pos, platformSubPath.parentPlatform.GetNodeGraph()); PathFinder.GetPath(startN, platformSubPath.endN, platformSubPath.parentPlatform.GetNodeGraph(), this.SetSubPath); }
public void BuildTower(Vector3 pos, UnitTower tower) { //pathfinding related code, only call if this platform is walkable; if (!walkable) { return; } if (tower.type != _TowerType.Mine) { NodeTD node = PathFinder.GetNearestNode(pos, nodeGraph); node.walkable = false; tower.SetPlatform(this, node); //if the node has been check before during CheckForBlock(), just use the altPath if (node == nextBuildNode) { for (int i = 0; i < subPathList.Count; i++) { if (subPathList[i].IsNodeInPath(node)) { subPathList[i].SwitchToSubPath(); } } return; } for (int i = 0; i < subPathList.Count; i++) { if (subPathList[i].IsNodeInPath(node)) { subPathList[i].SearchNewPath(nodeGraph); } } } }
public NodeTD GetNearestNode(Vector3 point) { return(PathFinder.GetNearestNode(point, nodeGraph)); }