Write a lot to playerprefs at once?

I have a int[] data And there's like 50 of them. What I need is to somehow write all of them to playerprefs. I suppose I need to use a loop of some sorts, but I don't know how.

Preferred in c# but js will do too.

Also loading the data from playerprefs would be nice too, but I suppose I could backwards code the loop or something.


You could use a pretty simple for loop:

for (var curInt = 0; curInt < data.length; curInt++) {
    PlayerPrefs.SetInt("data " + curInt, data[curInt]);

That will write the contents of data to playerprefs as "data 0", "data 1", etc.

To read them back out, I'd use:

for (var curInt = 0; curInt < data.length; curInt++) {
    data[0] = PlayerPrefs.GetInt("data " + curInt);

Sorry for JS, it's all I know. C# wouldn't be that different, though.

Use ArrayPrefs; it's more efficient than a separate key for every item.