public void CreateConfigFile (Transform cellParent) { XmlDocument xmlDoc = new XmlDocument (); string rootName = "ChessBoard"; XmlDeclaration xmldecl = xmlDoc.CreateXmlDeclaration ("1.0", "UTF-8", ""); xmlDoc.AppendChild (xmldecl); XmlElement root = xmlDoc.CreateElement (rootName); UICellItem[] itemArray = cellParent.GetComponentsInChildren<UICellItem> (); for (int i = 0, length = itemArray.Length; i < length; i++) { XmlElement item = xmlDoc.CreateElement ("Item"); item.SetAttribute ("Pos", itemArray [i].coords.ToString ()); item.SetAttribute ("TargetPos", itemArray [i].targetPos.ToString ()); item.SetAttribute ("Direction", _getDirection (itemArray [i].directions).ToString ()); item.SetAttribute ("Priority", _getPriority (itemArray [i].directions)); root.AppendChild (item); } xmlDoc.AppendChild (root); xmlDoc.Save (GetFilePath ()); MainController.instance.UiDialogBoxPanel.ShowMsgOneBtn ("文件生成成功,对应路径:" + GetFilePath (), null); } public void LoadConfigFile (Transform cellParent) { XmlNodeList nodes; if (!hasFile (GetFilePath ())) { return; } else { XmlDocument xml = new XmlDocument (); xml.Load (@GetFilePath ()); nodes = xml.SelectNodes ("ChessBoard/Item"); } UICellItem[] itemArray = cellParent.GetComponentsInChildren<UICellItem> (); for (int i = 0; i < itemArray.Length; i++) { itemArray [i].ResetItem (); } string[] strTemp; for (int i = 0; i < itemArray.Length; i++) { strTemp = nodes [i].Attributes ["TargetPos"].Value.Split (','); itemArray [i].SetTargetPosInfo (strTemp); strTemp = nodes [i].Attributes ["Priority"].Value.Split (','); itemArray [i].SetItemDirections (strTemp); } }
unity创建xml与加载xml
免责声明:文章转载自《unity创建xml与加载xml》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇Visual Studio 2013 错误系统找不到指定文件,0x80070002反演小结下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=