本文整理汇总了C#中GridCell.SetPosition方法的典型用法代码示例。如果您正苦于以下问题:C# GridCell.SetPosition方法的具体用法?C# GridCell.SetPosition怎么用?C# GridCell.SetPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GridCell
的用法示例。
在下文中一共展示了GridCell.SetPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnEnable
void OnEnable()
{
Debug.Assert(Cells.X > 0 && Cells.Y > 0 && CellDimensions.x > 0 && CellDimensions.y > 0, "INVALID GRID! Gör om gör rätt!");
Vector3 centerPosition = Camera.main.transform.position;
//float centerX = (Cells.X * CellDimensions.x) * 0.5f;
float centerY = (Cells.Y * CellDimensions.y) * 0.5f;
float startX = centerPosition.x;//centerPosition.x - centerX;
float startY = centerPosition.y - centerY;
m_cells = new List<List<GridCell>>(Cells.Y);
for (int y = 0; y < Cells.Y; ++y)
{
List<GridCell> newColumn = new List<GridCell>(Cells.X);
for (int x = 0; x < Cells.X; ++x)
{
GridCell cell = new GridCell();
cell.SetDimensions(CellDimensions.x, CellDimensions.y);
cell.SetPosition(startX + CellDimensions.x * 0.5f + (x * CellDimensions.x), (startY + CellDimensions.y * 0.5f + (y * CellDimensions.y)), Camera.main.nearClipPlane);
newColumn.Add(cell);
}
m_cells.Add(newColumn);
}
}
示例2: 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);
}