新建2个脚本

代码如下:
// 脚本1 TestSertial
using System.Collections.Generic;
using System.Xml.Serialization;
[System.Serializable]
public class TestSertial
{
[XmlAttribute("ID")]
public int ID { get; set; }
[XmlAttribute("Name")]
public string Name { get; set; }
//[XmlAnyAttribute]
//public int Age { get; set; }
[XmlElement("_list")]
public List<int> _list{get;set;}
}
//脚本2 SerializeDemo
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using UnityEngine;
public class SerializeDemo : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
SerializeTestIt();
}
void SerializeTestIt()