Суть сводится к упаковке массива в строку с разделителями и последующем доставании этого массива оттуда, но уже без разделителей.
Плюс, здесь показано как можно работать с несколькими профилями у игроков.
Получаем:
- Код: Выделить всё
public static bool GetLevelProgress(out int[] progress, current_player)
{
if (PlayerPrefs.HasKey("LevelProgress" + "@" + current_player))
{
string res = PlayerPrefs.GetString("LevelProgress" + "@" + current_player);
string[] str = res.Split('|');
int count = str.Length;
progress = new int[count];
for (int i = 0; i < count; i++)
{
progress[i] = int.Parse(str[i]);
}
return true;
}
progress = null;
return false;
}
Засовываем:
- Код: Выделить всё
public static bool SetLevelProgress(int[] progress, current_player)
{
if (progress == null)
return false;
string s = "";
int count = progress.Length;
for (int i = 0; i < count; i++)
{
s += progress[i];
if (i < count - 1)
s += "|";
}
PlayerPrefs.SetString("LevelProgress" + "@" + current_player, s);
return true;
}