public static void savePosOfBuilding(testSaving Cam) { //greates the encrypter BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/buildingPos.save"; FileStream stream = new FileStream(path, FileMode.Create); //send the dater further in the system savingBuildPos data = new savingBuildPos(Cam); //encrypt the data formatter.Serialize(stream, data); stream.Close(); }
void Start() { savingBuildPos buildingData = saving.loadPosOfBuilding(); placeBuildings.destroyAllBuildings(); placeBuildings.tpos = new Vector3[1000]; //put the text file into the game for (int i = 0; i < buildingData.buildingsNames.Length; i++) { buildingsPosX.Add(buildingData.posOfBuildingX[i]); buildingsPosY.Add(buildingData.posOfBuildingY[i]); buildingsName.Add(buildingData.buildingsNames[i]); placeBuildings.makeBuilding(buildingsPosX[i], buildingsPosY[i], buildingsName[i]); } }
void Update() { timer -= Time.deltaTime; if (timer <= 0) { timer = 60f; //calls the function there creates the list for one sec placeBuildings.takeOutThePos(); //taking the list from placebuildings buildingsPosX = placeBuildings.buildingsPosX; buildingsPosY = placeBuildings.buildingsPosY; buildingsName = placeBuildings.Names; //gives saving this so that will mean that the saving scripts gets the arrays saving.savePosOfBuilding(this); } //in game content if (Input.GetKeyDown(KeyCode.L)) { savingBuildPos buildingData = saving.loadPosOfBuilding(); placeBuildings.destroyAllBuildings(); placeBuildings.tpos = new Vector3[1000]; //put the text file into the game for (int i = 0; i < buildingData.buildingsNames.Length; i++) { buildingsPosX.Add(buildingData.posOfBuildingX[i]); buildingsPosY.Add(buildingData.posOfBuildingY[i]); buildingsName.Add(buildingData.buildingsNames[i]); placeBuildings.makeBuilding(buildingsPosX[i], buildingsPosY[i], buildingsName[i]); } } //gives the system the data else if (Input.GetKeyDown(KeyCode.P)) { //calls the function there creates the list for one sec placeBuildings.takeOutThePos(); //taking the list from placebuildings buildingsPosX = placeBuildings.buildingsPosX; buildingsPosY = placeBuildings.buildingsPosY; buildingsName = placeBuildings.Names; //gives saving this so that will mean that the saving scripts gets the arrays saving.savePosOfBuilding(this); } }
//real in game save the others was just an test public static savingBuildPos loadPosOfBuilding() { string path = Application.persistentDataPath + "/buildingPos.save"; Debug.Log(Application.persistentDataPath + "/buildingPos.save"); if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); savingBuildPos data = formatter.Deserialize(stream) as savingBuildPos; stream.Close(); return(data); } else { Debug.LogError("Save File Not Found in " + path); return(null); } }