public void SaveFile() { HexCellMsgArray tempCell = CreateCellMsg(); string jsonStr = JsonUtility.ToJson(tempCell); StreamWriter sw = new StreamWriter(Application.dataPath + "/" + ScenesName + ".txt"); sw.Write(jsonStr); sw.Close(); }
HexCellMsgArray CreateCellMsg() { HexCellMsgArray tempCell = new HexCellMsgArray() { cellArray = new List <HexCellMsg>() }; for (int i = 0; i < cellCountX * cellCountZ; i++) { HexCellMsg temp = new HexCellMsg(); temp.x = cells[i].x; temp.y = cells[i].z; temp.color = cells[i].Color; temp.Elevation = cells[i].Elevation; tempCell.cellArray.Add(temp); } return(tempCell); }
void LoadFile() { if (File.Exists(Application.dataPath + "/" + ScenesName + ".txt")) { StreamReader sr = new StreamReader(Application.dataPath + "/" + ScenesName + ".txt"); string temp = sr.ReadToEnd(); HexCellMsgArray tempMeg = JsonUtility.FromJson <HexCellMsgArray>(temp); cells = new HexCell[cellCountX * cellCountZ]; for (int i = 0; i < cellCountX * cellCountZ; i++) { CreateCell(tempMeg.cellArray[i].x, tempMeg.cellArray[i].y, i, tempMeg.cellArray[i].color, tempMeg.cellArray[i].Elevation); } } else { CreateCells(); } }