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


C# GridCell.GetBlock方法代码示例

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


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

示例1: LoadFromPath

	private void LoadFromPath(string path)
	{		
		if(!File.Exists(path))
		{
			Debug.LogError("File doesn't exist!");
			return;
		}

		GameObject grid = GameObject.Find("Grid");
		Grid gridComponent = grid.GetComponent<Grid>();
		List<List<GridCell>> cells = gridComponent.GetCells();

		StreamReader reader = File.OpenText(path);
		gridComponent.Cells.X = int.Parse(reader.ReadLine());
		gridComponent.Cells.Y = int.Parse(reader.ReadLine());
		gridComponent.CellDimensions.x = float.Parse(reader.ReadLine());
		gridComponent.CellDimensions.y = float.Parse(reader.ReadLine());

		Vector3 centerPosition = Camera.main.transform.position;
		//float centerX = (gridComponent.Cells.X * gridComponent.CellDimensions.x) * 0.5f;
		float centerY = (gridComponent.Cells.Y * gridComponent.CellDimensions.y) * 0.5f;
		float startX = Camera.main.transform.position.x; //centerPosition.x - centerX;
		float startY = centerPosition.y - centerY;

		gridComponent.Reset();
		cells.Clear();

		string readLine = "";
		cells = new List<List<GridCell>>(gridComponent.Cells.Y);
		for (int y = 0; y < gridComponent.Cells.Y; ++y) 
		{
			List<GridCell> newColumn = new List<GridCell>(gridComponent.Cells.X);
			for (int x = 0; x < gridComponent.Cells.X; ++x) 
			{
				GridCell cell = new GridCell();
				cell.SetDimensions(gridComponent.CellDimensions.x, gridComponent.CellDimensions.y);
				cell.SetPosition(startX + gridComponent.CellDimensions.x * 0.5f + (x * gridComponent.CellDimensions.x), (startY + gridComponent.CellDimensions.y * 0.5f + (y * gridComponent.CellDimensions.y)), Camera.main.nearClipPlane);

				readLine = reader.ReadLine();
				if(readLine != "null")
				{
					GameObject block = GameObjectPool.Instance.GetFromPool(readLine, true);
					block.transform.position = cell.GetPosition();

					if(cell.GetBlock() != null)
						GameObjectPool.Instance.AddToPool(cell.GetBlock().gameObject);	

					cell.SetBlock(block.GetComponent<BlockBase>());		
				}
				newColumn.Add(cell);
			}
			cells.Add(newColumn);
		}	
		gridComponent.SetCells(cells);
	}
开发者ID:clovos,项目名称:SpaceSlider,代码行数:55,代码来源:IOManager.cs


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