Skip to content

Instantly share code, notes, and snippets.

@swt02026
Created January 2, 2015 08:00
Show Gist options
  • Save swt02026/3126ba0e849a3086f723 to your computer and use it in GitHub Desktop.
Save swt02026/3126ba0e849a3086f723 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System.IO;
public class SceneStorer {
static readonly string FILENAME = Application.persistentDataPath+"/"+"scene";
static public void WriteToFile(int sceneID){
//TODO
using(FileStream fs = new FileStream(FILENAME,FileMode.Create,FileAccess.Write)){
using(StreamWriter stream = new StreamWriter(fs)){
stream.WriteLine(sceneID.ToString());
}
}
}
static public int GetSaveLevel(){
if(File.Exists(FILENAME)){
return int.Parse( File.ReadAllText(FILENAME));
}
return -1;
}
static public int ReadFromFile(){
//TODO
using(FileStream fs =
new FileStream(FILENAME,FileMode.OpenOrCreate,FileAccess.ReadWrite)){
using(StreamReader stream = new StreamReader(fs)){
string content = stream.ReadLine();
if(content==null){
using(StreamWriter wstream = new StreamWriter(fs)){
return -1;
}
}
else{
return int.Parse( content);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment