public void GetNodeFromVector2Test() { // get a node Node node_1 = currNodeGrid.GetNodeFromVector2(new Vector2(NodeMeasures.NODE_DIAMETER - 0.05f, NodeMeasures.NODE_DIAMETER - 0.05f) + (Vector2)currNodeGrid.transform.position); // make sure the node obtained is the correct node Assert.AreEqual(0, node_1.Data.x); Assert.AreEqual(0, node_1.Data.y); Node node_2 = currNodeGrid.GetNodeFromVector2(new Vector2(NodeMeasures.NODE_DIAMETER * 6 - 0.05f, NodeMeasures.NODE_DIAMETER * 8 - 0.05f) + (Vector2)currNodeGrid.transform.position); Assert.AreEqual(5, node_2.Data.x); Assert.AreEqual(7, node_2.Data.y); Node node_3 = currNodeGrid.GetNodeFromVector2(new Vector2(NodeMeasures.NODE_DIAMETER * 6 + 0.05f, NodeMeasures.NODE_DIAMETER * 8 + 0.05f) + (Vector2)currNodeGrid.transform.position); Assert.AreEqual(6, node_3.Data.x); Assert.AreEqual(8, node_3.Data.y); Node node_4 = currNodeGrid.GetNodeFromVector2(new Vector2(NodeMeasures.NODE_DIAMETER * 25, NodeMeasures.NODE_DIAMETER * 22) + (Vector2)currNodeGrid.transform.position); Assert.AreEqual(25, node_4.Data.x); Assert.AreEqual(22, node_4.Data.y); }
public void RequestPath() { Node start = nodeGrid.GetNodeFromVector2(transform.position); Node end = nodeGrid.GetNodeFromMousePosition(); // store end node to pass onfailure and onArrival endNodeData = end; if (start == null || end == null) { return; } currentRequest = new PathRequest(Guid.NewGuid().ToString(), start, end, PathFindCallBack); requestManager.RequestPath(currentRequest); ProcessingPath = true; }
private void InitNodeInfo() { middleNode = nodeGrid.GetNodeFromVector2(transform.position); X = middleNode.Data.x; Y = middleNode.Data.y; // store the nodes interactable that we will replace prevInteractable = middleNode.Interactable; middleNode.Interactable = this; nodesToWater = nodeGrid.GetNodesFromDimensions(middleNode, xWaterDim, yWaterDim); }
public IEnumerator AStarPathFindingNoBlocksTest() { float xStart = NodeMeasures.NODE_DIAMETER * 5; float yStart = NodeMeasures.NODE_DIAMETER * 5; float xEnd = NodeMeasures.NODE_DIAMETER * 1; float yEnd = NodeMeasures.NODE_DIAMETER * 2; // 5 * i i i i S // 4 * i * * * * // 3 * i * * * * // 2 * E * * * * // 1 * * * * * * // 0 * * * * * * // 0 0 1 2 3 4 5 var start = new Vector2(xStart, yStart); var end = new Vector2(xEnd, yEnd); Node startNode = currNodeGrid.GetNodeFromVector2(start); Node endNode = currNodeGrid.GetNodeFromVector2(end); Vector2[] path = null; PathRequest request = new PathRequest("test", startNode, endNode, (Vector2[] _path, bool foundPath) => { path = _path; Assert.IsTrue(foundPath); }); currRequestManager.RequestPath(request); yield return(new WaitForSeconds(0.1f)); Assert.NotNull(path); Assert.AreEqual(7, currNodeGrid.GetManhattanDistance(startNode, endNode)); Assert.AreEqual(7, path.Length); }
private void Start() { grid = FindObjectOfType <NodeGrid>(); nodeData = grid.GetNodeFromVector2(transform.position); CheckNeedWater(); }