public PathFindingNode CreatePathNode(Vector3 _checkLoc) { PathDataNode idealNode = null; float prevdist = 10000000f; foreach (var node in PDM.pathDataList) { var dist = Vector3.Distance(_checkLoc, node.worldLocation); if (prevdist > dist) { prevdist = dist; idealNode = node; } } if (idealNode == null) { return(null); } else { var PathFindNode = new PathFindingNode(idealNode, 0, 0); return(PathFindNode); } // create a pathdata node on the clsoest node to the player. }
// Update is called once per frame private void ProcGen() { if (targetTexture2D != null) { for (int yIndex = 0; yIndex < targetTexture2D.height; ++yIndex) { for (int xIndex = 0; xIndex < targetTexture2D.width; ++xIndex) { int index = yIndex * targetTexture2D.width + xIndex; var pixelColour = pix[index]; //Make the nodes attached to a particular object //spawn them //If the Local vector2's are not null continue through the loop. ////Make a pathdata manager start. //if(pixelColour == startNodeColour) //{ // startPoint = new Vector2(xIndex, yIndex); //} //else if(pixelColour == endNodeColour) //{ // endPoint = new Vector2(xIndex, yIndex); //} Vector3 spawnPoint = startNode.transform.position; spawnPoint.x += (xIndex - startNodeMarkerLoc.x) * pixelToWorldScale.x; spawnPoint.z += (yIndex - startNodeMarkerLoc.z) * pixelToWorldScale.z; // for each pixel on the texture if (pixelColour == highPriorityPassableColour) { PathDataNode Node = new PathDataNode(spawnPoint, new Vector2Int(xIndex, yIndex), PathDataNode.NodeType.HighPriority); pathDataNodeList.Add(Node); } else if (pixelColour == lowPriorityPassableColour) { PathDataNode Node = new PathDataNode(spawnPoint, new Vector2Int(xIndex, yIndex), PathDataNode.NodeType.HighPriority); pathDataNodeList.Add(Node); } else if (pixelColour == unpassableColour) { PathDataNode Node = new PathDataNode(spawnPoint, new Vector2Int(xIndex, yIndex), PathDataNode.NodeType.HighPriority); pathDataNodeList.Add(Node); } else { PathDataNode Node = new PathDataNode(spawnPoint, new Vector2Int(xIndex, yIndex), PathDataNode.NodeType.UnPassable); pathDataNodeList.Add(Node); } // add a node based on colour } } pathDataManager.pathDataList = pathDataNodeList; Debug.Log("pathdata list" + pathDataNodeList.Count); //return the list } }
public bool ClosedListCheck(List <PathFindingNode> closedlist, PathDataNode checkNode) { foreach (var node in closedlist) { if (checkNode == node.Node) { return(true); } } return(false); //check if it is in the on the closed list }
public bool OpenListCheck(List <PathFindingNode> openlist, PathDataNode checkNode, List <PathFindingNode> Neighbours) { foreach (var node in openlist) { if (checkNode == node.Node) { Neighbours.Add(node); return(true); } } return(false); //cehck if it is in the open list }
// variables public PathFindingNode(PathDataNode _node, float _gcost, float _hcost) { Node = _node; gCost = _gcost; hCost = _hcost; }