How to port this to be compatible with Windows 8 Builds?
using (var outfile = new StreamWriter(Application.persistentDataPath + "/save.sav", false))
outfile.Write(serializedObject);
string _loadData = "";
using (var outfile = new StreamReader(Application.persistentDataPath + "/save.sav", false))
_loadData = outfile.ReadLine();
Any suggestions?
Try this:
string savePath = Path.Combine(Application.persistentDataPath, "save.sav");
#if !UNITY_WINRT
using (var outfile = new StreamWriter(savePath, false))
outfile.Write(serializedObject);
#else
var bytes = System.Text.Encoding.UTF8.GetBytes(serializedObject);
UnityEngine.Windows.File.WriteAllBytes(savePath, bytes);
#endif
string savePath = Path.Combine(Application.persistentDataPath, "save.sav");
string _loadData = "";
#if !UNITY_WINRT
using (var outfile = new StreamReader(savePath, false))
_loadData = outfile.ReadToEnd();
#else
var bytes = UnityEngine.Windows.File.ReadAllBytes(savePath);
_loadData = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
#endif
Another option (in Unity 5.0) is to use StreamReader and StreamWriter from WinRTLegacy. It would be like this:
#if NETFX_CORE
using StreamReader = WinRTLegacy.IO.StreamReader;
using StreamWriter = WinRTLegacy.IO.StreamWriter;
#else
using StreamReader = System.IO.StreamReader;
using StreamWriter = System.IO.StreamWriter;
#endif
I think in Tautvydas example you should use NETFX_CORE instead of UNITY_WINRT
Hi Aurimas!
I tried your code but I got :
Error 44 The type or namespace name ‘IO’ oes not exist in the namespace ‘WinRTLegacy’. (are you missing an assembly reference?
Tautvydas - Your code compiles! I will try it! Thanks!
As I mentioned, my example was for Unity 5, it’s not yet available in 4.5