public void CreateDefaultGrid() { m_Cells = new CellBehaviour[GridWidth, GridHeight]; for (int i = 0; i < GridWidth; i++) { for (int j = 0; j < GridHeight; j++) { CellBehaviour cell = CreateCell(i, j); cell.SetCellData(new CellData(new Cell(i, j))); cell.UpdateEnviroment(); } } }
public void LoadGridData() { GridDataController dataController = GetComponent <GridDataController>(); GridDataController.SavedData data = dataController.GetData(); m_Cells = new CellBehaviour[data.GridWidth, data.GridHeight]; //Создать ячейки for (int i = 0; i < data.CellsData.Count; i++) { CellData cellData = data.CellsData[i]; Cell rootCellData = cellData.RootCell; CellBehaviour cell = CreateCell(rootCellData.X, rootCellData.Y); cell.SetCellData(cellData); //Установка ячейки на уровень Vector3 pos = cell.transform.position; pos.y = cellData.VerticalLevel * VerticalStep; cell.transform.position = pos; } //Создать связи между ячейками for (int i = 0; i < data.GridWidth; i++) { for (int j = 0; j < data.GridHeight; j++) { //Если у ячейки есть связи CellData cellData = m_Cells[i, j].GetCellData(); if (cellData.LinkedCells.Count > 0) { for (int index = 0; index < cellData.LinkedCells.Count; index++) { //Координаты связанной ячейки int x = cellData.LinkedCells[index].X; int y = cellData.LinkedCells[index].Y; //Связать ячейки m_Cells[i, j].LinkCell(m_Cells[x, y], false); } //Обновить вертикальное состояние связей для ячейки m_Cells[i, j].UpdateVerticalDirectionForConnections(false); } } } UpdateEnviroment(); }