I wrote a script to save and load game statistic. It works fine. In this script, two levels have it own score and timer. So, I have to write level by level it own score and timer. The issue is if I have 100 or 200 levels in my game. I have to write for every level. Yes will work, but will take time. So, I was thinking if there any simple method to shift the number of lines like use List or anything else ?
public gameStatic dr;
void Awake() {
Load_game_end();
}
public void Save_game_end() {
BinaryFormatter bf = new BinaryFormatter();
FileStream data_file = File.Create(Application.persistentDataPath + "/WarWorld.datt");
level_static data = new level_static();
data.level1tv = dr.level1t; // level one
data.level2tv = dr.level2t; // level two
//
data.timer1 = dr.finalTime1; // level one
data.timer2 = dr.finalTime2; // level two
//
data.total_money = dr.total_money;
bf.Serialize(data_file, data);
data_file.Close();
Debug.Log("Game full saved");
}
public void Load_game_end() {
if (File.Exists (Application.persistentDataPath + "/WarWorld.datt"))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream data_file = File.Open (Application.persistentDataPath + "/ballworlds.datt", FileMode.Open);
level_static data = (level_static)bf.Deserialize(data_file);
data_file.Close();
dr.level1t= data.level1tv;
dr.level2t = data.level2tv;
//
dr.finalTime1 = data.timer1;
dr.finalTime2 = data.timer2;
//
dr.total_money = data.total_money;
Debug.Log("Game full loaded");
}
else {
Debug.Log("save not found");
}
}
public void delete_save_file() {
File.Delete(Application.persistentDataPath +"/WarWorld.datt");
Debug.Log("delete save file");
}
[Serializable]
class level_static
{
public float total_money;
//
public float level1tv; // height score level 1
public float level2tv;
//
public float timer1; // level 1 timer
public float timer2;
}