當前位置: 首頁>>代碼示例>>C#>>正文


C# IntRect.Expand方法代碼示例

本文整理匯總了C#中Pathfinding.IntRect.Expand方法的典型用法代碼示例。如果您正苦於以下問題:C# IntRect.Expand方法的具體用法?C# IntRect.Expand怎麽用?C# IntRect.Expand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Pathfinding.IntRect的用法示例。


在下文中一共展示了IntRect.Expand方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: UpdateArea

		public void UpdateArea (GraphUpdateObject guo) {
			
			Bounds b = guo.bounds;
			b.center -= forcedBounds.min;
			
			//Figure out which tiles are affected
			IntRect r = new IntRect (Mathf.FloorToInt (b.min.x / (tileSizeX*cellSize)), Mathf.FloorToInt (b.min.z / (tileSizeZ*cellSize)), Mathf.FloorToInt (b.max.x / (tileSizeX*cellSize)), Mathf.FloorToInt (b.max.z / (tileSizeZ*cellSize)));
			//Clamp to bounds
			r = IntRect.Intersection (r, new IntRect (0,0,tileXCount-1,tileZCount-1));
			
			if (!guo.updatePhysics) {
				
				
				for ( int z=r.ymin;z<=r.ymax;z++) {
					for ( int x=r.xmin;x<=r.xmax;x++) {
						NavmeshTile tile = tiles[z*tileXCount + x];
						tile.flag = true;
					}
				}
				
				for ( int z=r.ymin;z<=r.ymax;z++) {
					for ( int x=r.xmin;x<=r.xmax;x++) {
						NavmeshTile tile = tiles[z*tileXCount + x];
						if ( tile.flag ) {
							tile.flag = false;
							
							NavMeshGraph.UpdateArea (guo, tile);
						}
					}
				}
				
				return;
			}
			
			if (!dynamic) {
				throw new System.Exception ("Recast graph must be marked as dynamic to enable graph updates with updatePhysics = true");
			}
			
			Voxelize vox = globalVox;
			
			if (vox == null) {
				throw new System.InvalidOperationException ("No Voxelizer object. UpdateAreaInit should have been called before this function.");
			}
			
			
			
			AstarProfiler.StartProfile ("Init");
				
			/** \bug No bounds checking */
			
			//r.DebugDraw (Matrix4x4.TRS (forcedBounds.min, Quaternion.identity, new Vector3 (tileSize*cellSize, 1, tileSize*cellSize)), Color.red);
			
			//Debug.Break ();
			
			
			
			AstarProfiler.StartProfile ("RemoveConnections");
			
			
			
			for (int x=r.xmin;x<=r.xmax;x++) {
				for (int z=r.ymin;z<=r.ymax;z++) {
					RemoveConnectionsFromTile (tiles[x + z*tileXCount]);
				}
			}
			
			
			
			AstarProfiler.EndProfile ("RemoveConnections");
			
			AstarProfiler.StartProfile ("Build Tiles");
			
			for (int x=r.xmin;x<=r.xmax;x++) {
				for (int z=r.ymin;z<=r.ymax;z++) {
					BuildTileMesh (vox, x,z);
				}
			}
			
			
			
			AstarProfiler.EndProfile ("Build Tiles");
			
			
			AstarProfiler.StartProfile ("ConnectTiles");
			uint graphIndex = (uint)AstarPath.active.astarData.GetGraphIndex (this);
			
			for (int x=r.xmin;x<=r.xmax;x++) {
				for (int z=r.ymin;z<=r.ymax;z++) {
					NavmeshTile tile = tiles[x + z*tileXCount];
					GraphNode[] nodes = tile.nodes;
					
					for (int i=0;i<nodes.Length;i++) nodes[i].GraphIndex = graphIndex;
				}
			}
			
			
			
			//Connect the newly create tiles with the old tiles and with each other
			r = r.Expand (1);
			//Clamp to bounds
//.........這裏部分代碼省略.........
開發者ID:JoseRego,項目名稱:summer-rush,代碼行數:101,代碼來源:RecastGenerator.cs

示例2: UpdateArea

 public void UpdateArea(GraphUpdateObject guo)
 {
     Bounds bounds = guo.bounds;
     bounds.center -= this.forcedBounds.min;
     IntRect a = new IntRect(Mathf.FloorToInt(bounds.min.x / ((float)this.tileSizeX * this.cellSize)), Mathf.FloorToInt(bounds.min.z / ((float)this.tileSizeZ * this.cellSize)), Mathf.FloorToInt(bounds.max.x / ((float)this.tileSizeX * this.cellSize)), Mathf.FloorToInt(bounds.max.z / ((float)this.tileSizeZ * this.cellSize)));
     a = IntRect.Intersection(a, new IntRect(0, 0, this.tileXCount - 1, this.tileZCount - 1));
     if (!guo.updatePhysics)
     {
         for (int i = a.ymin; i <= a.ymax; i++)
         {
             for (int j = a.xmin; j <= a.xmax; j++)
             {
                 RecastGraph.NavmeshTile navmeshTile = this.tiles[i * this.tileXCount + j];
                 navmeshTile.flag = true;
             }
         }
         for (int k = a.ymin; k <= a.ymax; k++)
         {
             for (int l = a.xmin; l <= a.xmax; l++)
             {
                 RecastGraph.NavmeshTile navmeshTile2 = this.tiles[k * this.tileXCount + l];
                 if (navmeshTile2.flag)
                 {
                     navmeshTile2.flag = false;
                     NavMeshGraph.UpdateArea(guo, navmeshTile2);
                 }
             }
         }
         return;
     }
     if (!this.dynamic)
     {
         throw new Exception("Recast graph must be marked as dynamic to enable graph updates with updatePhysics = true");
     }
     Voxelize voxelize = this.globalVox;
     if (voxelize == null)
     {
         throw new InvalidOperationException("No Voxelizer object. UpdateAreaInit should have been called before this function.");
     }
     for (int m = a.xmin; m <= a.xmax; m++)
     {
         for (int n = a.ymin; n <= a.ymax; n++)
         {
             this.RemoveConnectionsFromTile(this.tiles[m + n * this.tileXCount]);
         }
     }
     for (int num = a.xmin; num <= a.xmax; num++)
     {
         for (int num2 = a.ymin; num2 <= a.ymax; num2++)
         {
             this.BuildTileMesh(voxelize, num, num2);
         }
     }
     uint graphIndex = (uint)AstarPath.active.astarData.GetGraphIndex(this);
     for (int num3 = a.xmin; num3 <= a.xmax; num3++)
     {
         for (int num4 = a.ymin; num4 <= a.ymax; num4++)
         {
             RecastGraph.NavmeshTile navmeshTile3 = this.tiles[num3 + num4 * this.tileXCount];
             GraphNode[] nodes = navmeshTile3.nodes;
             for (int num5 = 0; num5 < nodes.Length; num5++)
             {
                 nodes[num5].GraphIndex = graphIndex;
             }
         }
     }
     a = a.Expand(1);
     a = IntRect.Intersection(a, new IntRect(0, 0, this.tileXCount - 1, this.tileZCount - 1));
     for (int num6 = a.xmin; num6 <= a.xmax; num6++)
     {
         for (int num7 = a.ymin; num7 <= a.ymax; num7++)
         {
             if (num6 < this.tileXCount - 1 && a.Contains(num6 + 1, num7))
             {
                 this.ConnectTiles(this.tiles[num6 + num7 * this.tileXCount], this.tiles[num6 + 1 + num7 * this.tileXCount]);
             }
             if (num7 < this.tileZCount - 1 && a.Contains(num6, num7 + 1))
             {
                 this.ConnectTiles(this.tiles[num6 + num7 * this.tileXCount], this.tiles[num6 + (num7 + 1) * this.tileXCount]);
             }
         }
     }
 }
開發者ID:GameDiffs,項目名稱:TheForest,代碼行數:83,代碼來源:RecastGraph.cs


注:本文中的Pathfinding.IntRect.Expand方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。