当前位置: 首页>>代码示例>>C#>>正文


C# Pathfinding.GraphNode类代码示例

本文整理汇总了C#中Pathfinding.GraphNode的典型用法代码示例。如果您正苦于以下问题:C# GraphNode类的具体用法?C# GraphNode怎么用?C# GraphNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GraphNode类属于Pathfinding命名空间,在下文中一共展示了GraphNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetOther

		public GraphNode GetOther ( GraphNode a ) {
			
			if ( this.connections.Length < 2 ) return null;
			if ( this.connections.Length != 2 ) throw new System.Exception ("Invalid NodeLink3Node. Expected 2 connections, found " + this.connections.Length);
			
			return a == connections[0] ? (connections[1] as NodeLink3Node).GetOtherInternal(this) : (connections[0] as NodeLink3Node).GetOtherInternal(this);
		}
开发者ID:henryj41043,项目名称:TheUnseen,代码行数:7,代码来源:NodeLink3.cs

示例2: GetReachableNodes

		/** Returns all nodes reachable from the seed node.
		 * This function performs a BFS (breadth-first-search) or flood fill of the graph and returns all nodes which can be reached from
		 * the seed node. In almost all cases this will be identical to returning all nodes which have the same area as the seed node.
		 * In the editor areas are displayed as different colors of the nodes.
		 * The only case where it will not be so is when there is a one way path from some part of the area to the seed node
		 * but no path from the seed node to that part of the graph.
		 * 
		 * The returned list is sorted by node distance from the seed node
		 * i.e distance is measured in the number of nodes the shortest path from \a seed to that node would pass through.
		 * Note that the distance measurement does not take heuristics, penalties or tag penalties.
		 * 
		 * Depending on the number of reachable nodes, this function can take quite some time to calculate
		 * so don't use it too often or it might affect the framerate of your game.
		 * 
		 * \param seed The node to start the search from
		 * \param tagMask Optional mask for tags. This is a bitmask.
		 * 
		 * \returns A List<Node> containing all nodes reachable from the seed node.
		 * For better memory management the returned list should be pooled, see Pathfinding.Util.ListPool
		 */
		public static List<GraphNode> GetReachableNodes (GraphNode seed, int tagMask = -1) {
			Stack<GraphNode> stack = Pathfinding.Util.StackPool<GraphNode>.Claim ();
			List<GraphNode> list = Pathfinding.Util.ListPool<GraphNode>.Claim ();
			
			
			HashSet<GraphNode> map = new HashSet<GraphNode>();
			
			GraphNodeDelegate callback;
			if (tagMask == -1) {
				callback = delegate (GraphNode node) {
					if (node.Walkable && map.Add (node)) {
						list.Add (node);
						stack.Push (node);
					}
				};
			} else {
				callback = delegate (GraphNode node) {
					if (node.Walkable && ((tagMask >> (int)node.Tag) & 0x1) != 0 && map.Add (node)) {
						list.Add (node);
						stack.Push (node);
					}
				};
			}
			
			callback (seed);
			
			while (stack.Count > 0) {
				stack.Pop ().GetConnections (callback);
			}
			
			Pathfinding.Util.StackPool<GraphNode>.Release (stack);
			
			return list;
		}
开发者ID:JohnMai,项目名称:WhiteSharks,代码行数:54,代码来源:PathUtilities.cs

