public override void OnInspectorGUI() { base.OnInspectorGUI(); GridController source = (GridController)target; GridDataController dataController = source.GetComponent <GridDataController>(); if (GUILayout.Button("Create Default Grid")) { source.Clear(); source.CreateDefaultGrid(); } if (dataController.DataExists && GUILayout.Button("Create Grid From Data")) { source.Clear(); source.LoadGridData(); } if (source.GridExists) { if (GUILayout.Button("Save Data")) { source.SaveGridData(); } if (GUILayout.Button("Clear")) { source.Clear(); } } }
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(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); GridDataController source = (GridDataController)target; GridController gridController = source.GetComponent <GridController>(); if (source.DataExists && GUILayout.Button("Serialize")) { source.SerializeData(); } if (GUILayout.Button("Deserialize")) { source.DeserializeData(); } if (source.DataExists && GUILayout.Button("Clear local data")) { source.Clear(); } }
public void SaveGridData() { GridDataController dataController = GetComponent <GridDataController>(); dataController.SaveData(m_Cells, GridWidth, GridHeight, EnviromentIndex); }