自定义类:
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using UnityEngine;
public enum StateRange
{
StatePic,
VideoPlaying,
SceneLoad,
}
public class Daji
{
public float daJiWaitForTime = 5.0f;
public int stateRangeInt = 0;
public Daji()
{
}
public Daji(float daJiWaitForTime,StateRange stateRange)
{
this.daJiWaitForTime = daJiWaitForTime;
switch (stateRange)
{
case StateRange.StatePic:
this.stateRangeInt = 0;
break;
case StateRange.VideoPlaying:
this.stateRangeInt = 1;
break;
case StateRange.SceneLoad:
this.stateRangeInt = 2;
break;
}
}
}
public class GuoChang
{
public float GuoChangtForTime = 5.0f;
public int stateRangeInt = 0;
public int isOwnHaveInt = 0;
public GuoChang()
{
}
public GuoChang(float GuoChangtForTime, StateRange stateRange, bool isOwnHave)
{
this.GuoChangtForTime = GuoChangtForTime;
switch (stateRange)
{
case StateRange.StatePic:
this.stateRangeInt = 0;
break;
case StateRange.VideoPlaying:
this.stateRangeInt = 1;
break;
case StateRange.SceneLoad:
this.stateRangeInt = 2;
break;
}
switch (isOwnHave)
{
case false:
this.isOwnHaveInt = 0;
break;
case true:
this.isOwnHaveInt = 1;
break;
}
}
}
public class XunHuan/*: IXmlSerializable*/
{
public float XunHuantForTime = 5.0f;
public int stateRangeInt = 0;
public XunHuan()
{
}
public XunHuan(float XunHuantForTime, StateRange stateRange)
{
this.XunHuantForTime = XunHuantForTime;
switch (stateRange)
{
case StateRange.StatePic:
this.stateRangeInt = 0;
break;
case StateRange.VideoPlaying:
this.stateRangeInt = 1;
break;
case StateRange.SceneLoad:
this.stateRangeInt = 2;
break;
}
}
/* public XmlSchema GetSchema()
{
return null;
}
public void ReadXml(XmlReader reader)
{
//throw new System.NotImplementedException();
reader.Read();//读到XunHuantForTime结点
reader.Read();//读到XunHuantForTime结点包裹的内容
this.XunHuantForTime = float.Parse(reader.Value);
reader.Read();读到XunHuantForTime尾部结点
reader.Read();
reader.Read();
this.stateRangeInt = int.Parse(reader.Value);
}
public void WriteXml(XmlWriter writer)
{
// throw new System.NotImplementedException();
writer.WriteElementString("XunHuantForTime", this.XunHuantForTime.ToString());
writer.WriteElementString("stateRangeInt", this.stateRangeInt.ToString());
}*/
}
public class PlanJiHua3
{
public int version ;
public Daji daji ;
public List<GuoChang> guoChangList ;
public SerizlizerDictionary<int, XunHuan> xunHuanDic ;
}
S后结果:
测试结果 S+D:
XMLSDtes
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class XMLSDtest : MonoBehaviour
{
private void Awake()
{
PlanJiHua3 planJiHua = new PlanJiHua3();
planJiHua.version = 1;
planJiHua.daji = new Daji();
planJiHua.guoChangList = new List<GuoChang>(2) { new GuoChang(), new GuoChang() };
planJiHua.xunHuanDic = new SerizlizerDictionary<int, XunHuan>() { { 1, new XunHuan() }, { 2, new XunHuan() } };
XmlDataMgr.Instance.SaveData(planJiHua, "PlanJiHua3");
}
// Start is called before the first frame update
void Start()
{
PlanJiHua3 planJiHua3 = XmlDataMgr.Instance.LoadData(typeof(PlanJiHua3), "PlanJiHua3") as PlanJiHua3;
Debug.Log("planJiHua3.daji.daJiWaitForTime" + GameDataMgr.Instance.planJiHua3.daji.daJiWaitForTime);
Debug.Log("planJiHua3.daji.daJiWaitForTime" + GameDataMgr.Instance.planJiHua3.xunHuanDic[1].XunHuantForTime);
GameDataMgr.Instance.SetPlanJiHua3(planJiHua3);
Debug.Log("planJiHua3.daji.daJiWaitForTime++++++" + GameDataMgr.Instance.planJiHua3.daji.daJiWaitForTime);
Debug.Log("planJiHua3.daji.daJiWaitForTime++++++" + GameDataMgr.Instance.planJiHua3.xunHuanDic[1].XunHuantForTime);
}
// Update is called once per frame
void Update()
{
}
}