示例3: GetReachableNodes

		/** Returns all nodes reachable from the seed node.
		 * This function performs a BFS (breadth-first-search) or flood fill of the graph and returns all nodes which can be reached from
		 * the seed node. In almost all cases this will be identical to returning all nodes which have the same area as the seed node.
		 * In the editor areas are displayed as different colors of the nodes.
		 * The only case where it will not be so is when there is a one way path from some part of the area to the seed node
		 * but no path from the seed node to that part of the graph.
		 * 
		 * The returned list is sorted by node distance from the seed node
		 * i.e distance is measured in the number of nodes the shortest path from \a seed to that node would pass through.
		 * Note that the distance measurement does not take heuristics, penalties or tag penalties.
		 * 
		 * Depending on the number of reachable nodes, this function can take quite some time to calculate
		 * so don't use it too often or it might affect the framerate of your game.
		 * 
		 * \param seed The node to start the search from
		 * \param tagMask Optional mask for tags. This is a bitmask.
		 * 
		 * \returns A List<Node> containing all nodes reachable from the seed node.
		 * For better memory management the returned list should be pooled, see Pathfinding.Util.ListPool
		 */
		public static List<GraphNode> GetReachableNodes (GraphNode seed, int tagMask = -1) {
			var stack = StackPool<GraphNode>.Claim ();
			var list = ListPool<GraphNode>.Claim ();
			
			/** \todo Pool */
			var map = new HashSet<GraphNode>();
			
			GraphNodeDelegate callback;
			if (tagMask == -1) {
				callback = delegate (GraphNode node) {
					if (node.Walkable && map.Add (node)) {
						list.Add (node);
						stack.Push (node);
					}
				};
			} else {
				callback = delegate (GraphNode node) {
					if (node.Walkable && ((tagMask >> (int)node.Tag) & 0x1) != 0 && map.Add (node)) {
						list.Add (node);
						stack.Push (node);
					}
				};
			}
			
			callback (seed);
			
			while (stack.Count > 0) {
				stack.Pop ().GetConnections (callback);
			}
			
			StackPool<GraphNode>.Release (stack);
			
			return list;
		}
开发者ID:Marchys,项目名称:fanalet,代码行数:54,代码来源:PathUtilities.cs

示例4: Construct

		public static FloodPath Construct (GraphNode start, OnPathDelegate callback = null) {
			if (start == null) throw new ArgumentNullException("start");

			var p = PathPool.GetPath<FloodPath>();
			p.Setup(start, callback);
			return p;
		}
开发者ID:Alx666,项目名称:ProjectPhoenix,代码行数:7,代码来源:FloodPath.cs

示例5: AddConnection

		/** Add a connection from this node to the specified node.
		 * If the connection already exists, the cost will simply be updated and
		 * no extra connection added.
		 * 
		 * \note Only adds a one-way connection. Consider calling the same function on the other node
		 * to get a two-way connection.
		 */
		public override void AddConnection (GraphNode node, uint cost) {
			
			if (connections != null) { 
				for (int i=0;i<connections.Length;i++) {
					if (connections[i] == node) {
						connectionCosts[i] = cost;
						return;
					}
				}
			}
			
			int connLength = connections != null ? connections.Length : 0;
			
			GraphNode[] newconns = new GraphNode[connLength+1];
			uint[] newconncosts = new uint[connLength+1];
			for (int i=0;i<connLength;i++) {
				newconns[i] = connections[i];
				newconncosts[i] = connectionCosts[i];
			}
			
			newconns[connLength] = node;
			newconncosts[connLength] = cost;
			
			connections = newconns;
			connectionCosts = newconncosts;
		}
开发者ID:Bjeck,项目名称:BM-RTS-game,代码行数:33,代码来源:PointNode.cs

示例6: GetPortal

		public override bool GetPortal (GraphNode other, List<Vector3> left, List<Vector3> right, bool backwards)
		{
			
			if ( this.connections.Length < 2 ) return false;
			
			if ( this.connections.Length != 2 ) throw new System.Exception ("Invalid NodeLink3Node. Expected 2 connections, found " + this.connections.Length);
			
			//if ( other != connections[0] || other != connections[1] ) return false;
			
			if ( left != null ) {
				//Debug.DrawLine ( portalA, portalB, Color.red);
				left.Add ( portalA );
				right.Add ( portalB );
				/*
				Vector3 normal = link.transform.forward;
				Vector3 tangent = Vector3.Dot (normal, (Vector3)(other.Position - this.Position) ) > 0 ? link.transform.right*0.5f : -link.transform.right*0.5f;
				
				Debug.DrawLine ( link.transform.position -tangent * link.portalWidth, link.transform.position +tangent * link.portalWidth, Color.red);
				
				Debug.DrawRay ( link.transform.position -tangent * link.portalWidth, Vector3.up*5, Color.red);
				Debug.Break ();
				left.Add ( link.transform.position -tangent * link.portalWidth );
				right.Add (link.transform.position +tangent * link.portalWidth );*/
			}
			
			return true;
		}
开发者ID:henryj41043,项目名称:TheUnseen,代码行数:27,代码来源:NodeLink3.cs

