Code: Select all
[Serializable]
public class CreatureVo
{
public int creatrueType;
public int blood;
public override string ToString()
{
return string.Format("Creature-> type:{0} blood:{1}", creatrueType, blood);
}
}
[Serializable]
public class FishVo : CreatureVo
{
public int color;
public override string ToString()
{
return string.Format("Fish-> type:{0} color:{1} blood:{2}", creatrueType, color, blood);
}
}
[Serializable]
public class MonkeyVo : CreatureVo
{
public string name;
public override string ToString()
{
return string.Format("Monkey-> type:{0} name:{1} blood:{2}", creatrueType, name, blood);
}
}
[Serializable]
public class GameVo
{
public List<CreatureVo> AllCreatureVoList;
public GameVo()
{
AllCreatureVoList = new List<CreatureVo>();
}
}
TestCode:
Code: Select all
public class TestLogic : MonoBehaviour
{
public void OnClickSaveBtnES3()
{
var gameVo = GetNewGameVo();
ES3.DeleteFile("vo");
ES3.Save<GameVo>("vo", gameVo);
Debug.Log("ES3 Done save game vo");
}
public void OnClickLoadBtnES3()
{
var gamevo = ES3.Load<GameVo>("vo");
gamevo.AllCreatureVoList.ForEach(Debug.Log);
Debug.Log("ES3 Done load game vo");
}
public void OnClickSaveBtnES2()
{
var gameVo = GetNewGameVo();
ES2.Delete("vo");
ES2.Save(gameVo, "vo");
Debug.Log("ES2 Done save game vo");
}
public void OnClickLoadBtnES2()
{
var gamevo = ES2.Load<GameVo>("vo");
gamevo.AllCreatureVoList.ForEach(Debug.Log);
Debug.Log("ES2 Done load game vo");
}
private GameVo GetNewGameVo()
{
var gamevo = new GameVo();
var monkey = new MonkeyVo
{
name = "Monkey",
blood = 100,
creatrueType = 1
};
gamevo.AllCreatureVoList.Add(monkey);
var fishVo = new FishVo
{
color = 15,
blood = 70,
creatrueType = 2
};
gamevo.AllCreatureVoList.Add(fishVo);
return gamevo;
}
}
Out print log:
ES2:
Creature-> type:1 blood:100
Creature-> type:2 blood:70
ES3:
Monkey-> type:1 name:Monkey blood:100
Fish-> type:2 color:15 blood:70
---
I have test it for ES2 & ES3 . ES3 work fine , but with ES2 it can only store for the parent class.
am i wrong ?
Thanks.
Eran.