- Home /
Caching texture locally for iOS Android
Is it possible to store a texture(s) loaded at runtime for mobile platforms? It seems PlayerPrefs only supports shorter strings and numbers. Is using a storage engine like SQLite locally the only way?
Answer by whydoidoit · Jun 22, 2012 at 09:26 AM
You can put it in a file :) Save the file in persistentDataPath and you are good to go... If you really want to put it in PlayerPrefs then you can convert the byte representation of it to a string with Convert.ToBase64String() - note that this makes it bigger. Convert it back with Convert.FromBase64String().
Does persistentDataPath work across all mobile platforms? It seems that PlayerPrefs has a max filesize of 1 $$anonymous$$B?
Other question is, how do you query which persistentDataPath is writable on different Android devices? Or, is there a default one sandboxed for each app? Are there size constraints?
hmm how do you get the byte representation of a Texture or Texture2D ?
Sorry I missed your comments :(
You get the bytes of a Texture by calling EncodeToPNG - which returns a byte array - or you can use the GetPixels32 (or GetPixels) to get something that is convertible to a byte array
I believe that the latest releases of Unity (post 3.4) are consistent in the ability to use persistentDataPath. PlayerPrefs only has a maximum of 1$$anonymous$$B on the web player - on everything else it is unlimited.