In my project, the SaveData class save and load works on Unity Editor, but not on Android (not tested on iOS), and I am having problems with corrupted save data or missing (not saved?) save data.
The save data is saved in SaveData class, which contains the custom classes skill_data, WorldData, and Owned_skill. Of these, skill_data and WorldData are ScriptableObjects.
Code: Select all
using System.Collections.Generic;
[System.Serializable]
public class SaveData
{
public int jewel;
public int enemies_defeated;
public bool got_first_weapon;
public bool playing_now;
public bool FirstSettingDone;
public bool CanRevive;
public int enemies_defeated;
public skill_data first_equipped_skill;
public WorldData current_world;
public List<Owned_skill> saved_skill;
public List<skill_data> registered_list;
public static readonly int Upgrades = 4;
public int[] Player_UpgradeLv = new int[Upgrades];
public int RerollLeft;
public int LV;
public float CurrentExp;
public float BGMVolume, SEVolume;
public static readonly int Descriptions = 2;
public bool[] DescriptionDone = new bool[Descriptions];
public bool CanAccessGachaAndUpgrade;
public SaveData()
{
}
public SaveData(SaveData Copydata)
{
jewel = Copydata.jewel;
playing_now = Copydata.playing_now;
FirstSettingDone = Copydata.FirstSettingDone;
CanRevive = Copydata.CanRevive;
got_first_weapon = Copydata.got_first_weapon;
enemies_defeated = Copydata.enemies_defeated;
first_equipped_skill = Copydata.first_equipped_skill;
current_world = Copydata.current_world;
saved_skill = new List<Owned_skill>(Copydata.saved_skill);
registered_list = new List<skill_data>(Copydata.registered_list);
BGMVolume = Copydata.BGMVolume;
SEVolume = Copydata.SEVolume;
for (int i = 0; i < Copydata.Player_UpgradeLv.Length; i++)
{
Player_UpgradeLv[i] = Copydata.Player_UpgradeLv[i];
}
for (int i = 0; i < Copydata.DescriptionDone.Length; i++)
{
DescriptionDone[i] = Copydata.DescriptionDone[i];
}
RerollLeft = Copydata.RerollLeft;
LV= Copydata.LV;
CurrentExp = Copydata.CurrentExp;
CanAccessGachaAndUpgrade = Copydata.CanAccessGachaAndUpgrade;
}
}
Code: Select all
private void Awake()
{
DataLoad();
}
public void DataSave()
{
ES3.Save("RunGame", saved_data);
}
public void DataLoad()
{
if (ES3.KeyExists("RunGame"))
{
SaveData LoadData =
(SaveData)ES3.Load("RunGame");
saved_data = new SaveData(LoadData);
}
}
private void OnApplicationQuit()
{
DataSave();
}
private void OnApplicationPause(bool pauseStatus)
{
if (pauseStatus)
DataSave();
}
The first is that when the save data is corrupted, the primitive data types such as jewel and Player_UpgradeLv are saved normally and the loading problem occurs only in the custom classes.
The second is that on Android, when you return to the home screen to close the game, the game is not saved immediately, but you have to wait for a while. You have to wait for a while. If you close the game quickly, the game does not save.
Thanks in advance.