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


C# GraphUpdateObject.Apply方法代码示例

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


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

示例1: UpdateArea


//.........这里部分代码省略.........
				}
			}
			
			//Update Physics
			if (o.updatePhysics && !o.modifyWalkability) {
				
				collision.Initialize (matrix,nodeSize);
				
				clampedRect = IntRect.Intersection (physicsRect,gridRect);
				
				for (int x = clampedRect.xmin; x <= clampedRect.xmax;x++) {
					for (int z = clampedRect.ymin;z <= clampedRect.ymax;z++) {
						
						int index = z*width+x;
						
						GridNode node = nodes[index];
						
						UpdateNodePositionCollision (node,x,z, o.resetPenaltyOnPhysics);
					}
				}
			}
			
			//Apply GUO
			
			clampedRect = IntRect.Intersection (originalRect, gridRect);
			for (int x = clampedRect.xmin; x <= clampedRect.xmax;x++) {
				for (int z = clampedRect.ymin;z <= clampedRect.ymax;z++) {
					int index = z*width+x;
					
					GridNode node = nodes[index];
					
					if (willChangeWalkability) {
						node.Walkable = node.WalkableErosion;
						if (o.bounds.Contains ((Vector3)node.position)) o.Apply (node);
						node.WalkableErosion = node.Walkable;
					} else {
						if (o.bounds.Contains ((Vector3)node.position)) o.Apply (node);
					}
				}
			}
		
#if ASTARDEBUG
			physicsRect.DebugDraw (debugMatrix,Color.blue);
			affectRect.DebugDraw (debugMatrix,Color.black);
