Thank you for your post! I also discovered that you need to call sync function in javascript to ensure saved data is written into indexedDB.
Old Unity you can call this after you saved the data.
Application.ExternalEval("FS.syncfs(false, function (err) {})");
In newer Unity you need to create a .jslib and expose the function to Unity:
https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html
And I wrote something like this in .jslib:
mergeInto(LibraryManager.library, {
WebIdbfsSync: function () {
FS.syncfs(false, function (err) {});
},
});
Then you can call WebIdbfsSync() in Unity. :D
Ralix
Thank you for the update! This is really a great and thorough guide. I hope I get to try it soon.
About the data being saved when you test locally, I'd probably simply split the behaviour if you're not in WebGL, i.e.:
if (Application.platform != RuntimePlatform.WebGLPlayer) SaveNormally();
https://docs.unity3d.com/ScriptReference/Application-platform.html
or platform-dependent compilation
https://docs.unity3d.com/Manual/PlatformDependentCompilation.html
#if UNITY_EDITOR
SaveNormally();
#elif UNITY_WEBGL
Save()
#else
// whatever
#endif
3p0ch
Oh, that looks like it might work nicely by wrapping everything in the class definition in
[code]
public static class NGData {
#if UNITY_WEBGL
the current code
#else
// for each PlayerPrefs.FunctionName
public static void FunctionName(parameters) {
PlayerPrefs.FunctionName(parameters);
}
#endif
}
[/code]