当前位置: 首页>>代码示例>>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;未经允许,请勿转载。