#endif
			
			//Recalculate connections
			if (willChangeWalkability && erosion == 0) {
				
				clampedRect = IntRect.Intersection (affectRect, gridRect);
				for (int x = clampedRect.xmin; x <= clampedRect.xmax;x++) {
					for (int z = clampedRect.ymin;z <= clampedRect.ymax;z++) {
						int index = z*width+x;
						
						GridNode node = nodes[index];
						
						CalculateConnections (nodes,x,z,node);
					}
				}
			} else if (willChangeWalkability && erosion > 0) {
				
				
				clampedRect = IntRect.Union (originalRect, physicsRect);
				
				IntRect erosionRect1 = clampedRect.Expand (erosion);
				IntRect erosionRect2 = erosionRect1.Expand (erosion);
开发者ID:JoseRego,项目名称:summer-rush,代码行数:67,代码来源:GridGenerator.cs

示例2: UpdateArea


//.........这里部分代码省略.........
			Vector3 b = new Vector3 (r.xMin,0,r.yMax);//	-1	 1 
			Vector3 c = new Vector3 (r.xMax,0,r.yMin);//	 1 	-1
			Vector3 d = new Vector3 (r.xMax,0,r.yMax);//	 1 	 1
			*/
			Int3 a = new Int3(r2.xmin,0,r2.ymin);
			Int3 b = new Int3(r2.xmin,0,r2.ymax);
			Int3 c = new Int3(r2.xmax,0,r2.ymin);
			Int3 d = new Int3(r2.xmax,0,r2.ymax);
			
			Int3 ia = (Int3)a;
			Int3 ib = (Int3)b;
			Int3 ic = (Int3)c;
			Int3 id = (Int3)d;
			
#if ASTARDEBUG
			Debug.DrawLine (a,b,Color.white);
			Debug.DrawLine (a,c,Color.white);
			Debug.DrawLine (c,d,Color.white);
			Debug.DrawLine (d,b,Color.white);
#endif
			
			//for (int i=0;i<nodes.Length;i++) {
			graph.GetNodes (delegate (GraphNode _node) {
				TriangleMeshNode node = _node as TriangleMeshNode;
				
				bool inside = false;
				
				int allLeft = 0;
				int allRight = 0;
				int allTop = 0;
				int allBottom = 0;
				
				for (int v=0;v<3;v++) {
					
					Int3 p = node.GetVertex(v);
					Vector3 vert = (Vector3)p;
					//Vector2 vert2D = new Vector2 (vert.x,vert.z);
					
					if (r2.Contains (p.x,p.z)) {
						//Debug.DrawRay (vert,Vector3.up*10,Color.yellow);
						inside = true;
						break;
					}
					
					if (vert.x < r.xMin) allLeft++;
					if (vert.x > r.xMax) allRight++;
					if (vert.z < r.yMin) allTop++;
					if (vert.z > r.yMax) allBottom++;
					
					//if (!bounds.Contains (node[v]) {
					//	inside = false;
					//	break;
					//}
				}
				if (!inside) {
					if (allLeft == 3 || allRight == 3 || allTop == 3 || allBottom == 3) {
						return true;
					}
				}
				
				//Debug.DrawLine ((Vector3)node.GetVertex(0),(Vector3)node.GetVertex(1),Color.yellow);
				//Debug.DrawLine ((Vector3)node.GetVertex(1),(Vector3)node.GetVertex(2),Color.yellow);
				//Debug.DrawLine ((Vector3)node.GetVertex(2),(Vector3)node.GetVertex(0),Color.yellow);
				
				for (int v=0;v<3;v++) {
					int v2 = v > 1 ? 0 : v+1;
					
					Int3 vert1 = node.GetVertex(v);
					Int3 vert2 = node.GetVertex(v2);
					
					if (Polygon.Intersects (a,b,vert1,vert2)) { inside = true; break; }
					if (Polygon.Intersects (a,c,vert1,vert2)) { inside = true; break; }
					if (Polygon.Intersects (c,d,vert1,vert2)) { inside = true; break; }
					if (Polygon.Intersects (d,b,vert1,vert2)) { inside = true; break; }
				}
				
				
				
				if (node.ContainsPoint (ia) || node.ContainsPoint (ib) || node.ContainsPoint (ic) || node.ContainsPoint (id)) {
					inside = true;
				}
				
				if (!inside) {
					return true;
				}
				
				o.WillUpdateNode(node);
				o.Apply (node);
				/*Debug.DrawLine ((Vector3)node.GetVertex(0),(Vector3)node.GetVertex(1),Color.blue);
				Debug.DrawLine ((Vector3)node.GetVertex(1),(Vector3)node.GetVertex(2),Color.blue);
				Debug.DrawLine ((Vector3)node.GetVertex(2),(Vector3)node.GetVertex(0),Color.blue);
				Debug.Break ();*/
				return true;
			});
			
			//System.DateTime endTime = System.DateTime.UtcNow;
			//float theTime = (endTime-startTime).Ticks*0.0001F;
			//Debug.Log ("Intersecting bounds with navmesh took "+theTime.ToString ("0.000")+" ms");
		
		}
开发者ID:henryj41043,项目名称:TheUnseen,代码行数:101,代码来源:NavMeshGenerator.cs

示例3: UpdateArea


