void LoadMap(HexSave[,] hS) { height = hS.GetLength (0); width = hS.GetLength (1); hexGraph = ResizeMD (hexGraph, height, width); Vector3 pos; for (int h = 0; h < height; h++) { for(int w = 0; w < width; w++){ //Debug.Log (h+", "+w+":"+hS[h,w].matIndex+", "+hexGroup.hexes[hS[h,w].matIndex].mat); if(hexGraph[h,w] == null){ pos = new Vector3(hS[h,w].posX, hS[h,w].posY, hS[h,w].posZ); CreateHex (h, w, hS[h,w].matIndex, pos); } else{ hexGraph[h,w].tile.transform.position = new Vector3(hS[h,w].posX, hS[h,w].posY, hS[h,w].posZ); hexGraph[h,w].matIndex = hS[h,w].matIndex; hexGraph[h,w].tile.gameObject.GetComponent<MeshRenderer>().material = hexGroup.hexes[hS[h,w].matIndex].mat; } hexGraph[h,w].oreFlag = hS[h,w].oreFlag; hexGraph[h,w].tile.GetComponent<Animator>().SetInteger ("OreState", hexGraph[h,w].oreFlag); //Debug.Log (h+", "+w+": "+hexGraph[h,w].oreFlag); } } GraphMap (); }
public void Save() { BinaryFormatter bf = new BinaryFormatter(); FileStream file; //string fName = Path.GetFileNameWithoutExtension (EditorApplication.currentScene); if (File.Exists (Application.persistentDataPath + "/" + levelName + ".hex")) { file = File.Open (Application.persistentDataPath + "/" + levelName + ".hex", FileMode.Open); } else { file = File.Create (Application.persistentDataPath + "/" + levelName + ".hex"); } //Debug.Log (hexGraph.GetLength (0) + " Lengths " + hexGraph.GetLength (1)); HexSave[,] hexSave = new HexSave[hexGraph.GetLength (0), hexGraph.GetLength (1)]; for (int i = 0; i < hexGraph.GetLength (0); i++) { for (int k = 0; k < hexGraph.GetLength (1); k++){ HexSave hS = new HexSave(); hS.matIndex = hexGraph[i,k].matIndex; //Debug.Log (hS.matIndex+" : "+hexGraph[i,k].matIndex); hS.posX = hexGraph[i,k].position.x; hS.posY = hexGraph[i,k].position.y; //Debug.Log (hS.posY); hS.posZ = hexGraph[i,k].position.z; hS.oreFlag = hexGraph[i, k].oreFlag; hexSave[i,k] = hS; } } bf.Serialize (file, hexSave); file.Close (); Debug.Log (levelName + " Saved!"); /* SpawnList data = new SpawnList (); foreach (UnitCallScript unit in unitList) { SpawnData spawn = new SpawnData(); spawn.callTime = unit.callTime; spawn.groupNum = unit.groupNum; spawn.sinceLast = unit.sinceLast; spawn.unitName = unit.unit.name; data.spawnData.Add(spawn); } bf.Serialize (file, data); file.Close (); Debug.Log ("Saved " + file.Name); */ }