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


C# IntRect.Expand方法代码示例

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


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

示例1: UpdateGraphCoroutine

	/** Async method for moving the graph */
	IEnumerator UpdateGraphCoroutine () {

		// Find the direction
		// that we want to move the graph in.
		// Calcuculate this in graph space (where a distance of one is the size of one node)
		Vector3 dir = PointToGraphSpace(target.position) - PointToGraphSpace(graph.center);

		// Snap to a whole number of nodes
		dir.x = Mathf.Round(dir.x);
		dir.z = Mathf.Round(dir.z);
		dir.y = 0;

		// Nothing do to
		if ( dir == Vector3.zero ) yield break;

		// Number of nodes to offset in each direction
		Int2 offset = new Int2(-Mathf.RoundToInt(dir.x), -Mathf.RoundToInt(dir.z));

		// Move the center (this is in world units, so we need to convert it back from graph space)
		graph.center += graph.matrix.MultiplyVector (dir);
		graph.GenerateMatrix ();

		// Create a temporary buffer
		// required for the calculations
		if ( tmp == null || tmp.Length != graph.nodes.Length ) {
			tmp = new GridNode[graph.nodes.Length];
		}

		// Cache some variables for easier access
		int width = graph.width;
		int depth = graph.depth;
		GridNode[] nodes = graph.nodes;

		// Check if we have moved
		// less than a whole graph
		// width in any direction
		if ( Mathf.Abs(offset.x) <= width && Mathf.Abs(offset.y) <= depth ) {
		
			// Offset each node by the #offset variable
			// nodes which would end up outside the graph
			// will wrap around to the other side of it
			for ( int z=0; z < depth; z++ ) {
				int pz = z*width;
				int tz = ((z+offset.y + depth)%depth)*width;
				for ( int x=0; x < width; x++ ) {
					tmp[tz + ((x+offset.x + width) % width)] = nodes[pz + x];
				}
			}
			
			yield return null;

			// Copy the nodes back to the graph
			// and set the correct indices
			for ( int z=0; z < depth; z++ ) {
				int pz = z*width;
				for ( int x=0; x < width; x++ ) {
					GridNode node = tmp[pz + x];
					node.NodeInGridIndex = pz + x;
					nodes[pz + x] = node;
				}
			}


			IntRect r = new IntRect ( 0, 0, offset.x, offset.y );
			int minz = r.ymax;
			int maxz = depth;

			// If offset.x < 0, adjust the rect
			if ( r.xmin > r.xmax ) {
				int tmp2 = r.xmax;
				r.xmax = width + r.xmin;
				r.xmin = width + tmp2;
			}

			// If offset.y < 0, adjust the rect
			if ( r.ymin > r.ymax ) {
				int tmp2 = r.ymax;
				r.ymax = depth + r.ymin;
				r.ymin = depth + tmp2;
	
				minz = 0;
				maxz = r.ymin;
			}

			// Make sure erosion is taken into account
			// Otherwise we would end up with ugly artifacts
			r = r.Expand ( graph.erodeIterations + 1 );

			// Makes sure the rect stays inside the grid
			r = IntRect.Intersection ( r, new IntRect ( 0, 0, width, depth ) );
	
			yield return null;

			// Update all nodes along one edge of the graph
			// With the same width as the rect
			for ( int z = r.ymin; z < r.ymax; z++ ) {
				for ( int x = 0; x < width; x++ ) {
					graph.UpdateNodePositionCollision ( nodes[z*width + x], x, z, false );
				}
//.........这里部分代码省略.........
开发者ID:JtheSpaceC,项目名称:Breaking-The-Rules,代码行数:101,代码来源:ProceduralGridMover.cs

示例2: UpdateGraph

	public IEnumerator UpdateGraph () {

		Vector3 dir = target.position - graph.center;

		// Snap to a whole number of nodes
		dir.x = Mathf.Round(dir.x/graph.nodeSize)*graph.nodeSize;
		dir.z = Mathf.Round(dir.z/graph.nodeSize)*graph.nodeSize;
		dir.y = 0;

		if ( dir == Vector3.zero ) yield break;

		Int2 offset = new Int2 ( -Mathf.RoundToInt(dir.x/graph.nodeSize), -Mathf.RoundToInt(dir.z/graph.nodeSize) );

		// Move the center
		graph.center += dir;
		graph.GenerateMatrix ();

		if ( tmp == null || tmp.Length != graph.nodes.Length ) {
			tmp = new GridNode[graph.nodes.Length];
		}

		int width = graph.width;
		int depth = graph.depth;
		GridNode[] nodes = graph.nodes;
		
		if ( Mathf.Abs(offset.x) <= width && Mathf.Abs(offset.y) <= depth ) {
		
			for ( int z=0; z < depth; z++ ) {
				int pz = z*width;
				int tz = ((z+offset.y + depth)%depth)*width;
				for ( int x=0; x < width; x++ ) {
					tmp[tz + ((x+offset.x + width) % width)] = nodes[pz + x];
				}
			}
			
			yield return null;
			
			for ( int z=0; z < depth; z++ ) {
				int pz = z*width;
				for ( int x=0; x < width; x++ ) {
					GridNode node = tmp[pz + x];
					node.NodeInGridIndex = pz + x;
					nodes[pz + x] = node;
				}
			}
	
			IntRect r = new IntRect ( 0, 0, offset.x, offset.y );
			int minz = r.ymax;
			int maxz = depth;
	
			if ( r.xmin > r.xmax ) {
				int tmp2 = r.xmax;
				r.xmax = width + r.xmin;
				r.xmin = width + tmp2;
			}
			if ( r.ymin > r.ymax ) {
				int tmp2 = r.ymax;
				r.ymax = depth + r.ymin;
				r.ymin = depth + tmp2;
	
				minz = 0;
				maxz = r.ymin;
			}
	
			//Debug.Log ( "R1 " + r );
			r = r.Expand ( graph.erodeIterations + 1 );
			r = IntRect.Intersection ( r, new IntRect ( 0, 0, width, depth ) );
	
			//Debug.Log ( "R2 " + r );
	
			yield return null;
	
			for ( int z = r.ymin; z < r.ymax; z++ ) {
				for ( int x = 0; x < width; x++ ) {
					graph.UpdateNodePositionCollision ( nodes[z*width + x], x, z, false );
				}
			}
	
			yield return null;
	
			for ( int z = minz; z < maxz; z++ ) {
				for ( int x = r.xmin; x < r.xmax; x++ ) {
					graph.UpdateNodePositionCollision ( nodes[z*width + x], x, z, false );
				}
			}
	
			yield return null;
	
			for ( int z = r.ymin; z < r.ymax; z++ ) {
				for ( int x = 0; x < width; x++ ) {
					graph.CalculateConnections (nodes, x, z, nodes[z*width+x]);
				}
			}
	
			yield return null;
	
			for ( int z = minz; z < maxz; z++ ) {
				for ( int x = r.xmin; x < r.xmax; x++ ) {
					graph.CalculateConnections (nodes, x, z, nodes[z*width+x]);
				}
//.........这里部分代码省略.........
开发者ID:Gapti,项目名称:ClashOfClanRIP,代码行数:101,代码来源:ProceduralGridMover.cs


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