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 } 
  • one
    PlayerPrefs is the worst way to store anything except some settings. - RiotBr3aker
  • Save in json format to file - Dodik
  • @ RiotBr3aker Why do you think so? - Andrew
  • @Andrew, because on win this "file" is stored generally speaking in the registry, which does not involve the storage of non- metadata. Moreover, on different platforms there are restrictions on the volume of recording. And the speed of reading from PlayerPrefs extremely slow compared to some of its own json. - RiotBr3aker
  • @ RiotBr3aker Thanks for the explanation. - Andrew

0