Unity WriteAllBytes Web Player alternative

765 views Asked by At

I have an app that uses a sync function where all the content is saved locally from a server (CMS).

On the server I have text, images and videos. The script is downloading all that info and then is saving the text in text files and images and videos as bytes. In the editor and on android is working well and my question is how I can use an alternative to File.writeAllBytes for the web player. I searched a lot for solutions but I didn't find any. How I can access the file system on local storage from the web player or how can I use the cache system for this?

1

There are 1 answers

3
rutter On

How I can access the file system on local storage from the web player

For security reasons, games run via the Unity Web Player are not given direct access to the file system. Unity's built-in PlayerPrefs system does allow you to store some data locally, but it only supports a few primitive types, and the Web Player limits the data to 1 MB.

It doesn't sound like you're using AssetBundles, but in case you are, the WWW class has a function LoadFromCacheOrDownload that can do some local caching. I'm not aware of any specific reason to limit that function to AssetBundles, but I would speculate that it was originally meant to push devs into buying the Pro license.

You can call JavaScript on the page that's hosting the game, with Application.ExternalCall and Application.ExternalEval, and the page itself can also send messages to the game by interacting with the web player object. I'm not a particularly savvy JS developer, but that may open up some other workarounds.

These limitations may impact your design options.