Hi,
I have to save and load data for my game, i’ve got bools, int, floats, arrays of bools int strings or float, 2d arrays,…
I can’t find anything about that…
I’m going to try to use a part the ArrayPrefs script from the wiki unify:
#region Int Array
/// <summary>
/// Stores a Int Array or Multiple Parameters into a Key
/// </summary>
public static bool SetIntArray(string key, params int[] intArray)
{
if (intArray.Length == 0) return false;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i = 0; i < intArray.Length - 1; i++)
sb.Append(intArray[i]).Append("|");
sb.Append(intArray[intArray.Length - 1]);
try { PlayerPrefs.SetString(key, sb.ToString()); }
catch (Exception e) { return false; }
return true;
}
/// <summary>
/// Returns a Int Array from a Key
/// </summary>
public static int[] GetIntArray(string key)
{
if (PlayerPrefs.HasKey(key))
{
string[] stringArray = PlayerPrefs.GetString(key).Split("|"[0]);
int[] intArray = new int[stringArray.Length];
for (int i = 0; i < stringArray.Length; i++)
intArray[i] = Convert.ToInt32(stringArray[i]);
return intArray;
}
return new int[0];
}
I’ll use that to save each array into a single string, and I will split the 2d arrays into simple arrays wich will be saved into a single string aswell.
Do you think it’s doable?
It’s for IOS, can it be problematic performances-wise ?
Anyone has a better idea or found something which does that already ?
Thanks for the help
I’ll post my research progress…