//.........这里部分代码省略.........

                for (int x = clampedRect.xmin; x <= clampedRect.xmax;x++) {
                    for (int z = clampedRect.ymin;z <= clampedRect.ymax;z++) {
                        for (int y=0;y<layerCount;y++) {
                            int index = y*width*depth + z*width+x;

                            LevelGridNode node = nodes[index] as LevelGridNode;

                            if (node == null) continue;

                            CalculateConnections (nodes,node,x,z,y);
                        }
                    }
                }
                if (addedNodes) {
                    AstarPath.active.DataUpdate();
                }
            }

            //Apply GUO

            clampedRect = IntRect.Intersection (originalRect, gridRect);
            for (int x = clampedRect.xmin; x <= clampedRect.xmax;x++) {
                for (int z = clampedRect.ymin;z <= clampedRect.ymax;z++) {
                    for (int y=0;y<layerCount;y++) {
                        int index = y*width*depth + z*width+x;

                        LevelGridNode node = nodes[index] as LevelGridNode;

                        if (node == null) continue;

                        if (willChangeWalkability) {
                            node.walkable = node.Bit15;
                            o.Apply (node);
                            node.Bit15 = node.walkable;
                        } else {
                            o.Apply (node);
                        }
                    }
                }
            }

            #if ASTARDEBUG
            physicsRect.DebugDraw (debugMatrix,Color.blue);
            affectRect.DebugDraw (debugMatrix,Color.black);
            #endif

            //Recalculate connections
            if (willChangeWalkability && erodeIterations == 0) {

                clampedRect = IntRect.Intersection (affectRect, gridRect);
                for (int x = clampedRect.xmin; x <= clampedRect.xmax;x++) {
                    for (int z = clampedRect.ymin;z <= clampedRect.ymax;z++) {
                        for (int y=0;y<layerCount;y++) {
                            int index = y*width*depth + z*width+x;

                            LevelGridNode node = nodes[index] as LevelGridNode;

                            if (node == null) continue;

                            CalculateConnections (nodes,node,x,z,y);
                        }
                    }
                }
            } else if (willChangeWalkability && erodeIterations > 0) {
开发者ID:paillardf,项目名称:RV01_WALL,代码行数:66,代码来源:LayerGridGraphGenerator.cs

示例4: UpdateArea

        /** Internal function to update an area of the graph.
         * \todo Messy code, clean it up. */
        public void UpdateArea(GraphUpdateObject o)
        {
            if (nodes == null) {
                Debug.LogWarning ("The Grid Graph is not scanned, cannot update area ");
                //Not scanned
                return;
            }

            //Copy the bounds
            Bounds b = o.bounds;

            //Matrix inverse
            //node.position = matrix.MultiplyPoint3x4 (new Vector3 (x+0.5F,0,z+0.5F));

            Vector3 min, max;
            GetBoundsMinMax (b,inverseMatrix,out min, out max);

            int minX = Mathf.RoundToInt (min.x-0.5F);
            int maxX = Mathf.RoundToInt (max.x-0.5F);

            int minZ = Mathf.RoundToInt (min.z-0.5F);
            int maxZ = Mathf.RoundToInt (max.z-0.5F);

            //We now have coordinates in local space (i.e 1 unit = 1 node)

            int ominx = minX;
            int omaxx = maxX;
            int ominz = minZ;
            int omaxz = maxZ;

            if (o.updatePhysics && !o.modifyWalkability) {
                //Add the collision.diameter margin for physics calls
                if (collision.collisionCheck) {
                    Vector3 margin = new Vector3 (collision.diameter,0,collision.diameter)*0.5F;

                    min -= margin*1.02F;//0.02 safety margin, physics is rarely very accurate
                    max += margin*1.02F;
            #if DEBUG
                    Debug.DrawLine (matrix.MultiplyPoint3x4(min),matrix.MultiplyPoint3x4(max),Color.cyan);
            #endif

                    minX = Mathf.RoundToInt (min.x-0.5F);
                    maxX = Mathf.RoundToInt (max.x-0.5F);

                    minZ = Mathf.RoundToInt (min.z-0.5F);
                    maxZ = Mathf.RoundToInt (max.z-0.5F);

                }

                collision.Initialize (matrix,nodeSize);

                for (int x = minX;x <= maxX;x++) {
                    for (int z = minZ;z <= maxZ;z++) {

                        if (x < 0 || z < 0) {
                            continue;
                        }
                        if (z >= depth || x >= width) {
                            break;
                        }

                        int index = z*width+x;

                        GridNode node = nodes[index] as GridNode;

                        //Register that this node will eventually have some settings changed
                        o.WillUpdateNode (node);

                        UpdateNodePositionCollision (node,x,z);
                    }
                }
            }

            //This is the area inside the bounding box, call Apply on it
            for (int x = ominx;x <= omaxx;x++) {
                for (int z = ominz;z <= omaxz;z++) {

                    if (x < 0 || z < 0) {
                        continue;
                    }
                    if (z >= depth || x >= width) {
                        break;
                    }

                    int index = z*width+x;

                    GridNode node = nodes[index] as GridNode;

                    if (!o.updatePhysics || o.modifyWalkability) {
                        //Register that this node will eventually have some settings changed
                        //If the above IF evaluates to false, the node will already have been added before in the function
                        o.WillUpdateNode (node);
                    }

                    node.walkable = node.WalkableErosion;
                    o.Apply (node);
                    node.WalkableErosion = node.walkable;
                }
//.........这里部分代码省略.........
开发者ID:Anaryu,项目名称:aetherion,代码行数:101,代码来源:GridGenerator.cs

示例5: UpdateArea

		public static void UpdateArea (GraphUpdateObject o, NavGraph graph) {
			
			INavmesh navgraph = graph as INavmesh;
			
			if (navgraph == null) { Debug.LogError ("Update Area on NavMesh must be called with a graph implementing INavmesh"); return; }
			
			if (graph.nodes == null || graph.nodes.Length == 0) {
				Debug.LogError ("NavGraph hasn't been generated yet or does not contain any nodes");
				return;// new NNInfo ();
			}
			
			//System.DateTime startTime = System.DateTime.Now;
				
			Bounds bounds = o.bounds;
			
			Rect r = Rect.MinMaxRect (bounds.min.x,bounds.min.z,bounds.max.x,bounds.max.z);
			
			Vector3 a = new Vector3 (r.xMin,0,r.yMin);//	-1 	-1
			Vector3 b = new Vector3 (r.xMin,0,r.yMax);//	-1	 1 
			Vector3 c = new Vector3 (r.xMax,0,r.yMin);//	 1 	-1
			Vector3 d = new Vector3 (r.xMax,0,r.yMax);//	 1 	 1
			
			
			for (int i=0;i<graph.nodes.Length;i++) {
				MeshNode node = graph.nodes[i] as MeshNode;
				
				bool inside = false;
				
				int allLeft = 0;
				int allRight = 0;
				int allTop = 0;
				int allBottom = 0;
				
				for (int v=0;v<3;v++) {
					
					Vector3 vert = (Vector3)navgraph.vertices[node[v]];
					Vector2 vert2D = new Vector2 (vert.x,vert.z);
					
					if (r.Contains (vert2D)) {
						//Debug.DrawRay (vert,Vector3.up,Color.yellow);
						inside = true;
						break;
					}
					
					if (vert.x < r.xMin) allLeft++;
					if (vert.x > r.xMax) allRight++;
					if (vert.z < r.yMin) allTop++;
					if (vert.z > r.yMax) allBottom++;
					
					//if (!bounds.Contains (node[v]) {
					//	inside = false;
					//	break;
					//}
				}
				if (!inside) {
					if (allLeft == 3 || allRight == 3 || allTop == 3 || allBottom == 3) {
						continue;
					}
				}
				
				for (int v=0;v<3;v++) {
					int v2 = v > 1 ? 0 : v+1;
					
					Vector3 vert1 = (Vector3)navgraph.vertices[node[v]];
					Vector3 vert2 = (Vector3)navgraph.vertices[node[v2]];
					
					if (Polygon.Intersects (a,b,vert1,vert2)) { inside = true; break; }
					if (Polygon.Intersects (a,c,vert1,vert2)) { inside = true; break; }
					if (Polygon.Intersects (c,d,vert1,vert2)) { inside = true; break; }
					if (Polygon.Intersects (d,b,vert1,vert2)) { inside = true; break; }
				}
				
				
				
				if (!inside && ContainsPoint (node,a,navgraph.vertices)) { inside = true; }//Debug.DrawRay (a+Vector3.right*0.01F*i,Vector3.up,Color.red); }
				if (!inside && ContainsPoint (node,b,navgraph.vertices)) { inside = true; } //Debug.DrawRay (b+Vector3.right*0.01F*i,Vector3.up,Color.red); }
				if (!inside && ContainsPoint (node,c,navgraph.vertices)) { inside = true; }//Debug.DrawRay (c+Vector3.right*0.01F*i,Vector3.up,Color.red); }
				if (!inside && ContainsPoint (node,d,navgraph.vertices)) { inside = true; }//Debug.DrawRay (d+Vector3.right*0.01F*i,Vector3.up,Color.red); }
				
				if (!inside) {
					continue;
				}
				
				o.WillUpdateNode(node);
				o.Apply (node);
				//Debug.DrawLine (vertices[node.v1],vertices[node.v2],Color.blue);
				//Debug.DrawLine (vertices[node.v2],vertices[node.v3],Color.blue);
				//Debug.DrawLine (vertices[node.v3],vertices[node.v1],Color.blue);
				//Debug.Break ();
			}
			
			//System.DateTime endTime = System.DateTime.Now;
			//float theTime = (endTime-startTime).Ticks*0.0001F;
			//Debug.Log ("Intersecting bounds with navmesh took "+theTime.ToString ("0.000")+" ms");
		
		}
开发者ID:pravusjif,项目名称:PravusUnityTests,代码行数:96,代码来源:NavMeshGenerator.cs

示例6: UpdateArea

        /** Updates an area in the list graph.
         * Recalculates possibly affected connections, i.e all connectionlines passing trough the bounds of the \a guo will be recalculated
         * \astarpro */
        public void UpdateArea(GraphUpdateObject guo)
        {
            if (nodes == null) {
                return;
            }

            for (int i=0;i<nodes.Length;i++) {
                if (guo.bounds.Contains ((Vector3)nodes[i].position)) {
                    guo.WillUpdateNode (nodes[i]);
                    guo.Apply (nodes[i]);
                }
            }

            if (guo.updatePhysics) {

                //Use a copy of the bounding box, we should not change the GUO's bounding box since it might be used for other graph updates
                Bounds bounds = guo.bounds;

                if (thickRaycast) {
                    //Expand the bounding box to account for the thick raycast
                    bounds.Expand (thickRaycastRadius*2);
                }

                //Create two temporary arrays used for holding new connections and costs
                List<Node> tmp_arr = Pathfinding.Util.ListPool<Node>.Claim ();
                List<int>  tmp_arr2 =Pathfinding.Util.ListPool<int>.Claim ();

                for (int i=0;i<nodes.Length;i++) {
                    Node node = nodes[i];
                    Vector3 a = (Vector3)node.position;

                    List<Node> conn = null;
                    List<int> costs = null;

                    for (int j=0;j<nodes.Length;j++) {
                        if (j==i) continue;

                        Vector3 b = (Vector3)nodes[j].position;
                        if (Polygon.LineIntersectsBounds (bounds,a,b)) {

                            float dist;
                            Node other = nodes[j];
                            bool contains = node.ContainsConnection (other);

                            //Note, the IsValidConnection test will actually only be done once
                            //no matter what,so there is no performance penalty there
                            if (!contains && IsValidConnection (node,other, out dist)) {
                                //Debug.DrawLine (a+Vector3.up*0.1F,b+Vector3.up*0.1F,Color.green);
                                if (conn == null) {
                                    tmp_arr.Clear();
                                    tmp_arr2.Clear ();
                                    conn = tmp_arr;
                                    costs = tmp_arr2;
                                    conn.AddRange (node.connections);
                                    costs.AddRange (node.connectionCosts);
                                }

                                int cost = Mathf.RoundToInt (dist*Int3.FloatPrecision);
                                conn.Add (other);
                                costs.Add (cost);

                            } else if (contains && !IsValidConnection (node,other, out dist)) {
                                //Debug.DrawLine (a+Vector3.up*0.5F*Random.value,b+Vector3.up*0.5F*Random.value,Color.red);
                                if (conn == null) {
                                    tmp_arr.Clear();
                                    tmp_arr2.Clear ();
                                    conn = tmp_arr;
                                    costs = tmp_arr2;
                                    conn.AddRange (node.connections);
                                    costs.AddRange (node.connectionCosts);
                                }

                                int p = conn.IndexOf (other);

                                //Shouldn't have to check for it, but who knows what might go wrong
                                if (p != -1) {
                                    conn.RemoveAt (p);
                                    costs.RemoveAt (p);
                                }
                            }
                        }
                    }

                    if (conn != null) {
                        node.connections = conn.ToArray ();
                        node.connectionCosts = costs.ToArray ();
                    }
                }

                Pathfinding.Util.ListPool<Node>.Release (tmp_arr);
                Pathfinding.Util.ListPool<int>.Release (tmp_arr2);
            }
        }
开发者ID:sonygod,项目名称:ESPUnity,代码行数:96,代码来源:PointGenerator.cs

示例7: UpdateArea

		public static void UpdateArea (GraphUpdateObject o, INavmesh graph) {

			//System.DateTime startTime = System.DateTime.UtcNow;

			Bounds bounds = o.bounds;

			Rect r = Rect.MinMaxRect (bounds.min.x,bounds.min.z,bounds.max.x,bounds.max.z);

			var r2 = new IntRect(
				Mathf.FloorToInt(bounds.min.x*Int3.Precision),
				Mathf.FloorToInt(bounds.min.z*Int3.Precision),
				Mathf.FloorToInt(bounds.max.x*Int3.Precision),
				Mathf.FloorToInt(bounds.max.z*Int3.Precision)
			);

			var a = new Int3(r2.xmin,0,r2.ymin);
			var b = new Int3(r2.xmin,0,r2.ymax);
			var c = new Int3(r2.xmax,0,r2.ymin);
			var d = new Int3(r2.xmax,0,r2.ymax);

			graph.GetNodes (_node => {
				var node = _node as TriangleMeshNode;

				bool inside = false;

				int allLeft = 0;
				int allRight = 0;
				int allTop = 0;
				int allBottom = 0;

				for (int v=0;v<3;v++) {

					Int3 p = node.GetVertex(v);
					var vert = (Vector3)p;

					if (r2.Contains (p.x,p.z)) {
						inside = true;
						break;
					}

					if (vert.x < r.xMin) allLeft++;
					if (vert.x > r.xMax) allRight++;
					if (vert.z < r.yMin) allTop++;
					if (vert.z > r.yMax) allBottom++;
				}
				if (!inside) {
					if (allLeft == 3 || allRight == 3 || allTop == 3 || allBottom == 3) {
						return true;
					}
				}

				for (int v=0;v<3;v++) {
					int v2 = v > 1 ? 0 : v+1;

					Int3 vert1 = node.GetVertex(v);
					Int3 vert2 = node.GetVertex(v2);

					if (Polygon.Intersects (a,b,vert1,vert2)) { inside = true; break; }
					if (Polygon.Intersects (a,c,vert1,vert2)) { inside = true; break; }
					if (Polygon.Intersects (c,d,vert1,vert2)) { inside = true; break; }
					if (Polygon.Intersects (d,b,vert1,vert2)) { inside = true; break; }
				}

				if (node.ContainsPoint (a) || node.ContainsPoint (b) || node.ContainsPoint (c) || node.ContainsPoint (d)) {
					inside = true;
				}

				if (!inside) {
					return true;
				}

				o.WillUpdateNode(node);
				o.Apply (node);
				return true;
			});
		}
开发者ID:SpacesAdventure,项目名称:Kio-2,代码行数:76,代码来源:NavMeshGenerator.cs

示例8: UpdateArea

		public static void UpdateArea (GraphUpdateObject o, INavmesh graph) {
			Bounds bounds = o.bounds;

			// Bounding rectangle with floating point coordinates
			Rect r = Rect.MinMaxRect (bounds.min.x,bounds.min.z,bounds.max.x,bounds.max.z);

			// Bounding rectangle with int coordinates
			var r2 = new IntRect(
				Mathf.FloorToInt(bounds.min.x*Int3.Precision),
				Mathf.FloorToInt(bounds.min.z*Int3.Precision),
				Mathf.FloorToInt(bounds.max.x*Int3.Precision),
				Mathf.FloorToInt(bounds.max.z*Int3.Precision)
			);

			// Corners of the bounding rectangle
			var a = new Int3(r2.xmin,0,r2.ymin);
			var b = new Int3(r2.xmin,0,r2.ymax);
			var c = new Int3(r2.xmax,0,r2.ymin);
			var d = new Int3(r2.xmax,0,r2.ymax);

			var ymin = ((Int3)bounds.min).y;
			var ymax = ((Int3)bounds.max).y;

			// Loop through all nodes
			graph.GetNodes (_node => {
				var node = _node as TriangleMeshNode;

				bool inside = false;

				int allLeft = 0;
				int allRight = 0;
				int allTop = 0;
				int allBottom = 0;

				// Check bounding box rect in XZ plane
				for (int v=0;v<3;v++) {
					Int3 p = node.GetVertex(v);
					var vert = (Vector3)p;

					if (r2.Contains (p.x,p.z)) {
						inside = true;
						break;
					}

					if (vert.x < r.xMin) allLeft++;
					if (vert.x > r.xMax) allRight++;
					if (vert.z < r.yMin) allTop++;
					if (vert.z > r.yMax) allBottom++;
				}

				if (!inside) {
					if (allLeft == 3 || allRight == 3 || allTop == 3 || allBottom == 3) {
						return true;
					}
				}

				// Check if the polygon edges intersect the bounding rect
				for (int v = 0; v < 3; v++) {
					int v2 = v > 1 ? 0 : v+1;

					Int3 vert1 = node.GetVertex(v);
					Int3 vert2 = node.GetVertex(v2);

					if (Polygon.Intersects (a,b,vert1,vert2)) { inside = true; break; }
					if (Polygon.Intersects (a,c,vert1,vert2)) { inside = true; break; }
					if (Polygon.Intersects (c,d,vert1,vert2)) { inside = true; break; }
					if (Polygon.Intersects (d,b,vert1,vert2)) { inside = true; break; }
				}

				// Check if the node contains any corner of the bounding rect
				if (inside || node.ContainsPoint (a) || node.ContainsPoint (b) || node.ContainsPoint (c) || node.ContainsPoint (d)) {
					inside = true;
				}

				if (!inside) {
					return true;
				}

				int allAbove = 0;
				int allBelow = 0;

				// Check y coordinate
				for (int v = 0; v < 3; v++) {
					Int3 p = node.GetVertex(v);
					var vert = (Vector3)p;
					if (vert.y < ymin) allBelow++;
					if (vert.y > ymax) allAbove++;
				}

				// Polygon is either completely above the bounding box or completely below it
				if (allBelow == 3 || allAbove == 3) return true;

				// Triangle is inside the bounding box!
				// Update it!
				o.WillUpdateNode(node);
				o.Apply (node);
				return true;
			});
		}
开发者ID:legionaryu,项目名称:Atom-defender,代码行数:99,代码来源:NavMeshGenerator.cs

示例9: UpdateArea

		public void UpdateArea (GraphUpdateObject o) {
			
			if (graphNodes == null || nodes == null) {
				Debug.LogWarning ("The Grid Graph is not scanned, cannot update area ");
				//Not scanned
				return;
			}
			
			//Copy the bounds
			Bounds b = o.bounds;
			
			//Matrix inverse 
			//node.position = matrix.MultiplyPoint3x4 (new Vector3 (x+0.5F,0,z+0.5F));
			
			Vector3 min = inverseMatrix.MultiplyPoint3x4 (b.min);
			Vector3 max = inverseMatrix.MultiplyPoint3x4 (b.max);
			
			int minX = Mathf.RoundToInt (min.x-0.5F);
			int maxX = Mathf.RoundToInt (max.x-0.5F);
			
			int minZ = Mathf.RoundToInt (min.z-0.5F);
			int maxZ = Mathf.RoundToInt (max.z-0.5F);
			
			//We now have coordinates in local space (i.e 1 unit = 1 node)
			
			int ominx = minX;
			int omaxx = maxX;
			int ominz = minZ;
			int omaxz = maxZ;
			
			if (o.updatePhysics && !o.modifyWalkability) {
				//Add the collision.diameter margin for physics calls
				if (collision.collisionCheck) {
					Vector3 margin = new Vector3 (collision.diameter,0,collision.diameter)*0.5F;
				
					min -= margin*1.02F;//0.02 safety margin, physics is rarely very accurate
					max += margin*1.02F;
					Debug.DrawLine (matrix.MultiplyPoint3x4(min),matrix.MultiplyPoint3x4(max),Color.cyan);
					
					minX = Mathf.RoundToInt (min.x-0.5F);
					maxX = Mathf.RoundToInt (max.x-0.5F);
				
					minZ = Mathf.RoundToInt (min.z-0.5F);
					maxZ = Mathf.RoundToInt (max.z-0.5F);
					
				}
				
				collision.Initialize (matrix,nodeSize);
				
				for (int x = minX;x <= maxX;x++) {
					for (int z = minZ;z <= maxZ;z++) {
						
						if (x < 0 || z < 0) {
							continue;
						}
						if (z >= depth || x >= width) {
							break;
						}
						
						int index = z*width+x;
						
						GridNode node = graphNodes[index];
						
						//Register that this node will eventually have some settings changed
						o.WillUpdateNode (node);
						
						UpdateNodePositionCollision (node,x,z);
					}
				}
			}
			
			//This is the area inside the bounding box, call Apply on it
			for (int x = ominx;x <= omaxx;x++) {
				for (int z = ominz;z <= omaxz;z++) {
					
					if (x < 0 || z < 0) {
						continue;
					}
					if (z >= depth || x >= width) {
						break;
					}
					
					int index = z*width+x;
					
					GridNode node = graphNodes[index];
					
					if (!o.updatePhysics || o.modifyWalkability) {
						//Register that this node will eventually have some settings changed
						//If the above IF evaluates to false, the node will already have been added before in the function
						o.WillUpdateNode (node);
					}
					
					o.Apply (node);
				}
			}
			
			//Recalculate connections
			if (o.updatePhysics || o.modifyWalkability) {
				//Add some margin
				minX--; //Mathf.Clamp (minX-1,0,width);
//.........这里部分代码省略.........
开发者ID:pravusjif,项目名称:PravusUnityTests,代码行数:101,代码来源:GridGenerator.cs

示例10: UpdatePath

 private void UpdatePath()
 {
     AstarPath path = AstarPath.active;
     PointGraph graph = path.graphs[0] as PointGraph;
     GraphUpdateObject guo = new GraphUpdateObject(new Bounds (Vector3.zero, Vector3.one * 10000));
     guo.addPenalty = 100000;
     guo.updatePhysics = false;
     guo.modifyWalkability = true;
     guo.setWalkability = false;
     AstarPath.active.UpdateGraphs(guo);
     foreach (Node node in graph.nodes) {
         Vector2 p = this.PositionToMatrix(new Vector3(node.position.x / 1000, node.position.y / 1000, node.position.z / 1000));
         Room r = this.level.GetRoom (p);
         if (r != null && !r.IsEnable()) {
             guo.Apply(node);
         }
     }
 }
开发者ID:giginet,项目名称:PanicColony,代码行数:18,代码来源:LevelManager.cs


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