x


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?

more ▼

asked Jun 22 '12 at 09:18 AM

ina gravatar image

ina
3.4k 500 554 616

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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().

more ▼

answered Jun 22 '12 at 09:26 AM

whydoidoit gravatar image

whydoidoit
33.7k 14 24 105

Does persistentDataPath work across all mobile platforms? It seems that PlayerPrefs has a max filesize of 1 MB?

Jun 22 '12 at 09:29 AM ina

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?

Jun 22 '12 at 09:30 AM ina

hmm how do you get the byte representation of a Texture or Texture2D ?

Jun 23 '12 at 11:53 PM ina

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

Jun 24 '12 at 12:14 AM whydoidoit

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 1MB on the web player - on everything else it is unlimited.

Jun 24 '12 at 12:15 AM whydoidoit
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2614
x2028
x77

asked: Jun 22 '12 at 09:18 AM

Seen: 715 times

Last Updated: Jun 24 '12 at 12:15 AM