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


C# AstarPath.Add方法代码示例

本文整理汇总了C#中AstarPath.Add方法的典型用法代码示例。如果您正苦于以下问题:C# AstarPath.Add方法的具体用法?C# AstarPath.Add怎么用?C# AstarPath.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AstarPath的用法示例。


在下文中一共展示了AstarPath.Add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Open

		public virtual void Open (AstarPath.BinaryHeap open, AstarPath.Path p, Node start, Node end, float angleCost) {
			
			for (int i=0;i<enabledConnections.Length;i++) {
				
				Connection connection = enabledConnections[i];
				Node node = connection.endNode;
				
				if (node == start) {
					continue;
				}
				
				//Debug.DrawLine (current.vectorPos,current.neighbours[i].vectorPos,Color.red); //Uncomment for debug
				//If the nodes script variable isn't refering to this path class the node counts as "not used yet" and can then be used
				if (node.script != p) {
					//Test if the angle from the current node to this one has exceded the angle limit
					//if (angle >= maxAngle) {
					//	return;
					//}
					node.parent = this;
					node.script = p;
					
					node.basicCost = connection.cost + Mathf.RoundToInt (connection.cost*connection.angle*angleCost);
					//(current.costs == null || costs.Length == 0 ? costs[node.invParentDirection] : current.costs[node.invParentDirection]);
					//Calculate the extra cost of moving in a slope
					//node.extraCost =  ;
					//Add the node to the open array
					//Debug.DrawLine (current.vectorPos,current.neighbours[i].vectorPos,Color.green); //Uncomment for @Debug
					
					node.UpdateH (end);
					node.UpdateG ();
					
					open.Add (node);
					
				} else {
					
					//If not we can test if the path from the current node to this one is a better one then the one already used
					int cost2 = connection.cost + Mathf.RoundToInt (connection.cost*connection.angle*angleCost);//(current.costs == null || current.costs.Length == 0 ? costs[current.neighboursKeys[i]] : current.costs[current.neighboursKeys[i]]);
					
					//int extraCost2
					
					if (g+cost2+node.penalty < node.g) {
						node.basicCost = cost2;
						//node.extraCost = extraCost2;
						node.parent = this;
						
						node.UpdateAllG ();
						
						open.Add (node);//@Quality, uncomment for better quality (I think).
						
						//Debug.DrawLine (current.vectorPos,current.neighbours[i].vectorPos,Color.cyan); //Uncomment for @Debug
					}
					
					 else if (node.g+cost2+penalty < g) {//Or if the path from this node ("node") to the current ("current") is better
						bool contains = false;
						
						//Make sure we don't travel along the wrong direction of a one way link now, make sure the Current node can be accesed from the Node.
						for (int y=0;y<node.connections.Length;y++) {
							if (node.connections[y].endNode == this) {
								contains = true;
								break;
							}
						}
						
						if (!contains) {
							continue;
						}
						
						parent = node;
						basicCost = cost2;
						//extraCost = extraCost2;
						
						node.UpdateAllG ();
						
						//Debug.DrawLine (current.vectorPos,current.neighbours[i].vectorPos,Color.blue); //Uncomment for @Debug
						open.Add (this);
					}
				}
			}
		}
开发者ID:hyper-active,项目名称:virtual-reality,代码行数:79,代码来源:AstarClasses.cs


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