This should fully make browser savefile work now
This commit is contained in:
1 file changed
+23
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -45,6 +46,8 @@ public class BazookaManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Load()
|
public void Load()
|
||||||
|
{
|
||||||
|
if (Application.platform != RuntimePlatform.WebGLPlayer)
|
||||||
{
|
{
|
||||||
string path = Path.Join(Application.persistentDataPath, "save.json");
|
string path = Path.Join(Application.persistentDataPath, "save.json");
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
@@ -68,17 +71,37 @@ public class BazookaManager : MonoBehaviour
|
|||||||
saveFile["version"] = "0";
|
saveFile["version"] = "0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var tempSaveFile = JObject.Parse(File.ReadAllText(Encoding.UTF8.GetString(Convert.FromBase64String(PlayerPrefs.GetString("saveFile", "e30=")))));
|
||||||
|
if (tempSaveFile != null) saveFile = tempSaveFile;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Debug.LogWarning("Failed to load save file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
|
if (Application.platform != RuntimePlatform.WebGLPlayer)
|
||||||
|
{
|
||||||
string path = Path.Join(Application.persistentDataPath, "save.json");
|
string path = Path.Join(Application.persistentDataPath, "save.json");
|
||||||
var encoded = Encoding.UTF8.GetBytes(saveFile.ToString());
|
var encoded = Encoding.UTF8.GetBytes(saveFile.ToString());
|
||||||
using var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
|
using var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||||
fileStream.Write(encoded, 0, encoded.Length);
|
fileStream.Write(encoded, 0, encoded.Length);
|
||||||
fileStream.Flush(true);
|
fileStream.Flush(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlayerPrefs.SetString("saveFile", Convert.ToBase64String(Encoding.UTF8.GetBytes(saveFile.ToString(Newtonsoft.Json.Formatting.None))));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user