How to save and load DateTime date array correctly? Now I save the array like this. Am I doing the right thing or is there a better option?
using UnityEngine; using System; public class NewBehaviourScript : MonoBehaviour { public DateTime[] times = new DateTime[100]; private void Awake() { for (int i = 0; i < 100; i++) { if (PlayerPrefs.HasKey("Time" + i)) { times[i] = DateTime.Parse(PlayerPrefs.GetString("Time" + i)); } } } #if UNITY_ANDROID && !UNITY_EDITOR private void OnApplicationPause(bool pause) { if (pause) { for (int i= 0; i<100; i++) { PlayerPrefs.SetString("Time"+i, times[i].ToString()); } } } #else private void OnApplicationQuit() { for (int i= 0; i<100; i++) { PlayerPrefs.SetString("Time"+i, times[i].ToString()); } } #endif }
PlayerPrefsis the worst way to store anything except some settings. - RiotBr3akerPlayerPrefsextremely slow compared to some of its own json. - RiotBr3aker