//public void FindPathOnButtonPress() { // List<PathPoint> listje = pathfindingNodeManager.ReturnNavPointList(); // PathPoint toFind = listje[Random.Range(0, listje.Count)]; // PathPoint start = listje[Random.Range(0, listje.Count)]; // if(toFind.GetNode != PathfindNode.Nonwalkable && start.GetNode != PathfindNode.Nonwalkable) { // pathfinder.FindPath(start.GetPosition, toFind.GetPosition); // } // else { // FindPathOnButtonPress(); // } //} private void OnDrawGizmos() { if (showPath) { pathfindingNodeManager = PathfindingNodeManager.Instance; if (pathfindingNodeManager.ReturnNavPointList().Count > 0) //If the grid is not empty { foreach (PathPoint n in pathfindingNodeManager.ReturnNavPointList()) //Loop through every node in the grid { if (n.GetNode == PathfindNode.Nonwalkable) //If the current node is a wall node { Gizmos.color = Color.white; //Set the color of the node } else { Gizmos.color = Color.yellow;//Set the color of the node } if (pathfindingNodeManager.FinalPath != null) //If the final path is not empty { if (pathfindingNodeManager.FinalPath.Contains(n)) //If the current node is in the final path { Gizmos.color = Color.red; //Set the color of that node } } Gizmos.DrawCube(new Vector3(n.GetPosition.x, 0, n.GetPosition.y), new Vector3(.3f, .3f, .3f));//Draw the node at the position of the node. } } } }
private void InitSettings(int storeNumber) { tiles = Tiles.Instance; objectSpawner = ObjectSpawner.Instance; pathfindingNodeManager = PathfindingNodeManager.Instance; stepsSize = (1 / tiles.gridSize); gridSize = tiles.gridSize; gridPercentage = (1 / gridSize); registers = Resources.LoadAll <GameObject>("Register"); pointsInRoom = new List <PathPoint>(); foreach (PathPoint point in pathfindingNodeManager.ReturnNavPointList()) { if (point.GetStoreNumber == storeNumber) { pointsInRoom.Add(point); } } stores = tiles.GetStoreSpaces; currentStore = stores[storeNumber]; storeSize = currentStore.GetHeightWidthofRoom; storeDecoration = Resources.LoadAll <GameObject>("StoreDecoration"); }
public void SetPathfinderGridValues() { List <PathPoint> points = pathfindingNodeManager.ReturnNavPointList(); PathPoint neighbour; Vector2 pointPosition; foreach (PathPoint pnt in points) { if (pnt.GetNode != PathfindNode.Outside) { if (pnt.GetNode == PathfindNode.Door) { //pnt.SetNode = PathfindNode.Walkable; continue; } if (pnt == null) { continue; } pointPosition = pnt.GetPosition; float xx = pointPosition.x; float yy = pointPosition.y; float gridStepSize = 1 / gridSize; xx -= gridStepSize; yy -= gridStepSize; for (int x = 0; x < gridSize; x++) { for (int y = 0; y < gridSize; y++) { neighbour = pathfindingNodeManager.GetPathPoint(new Vector2(xx, yy)); if (neighbour == null) { pnt.SetNode = PathfindNode.Nonwalkable; } else if (neighbour.GetNode == PathfindNode.None || neighbour.GetStoreNumber != pnt.GetStoreNumber) { pnt.SetNode = PathfindNode.Nonwalkable; } yy += gridStepSize; } xx += gridStepSize; yy = pointPosition.y; yy -= gridStepSize; } } else if (pnt.GetNode == PathfindNode.Outside) { if (pnt == null) { continue; } pointPosition = pnt.GetPosition; float xx = pointPosition.x; float yy = pointPosition.y; xx -= 1; yy -= 1; for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { neighbour = pathfindingNodeManager.GetPathPoint(new Vector2(xx, yy)); if (neighbour == null) { pnt.SetNode = PathfindNode.Nonwalkable; } else if (neighbour.GetNode == PathfindNode.None || neighbour.GetStoreNumber != pnt.GetStoreNumber) { pnt.SetNode = PathfindNode.Nonwalkable; } yy += 1; } xx += 1; yy = pointPosition.y; yy -= 1; } } } }