Search Unity

Alternatives when Using Windows 8 Build

Discussion in 'Windows' started by sevensails, Sep 1, 2014.

  1. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    How to port this to be compatible with Windows 8 Builds?

    Code (csharp):
    1.  
    2. using (var outfile = new StreamWriter(Application.persistentDataPath + "/save.sav", false))
    3.             outfile.Write(serializedObject);
    4.  
    Code (csharp):
    1.  
    2.          string _loadData = "";
    3.             using (var outfile = new StreamReader(Application.persistentDataPath + "/save.sav", false))
    4.                 _loadData = outfile.ReadLine();
    5.  
    Any suggestions?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,676
    Try this:

    Code (csharp):
    1.  
    2.     string savePath = Path.Combine(Application.persistentDataPath, "save.sav");
    3.  
    4. #if !UNITY_WINRT
    5.     using (var outfile = new StreamWriter(savePath, false))
    6.         outfile.Write(serializedObject);
    7. #else
    8.     var bytes = System.Text.Encoding.UTF8.GetBytes(serializedObject);
    9.     UnityEngine.Windows.File.WriteAllBytes(savePath, bytes);
    10. #endif
    11.  
    Code (csharp):
    1.  
    2.     string savePath = Path.Combine(Application.persistentDataPath, "save.sav");
    3.     string _loadData = "";
    4.  
    5. #if !UNITY_WINRT
    6.     using (var outfile = new StreamReader(savePath, false))
    7.         _loadData = outfile.ReadToEnd();
    8. #else
    9.     var bytes = UnityEngine.Windows.File.ReadAllBytes(savePath);
    10.     _loadData = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
    11. #endif
    12.  
     
  3. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    Another option (in Unity 5.0) is to use StreamReader and StreamWriter from WinRTLegacy. It would be like this:

    Code (CSharp):
    1. #if NETFX_CORE
    2. using StreamReader = WinRTLegacy.IO.StreamReader;
    3. using StreamWriter = WinRTLegacy.IO.StreamWriter;
    4. #else
    5. using StreamReader = System.IO.StreamReader;
    6. using StreamWriter = System.IO.StreamWriter;
    7. #endif
    I think in Tautvydas example you should use NETFX_CORE instead of UNITY_WINRT
     
  4. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    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!
     
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    As I mentioned, my example was for Unity 5, it's not yet available in 4.5