コード例 #1
0
	private static List<Node> FindNeighbourNodes (Node initialNode, Environment envr, bool ignoreMovement) {
	
		List<Node> neighbours = new List<Node> (); 

		float initialX = initialNode.coords.x;
		float initialY = initialNode.coords.y;
		int posX = (int)initialX;
		int posY = (int)initialY;

		Node upNode = new Node (); 
		Node downNode = new Node (); 
		Node leftNode = new Node (); 
		Node rightNode = new Node ();

		if (envr.CanMoveTo (posX, posY + 1, Vector3.up, false, ignoreMovement)) {
			upNode.Initalise (new Vector2 (initialX, (initialY + 1))); 
			neighbours.Add (upNode);
		}
		if (envr.CanMoveTo (posX, posY - 1, Vector3.down, false, ignoreMovement)) {
			downNode.Initalise (new Vector2(initialX, (initialY-1) ) ); 
			neighbours.Add (downNode); 
		}
		if (envr.CanMoveTo (posX-1, posY, Vector3.left, false, ignoreMovement)) {
			leftNode.Initalise (new Vector2( (initialX-1), initialY ) ); 
			neighbours.Add (leftNode); 
		}
		if (envr.CanMoveTo (posX+1, posY, Vector3.right, false, ignoreMovement)) {
			rightNode.Initalise (new Vector2( (initialX+1), initialY ) ); 
			neighbours.Add (rightNode);
		}
		//neighbours = RemoveBadPoints (initialNode,neighbours);

		return neighbours;
	}