void SaveData() { BinaryFormatter formatter=new BinaryFormatter(); string path=Application.persistentDataPath+"/playerAI.txt"; FileStream stream; if(File.Exists(path)) { stream=new FileStream(path,FileMode.Open); } else { stream=new FileStream(path,FileMode.Create); } storeddata data=new storeddata(numpopulation,currentGeneration,bestAgentSelection); formatter.Serialize(stream,data); stream.Close(); }
void LoadData() { string path=Application.persistentDataPath+"/playerAI.txt"; if(File.Exists(path)) { fileexist=true; BinaryFormatter formatter=new BinaryFormatter(); FileStream stream=new FileStream (path,FileMode.Open); data=formatter.Deserialize(stream) as storeddata; stream.Close(); } }