Ejemplo n.º 1
0
		private static bool isNodeInOpen (node node)
		{
			int fCost = node.fCost;
			List<node> nodeList = null;
			if (open.TryGetValue (fCost, out nodeList)) {
				if (nodeList.Contains (node)) {
					return true;	
				}
			}
			return false;
		}
Ejemplo n.º 2
0
		private static void addNodeToOpen (node node)
		{
			int fCost = node.fCost;
			List<node> nodeList = null;
			if (open.TryGetValue (fCost, out nodeList)) {
				nodeList.Add (node);
				open [fCost] = nodeList;
			} else {
				nodeList = new List<node> ();
				nodeList.Add (node);
				open.Add (fCost, nodeList);
			}
		}
Ejemplo n.º 3
0
		private static void removeNodeFromOpen (node node)
		{
			int fCost = node.fCost;
			List<node> nodeList = null;
			if (open.TryGetValue (fCost, out nodeList)) {
				nodeList.RemoveAt (0);
				if (nodeList.Count == 0) {
					open.Remove (fCost);
				} else {
					open [fCost] = nodeList;
				}

			}
		}
Ejemplo n.º 4
0
		public node (Vector3 Position, bool Walkable, int HCost=int.MaxValue, int GCost=int.MaxValue, node Parent=null)
		{ 
			pos = Position;
			walkable = Walkable;
			hCost = HCost;
			gCost = GCost;
			parent = Parent;
		}
Ejemplo n.º 5
0
		private static List<node> getNeighbours (node n, Vector3 Origin, Vector3 Target)
		{
			List<node> nList = new List<node> ();
			Vector3 tPos = n.pos;
			//
			for (int y =-1; y<= 1; y++) {
				for (int x =-1; x<= 1; x++) {
					for (int z =-1; z<= 1; z++) {
						int ny = (int)tPos.y + y;
						int nx = (int)tPos.x + x;
						int nz = (int)tPos.z + z;
						if (ny < 0 || ny > GridHeight)
							continue;
						if (nx < 0 || nx > GridWidth)
							continue;
						if (nz < 0 || nz > GridDepth)
							continue;
						if (y == 0 && x == 0 && z == 0)
							continue;
						//Debug.Log (new Vector3(x,y,z));
						node curNode = null;
						Grid.TryGetValue (new Vector3 (nx, ny, nz), out curNode);
						if (curNode != null) {	
							nList.Add (curNode);
							//Debug.Log (nList[nList.Count-1].gCost);						
						}
					}
				}
			}

			//Debug.Log ("");
			return nList;
		
		}
Ejemplo n.º 6
0
		private static List<node> getPathFromNode (node Node)
		{
			node curNode = Node;
			List<node> list = new List<node> ();
			while (curNode.parent !=null) {
				list.Insert (0, curNode);
				//Debug.Log (curNode.pos);
				curNode = curNode.parent;
			}
			return list;
		}