測試環境 操作系統:Windows8.1 開發工具:Unity5.5.2 1、新建一個測試項目,觀測引用System.Xml與Mono.Xml解析文件正確性,與打包後APK體積大小。 2、Mono.Xml 用例 編譯日誌可以觀測到沒有引用System.Xml.dll(該文件約1mb) 3、Syste ...
測試環境
操作系統:Windows8.1
開發工具:Unity5.5.2
1、新建一個測試項目,觀測引用System.Xml與Mono.Xml解析文件正確性,與打包後APK體積大小。
2、Mono.Xml 用例
using UnityEngine; using Mono.Xml; using System.Security; public class MonoXmlTest : MonoBehaviour { void Start () { SecurityParser parser = new SecurityParser(); string xmlPath = "test"; parser.LoadXml(Resources.Load(xmlPath).ToString()); SecurityElement element = parser.ToXml(); foreach (SecurityElement node in element.Children) { if (node.Tag == "table") { string wave = node.Attribute("wave"); string level = node.Attribute("level"); string name = node.Attribute("name"); Debug.Log("wave:" + wave + " level:" + level + " name:" + name); } } } }
- 結果正確:
- 安裝包大小:
-
編譯日誌可以觀測到沒有引用System.Xml.dll(該文件約1mb)
Mono dependencies included in the build Dependency assembly - Mono.Security.dll Dependency assembly - System.Core.dll Dependency assembly - System.dll Dependency assembly - mscorlib.dll Dependency assembly - UnityEngine.UI.dll Dependency assembly - UnityEngine.Networking.dll Dependency assembly - UnityEngine.PlaymodeTestsRunner.dll Dependency assembly - Assembly-CSharp.dll
3、System.xml用例
using UnityEngine; using System.Xml; public class SystemXmlTest : MonoBehaviour { // Use this for initialization void Start () { XmlDocument xml = new XmlDocument(); XmlReaderSettings set = new XmlReaderSettings(); xml.LoadXml(Resources.Load("test").ToString()); XmlNodeList nodes = xml.SelectSingleNode("ROOT").ChildNodes; foreach (XmlElement node in nodes) { string wave = node.GetAttribute("wave"); string level = node.GetAttribute("level"); string name = node.GetAttribute("name"); Debug.Log("wave:" + wave + " level:" + level + " name:" + name); } } }
- 結果正確:
- 安裝包大小:
- 編譯日誌:可以觀測到引用System.Xml.dll(該文件約1mb)
編譯日誌:可以觀測到引用System.Xml.dll(該文件約1mb) Mono dependencies included in the build Dependency assembly - Mono.Security.dll Dependency assembly - System.Core.dll Dependency assembly - System.Xml.dll Dependency assembly - System.dll Dependency assembly - mscorlib.dll Dependency assembly - UnityEngine.UI.dll Dependency assembly - UnityEngine.Networking.dll Dependency assembly - UnityEngine.PlaymodeTestsRunner.dll Dependency assembly - Assembly-CSharp.dll
4、結論:使用Mono.Xml代替System.Xml在APK安裝包編譯後,體積減小約400kb,建議使用Mono.Xml