Let say you have an array you want to save into Unity using playerpref, and you have a triple array of 50 x 50 x 50 = size of 125,000
public int[,,] map;
void Start()
{
map = new int[50, 50, 50];
}
/////////////////////////////////////
Below is how I do it
///////////////////////////////////
public void savegame()
{
for (int y = 0; y < 50; y++)
{
for (int x = 0; x < 50; x++)
{
for (int z = 0; z < 50; z++)
{
if(map[x,y,z]!=0)
{
PlayerPrefs.SetInt ("mymap"+x+"E"+y+"E"+z+"E",map[x,y,z]);
Debug.Log ("saving " + "mymap"+x+"E"+y+"E"+z+"E");
}
}
}
}
}
void loadgame()
{
for (int y = 0; y < 50; y++)
{
for (int x = 0; x < 50; x++)
{
for (int z = 0; z < 50; z++)
{
map[x,y,z]=PlayerPrefs.GetInt ("mymap"+x+"E"+y+"E"+z+"E");
}
}
}
}
No comments:
Post a Comment