public void CardinalNeighboursTest() { Node node = currNodeGrid.GetNodeFromVector2(new Vector2(NodeMeasures.NODE_DIAMETER * 5, NodeMeasures.NODE_DIAMETER * 5) + (Vector2)currNodeGrid.transform.position); List <Node> neighbours = currNodeGrid.GetCardinalNeighbours(node); Assert.IsTrue(neighbours.Count == 4); // manually check that each neighbour has the correct x and y coords Assert.IsTrue(neighbours[0].Data.x == node.Data.x - 1 && neighbours[0].Data.y == node.Data.y); Assert.IsTrue(neighbours[1].Data.x == node.Data.x + 1 && neighbours[1].Data.y == node.Data.y); Assert.IsTrue(neighbours[2].Data.x == node.Data.x && neighbours[2].Data.y == node.Data.y - 1); Assert.IsTrue(neighbours[3].Data.x == node.Data.x && neighbours[3].Data.y == node.Data.y + 1); }
private void TriggerAnimation(INodeData curr, INodeData end, bool succesful) { if (succesful) { // if we have planted return if (CheckForPlanting()) { return; } } else { // if the pathfinding failed because the end node wasnt walkable if (end != null && !end.Data.IsWalkable) { bool isNeighbour = nodeGrid.GetCardinalNeighbours(curr).Contains((Node)end); // if the node is in the vicinity of the player and the player is not moving on a path if (!pathFind.HasPath() && isNeighbour) { animator.SetBool(WALKING_ANIM, false); // if target node didnt change thats fine because the player will continue to look in the same direction. pathFind.ChangeDir(end.Data.pos); // if the tool cannot affect the node ahead dont use tool if (!toolHandler.GetToolToUse().CanAffectNodeAhead) { return; } } else { return; } } else { return; } } ChooseAnimation(toolHandler.ToolToUse); }