示例7: AddConnection

 public override void AddConnection(GraphNode node, uint cost)
 {
     if (this.connections != null)
     {
         for (int i = 0; i < this.connections.Length; i++)
         {
             if (this.connections[i] == node)
             {
                 this.connectionCosts[i] = cost;
                 return;
             }
         }
     }
     int num = (this.connections == null) ? 0 : this.connections.Length;
     GraphNode[] array = new GraphNode[num + 1];
     uint[] array2 = new uint[num + 1];
     for (int j = 0; j < num; j++)
     {
         array[j] = this.connections[j];
         array2[j] = this.connectionCosts[j];
     }
     array[num] = node;
     array2[num] = cost;
     this.connections = array;
     this.connectionCosts = array2;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:26,代码来源:PointNode.cs

示例8: GraphUpdateObject

		/** Updates graphs and checks if all nodes are still reachable from each other.
		 * Graphs are updated, then a check is made to see if the nodes are still reachable from each other.
		 * If they are not, the graphs are reverted to before the update and \a false is returned.\n
		 * This is slower than a normal graph update.
		 * All queued graph updates and thread safe callbacks will be flushed during this function.
		 *
		 * \note This might return true for small areas even if there is no possible path if AstarPath.minAreaSize is greater than zero (0).
		 * So when using this, it is recommended to set AstarPath.minAreaSize to 0 (A* Inspector -> Settings -> Pathfinding)
		 *
		 * \param guo The GraphUpdateObject to update the graphs with
		 * \param node1 Node which should have a valid path to \a node2. All nodes should be walkable or \a false will be returned.
		 * \param node2 Node which should have a valid path to \a node1. All nodes should be walkable or \a false will be returned.
		 * \param alwaysRevert If true, reverts the graphs to the old state even if no blocking ocurred
		 *
		 * \returns True if the given nodes are still reachable from each other after the \a guo has been applied. False otherwise.
		 *
\code
var guo = new GraphUpdateObject (tower.GetComponent<Collider>.bounds);
var spawnPointNode = AstarPath.active.GetNearest (spawnPoint.position).node;
var goalNode = AstarPath.active.GetNearest (goalNode.position).node;
if (GraphUpdateUtilities.UpdateGraphsNoBlock (guo, spawnPointNode, goalNode, false)) {
	// Valid tower position
	// Since the last parameter (which is called "alwaysRevert") in the method call was false
	// The graph is now updated and the game can just continue
} else {
	// Invalid tower position. It blocks the path between the spawn point and the goal
	// The effect on the graph has been reverted
	Destroy (tower);
}
\endcode
		 */
		public static bool UpdateGraphsNoBlock (GraphUpdateObject guo, GraphNode node1, GraphNode node2, bool alwaysRevert = false) {
			List<GraphNode> buffer = ListPool<GraphNode>.Claim ();
			buffer.Add (node1);
			buffer.Add (node2);
			bool worked = UpdateGraphsNoBlock (guo, buffer, alwaysRevert);
			ListPool<GraphNode>.Release (buffer);
			return worked;
		}
开发者ID:legionaryu,项目名称:Atom-defender,代码行数:39,代码来源:GraphUpdateUtilities.cs

示例9: Add

		/** Adds a node to the heap */
		public void Add(GraphNode node) {
			
			if (node == null) {
				Debug.Log ("Sending null node to BinaryHeap");
				return;
			}
			
			if (numberOfItems == binaryHeap.Length) {
				Debug.Log ("Forced to discard nodes because of binary heap size limit, please consider increasing the size ("+numberOfItems +" "+binaryHeap.Length+")");
				numberOfItems--;
			}
			
			binaryHeap[numberOfItems] = node;
			//node.heapIndex = numberOfItems;//Heap index
			
			int bubbleIndex = numberOfItems;
			uint nodeF = node.f;
			
			while (bubbleIndex != 1) {
				int parentIndex = bubbleIndex / 2;
				
				/*if (binaryHeap[parentIndex] == null) {
					Debug.Log ("WUT!!");
					return;
				}*/
				
				if (nodeF <= binaryHeap[parentIndex].f) {
				   
					//binaryHeap[bubbleIndex].f <= binaryHeap[parentIndex].f) { /** \todo Wouldn't it be more efficient with '<' instead of '<=' ? * /
					//Node tmpValue = binaryHeap[parentIndex];
					
					//tmpValue.heapIndex = bubbleIndex;//HeapIndex
					
					binaryHeap[bubbleIndex] = binaryHeap[parentIndex];
					binaryHeap[parentIndex] = node;//binaryHeap[bubbleIndex];
					
					//binaryHeap[bubbleIndex].heapIndex = bubbleIndex; //Heap index
					//binaryHeap[parentIndex].heapIndex = parentIndex; //Heap index
					
					bubbleIndex = parentIndex;
				} else {
				/*if (binaryHeap[bubbleIndex].f <= binaryHeap[parentIndex].f) { /** \todo Wouldn't it be more efficient with '<' instead of '<=' ? *
					Node tmpValue = binaryHeap[parentIndex];
					
					//tmpValue.heapIndex = bubbleIndex;//HeapIndex
					
					
					binaryHeap[parentIndex] = binaryHeap[bubbleIndex];
					binaryHeap[bubbleIndex] = tmpValue;
					
					bubbleIndex = parentIndex;
				} else {*/
					break;
				}
			}
								 
			numberOfItems++;
		}
开发者ID:JoseRego,项目名称:summer-rush,代码行数:59,代码来源:BinaryHeap.cs

示例10: InSearchTree

 public static bool InSearchTree(GraphNode node, Path path)
 {
     if (path == null || path.pathHandler == null)
     {
         return true;
     }
     PathNode pathNode = path.pathHandler.GetPathNode(node);
     return pathNode.pathID == path.pathID;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:9,代码来源:NavGraph.cs

示例11: ContainsConnection

 public override bool ContainsConnection(GraphNode node)
 {
     for (int i = 0; i < this.connections.Length; i++)
     {
         if (this.connections[i] == node)
         {
             return true;
         }
     }
     return false;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:11,代码来源:PointNode.cs

示例12: BFS

        /** Returns all nodes up to a given node-distance from the seed node.
         * This function performs a BFS (breadth-first-search) or flood fill of the graph and returns all nodes within a specified node distance which can be reached from
         * the seed node. In almost all cases when \a depth is large enough this will be identical to returning all nodes which have the same area as the seed node.
         * In the editor areas are displayed as different colors of the nodes.
         * The only case where it will not be so is when there is a one way path from some part of the area to the seed node
         * but no path from the seed node to that part of the graph.
         *
         * The returned list is sorted by node distance from the seed node
         * i.e distance is measured in the number of nodes the shortest path from \a seed to that node would pass through.
         * Note that the distance measurement does not take heuristics, penalties or tag penalties.
         *
         * Depending on the number of nodes, this function can take quite some time to calculate
         * so don't use it too often or it might affect the framerate of your game.
         *
         * \param seed The node to start the search from.
         * \param depth The maximum node-distance from the seed node.
         * \param tagMask Optional mask for tags. This is a bitmask.
         *
         * \returns A List<Node> containing all nodes reachable up to a specified node distance from the seed node.
         * For better memory management the returned list should be pooled, see Pathfinding.Util.ListPool
         *
         * \warning This method is not thread safe. Only use it from the Unity thread (i.e normal game code).
         */
        public static List<GraphNode> BFS(GraphNode seed, int depth, int tagMask = -1)
        {
            BFSQueue = BFSQueue ?? new Queue<GraphNode>();
            var que = BFSQueue;

            BFSMap = BFSMap ?? new Dictionary<GraphNode,int>();
            var map = BFSMap;

            // Even though we clear at the end of this function, it is good to
            // do it here as well in case the previous invocation of the method
            // threw an exception for some reason
            // and didn't clear the que and map
            que.Clear ();
            map.Clear ();

            List<GraphNode> result = ListPool<GraphNode>.Claim ();

            int currentDist = -1;
            GraphNodeDelegate callback;
            if (tagMask == -1) {
                callback = node => {
                    if (node.Walkable && !map.ContainsKey (node)) {
                        map.Add (node, currentDist+1);
                        result.Add (node);
                        que.Enqueue (node);
                    }
                };
            } else {
                callback = node => {
                    if (node.Walkable && ((tagMask >> (int)node.Tag) & 0x1) != 0 && !map.ContainsKey (node)) {
                        map.Add (node, currentDist+1);
                        result.Add (node);
                        que.Enqueue (node);
                    }
                };
            }

            callback (seed);

            while (que.Count > 0 ) {
                GraphNode n = que.Dequeue ();
                currentDist = map[n];

                if (currentDist >= depth) break;

                n.GetConnections (callback);
            }

            que.Clear ();
            map.Clear ();

            return result;
        }
开发者ID:NBurrichter,项目名称:Brainzzz,代码行数:76,代码来源:PathUtilities.cs

示例13: Initialize

 public RichSpecial Initialize(NodeLink2 nodeLink, GraphNode first)
 {
     this.nodeLink = nodeLink;
     if (first == nodeLink.StartNode)
     {
         this.first = nodeLink.StartTransform;
         this.second = nodeLink.EndTransform;
         this.reverse = false;
     }
     else
     {
         this.first = nodeLink.EndTransform;
         this.second = nodeLink.StartTransform;
         this.reverse = true;
     }
     return this;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:17,代码来源:RichSpecial.cs

示例14: Trace

 public void Trace(GraphNode from)
 {
     GraphNode graphNode = from;
     int num = 0;
     while (graphNode != null)
     {
         this.path.Add(graphNode);
         this.vectorPath.Add((Vector3)graphNode.position);
         graphNode = this.flood.GetParent(graphNode);
         num++;
         if (num > 1024)
         {
             Debug.LogWarning("Inifinity loop? >1024 node path. Remove this message if you really have that long paths (FloodPathTracer.cs, Trace function)");
             break;
         }
     }
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:17,代码来源:FloodPathTracer.cs

示例15: GetReachableNodes

		/** Returns all nodes reachable from the seed node.
		 * This function performs a BFS (breadth-first-search) or flood fill of the graph and returns all nodes which can be reached from
		 * the seed node. In almost all cases this will be identical to returning all nodes which have the same area as the seed node.
		 * In the editor areas are displayed as different colors of the nodes.
		 * The only case where it will not be so is when there is a one way path from some part of the area to the seed node
		 * but no path from the seed node to that part of the graph.
		 * 
		 * The returned list is sorted by node distance from the seed node
		 * i.e distance is measured in the number of nodes the shortest path from \a seed to that node would pass through.
		 * Note that the distance measurement does not take heuristics, penalties or tag penalties.
		 * 
		 * Depending on the number of reachable nodes, this function can take quite some time to calculate
		 * so don't use it too often or it might affect the framerate of your game.
		 * 
		 * \param seed The node to start the search from
		 * \param tagMask Optional mask for tags. This is a bitmask.
		 * 
		 * \returns A List<Node> containing all nodes reachable from the seed node.
		 * For better memory management the returned list should be pooled, see Pathfinding.Util.ListPool
		 */
		public static List<GraphNode> GetReachableNodes (GraphNode seed, int tagMask = -1) {
#if ASTAR_PROFILE
			System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
			watch.Start ();
#endif
			Stack<GraphNode> stack = Pathfinding.Util.StackPool<GraphNode>.Claim ();
			List<GraphNode> list = Pathfinding.Util.ListPool<GraphNode>.Claim ();
			
			
			HashSet<GraphNode> map = new HashSet<GraphNode>();
			
			GraphNodeDelegate callback;
			if (tagMask == -1) {
				callback = delegate (GraphNode node) {
					if (node.Walkable && map.Add (node)) {
						list.Add (node);
						stack.Push (node);
					}
				};
			} else {
				callback = delegate (GraphNode node) {
					if (node.Walkable && ((tagMask >> (int)node.Tag) & 0x1) != 0 && map.Add (node)) {
						list.Add (node);
						stack.Push (node);
					}
				};
			}
			
			callback (seed);
			
			while (stack.Count > 0) {
				stack.Pop ().GetConnections (callback);
			}
			
			Pathfinding.Util.StackPool<GraphNode>.Release (stack);
			
#if ASTAR_PROFILE
			watch.Stop ();
			Debug.Log ((1000*watch.Elapsed.TotalSeconds).ToString("0.0 ms"));
#endif
			return list;
		}
开发者ID:Gapti,项目名称:ClashOfClanRIP,代码行数:62,代码来源:PathUtilities.cs


注:本文中的Pathfinding.GraphNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。