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); } }