public void SaveData() { YarnVarSave save = new YarnVarSave(); DefaultVariable[] saveVars = new DefaultVariable[variables.Count]; int indx = 0; foreach (String var in variables.Keys) { DefaultVariable newVar = new DefaultVariable(); newVar.name = var; newVar.value = variables[var].AsString; newVar.type = variables[var].type; saveVars[indx] = newVar; indx++; } save.variables = saveVars; BinaryFormatter format = new BinaryFormatter(); FileStream fs = File.Create(Application.persistentDataPath + savefile); //Debug.Log(Application.persistentDataPath + savefile); format.Serialize(fs, save); fs.Close(); Debug.Log("Yarn Vars Saved"); }
public bool LoadSaveData() { if (File.Exists(Application.persistentDataPath + savefile)) { BinaryFormatter format = new BinaryFormatter(); FileStream fs = File.Open(Application.persistentDataPath + savefile, FileMode.Open); YarnVarSave save = (YarnVarSave)format.Deserialize(fs); fs.Close(); defaultVariables = save.variables; Debug.Log("Yarn Vars loaded"); return(true); } return(false); }