本文共 1412 字,大约阅读时间需要 4 分钟。
?Unity3D????????????????????????????????????????????Windows??Mac??????????PC????????????????????????????????????????????????????????????????????????????????CSV???XML???
?Unity3D???????????????????????????????????????XML?JSON???????????????????????????????????????????????????????????????
???????C#?Unity3D?????XML????????????????????????????XML??????????????
???????
using System;using System.IO;using System.Collections.Generic;using System.Linq;using System.Xml;public class XmlToObjectwhere T : new(){ public T ParseXml(string filePath) { var xml = File.ReadAllText(filePath); var root = Xml.Deserialize(xml) as XmlNode; if (root.Name != "???") { throw new ArgumentException("?????"); } var obj = new T(); var properties = obj.GetType().GetProperties(); foreach (XmlNode node in root.ChildNodes) { var property = properties.FirstOrDefault(p => p.Name == node.Name); if (property == null) { continue; } var value = node.Value; if (value != null) { property.SetValue(obj, value); } } return obj; }}
?????????????XML?????????????????????????????????????????????????????????????
?????????????????????????????????????????????XML???????????????????????????????????????????????????
转载地址:http://irei.baihongyu.com/