zoukankan      html  css  js  c++  java
  • unity创建xml与加载xml

      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);
            }
        }
  • 相关阅读:
    Gothic Revival Portal
    通过CRM API for 3CXPhone与其他应用进行对接
    Asp.net Identity 2.0 作弊条
    ReportViewer作弊条
    定制与扩展Asp.NET 5 MVC内建身份验证机制
    在Dynamics CRM 2015中通过3CX插件(以及3CX windows phone)拨出电话
    在Asp.net MVC中使用Authorization Manager (AzMan)进行Windows用户身份认证
    log4net资料收集
    jQuery 插件开发文章收集
    git &github 快速入门
  • 原文地址:https://www.cnblogs.com/Yellow0-0River/p/5362254.html
Copyright © 2011-2022 走看看