/// <summary> /// Adds the role.向xml文件中添加一个角色或者添加一个存档 /// </summary> /// <param name="_roleData">_role data.</param> /// <param name="r_and_s">R_and_s.</param> public void AddRole(SunmArchiveBean _roleData) { string newNodeName = ""; newNodeName = "Item"; _xmlDoc.Load(XmlSave_Path); XmlElement newNode = _xmlDoc.CreateElement(newNodeName); newNode.SetAttribute("id", new Vector3(_roleData.x, _roleData.y, _roleData.z) + ""); _xmlDoc.DocumentElement.AppendChild(newNode); XmlElement matarialId = _xmlDoc.CreateElement("matarialId"); matarialId.InnerText = _roleData.matarialId + ""; XmlElement archiveModel = _xmlDoc.CreateElement("archiveModel"); archiveModel.InnerText = _roleData.archiveModel; XmlElement xP = _xmlDoc.CreateElement("xP"); xP.InnerText = _roleData.x + ""; XmlElement yP = _xmlDoc.CreateElement("yP"); yP.InnerText = _roleData.y + ""; XmlElement zP = _xmlDoc.CreateElement("zP"); zP.InnerText = _roleData.z + ""; newNode.AppendChild(matarialId); newNode.AppendChild(xP); newNode.AppendChild(yP); newNode.AppendChild(zP); newNode.AppendChild(archiveModel); _xmlDoc.Save(XmlSave_Path); }
/// <summary> /// 读档 /// </summary> /// <param name="_fileName"></param> /// <param name="_ArchiveList"></param> /// <returns></returns> private IEnumerator loaddingArchiveL(string _ArchivePath, float waitTime) { string filepath = ""; if (Application.platform == RuntimePlatform.Android) { filepath = _ArchivePath; // 在Android中实例化WWW不能在路径前面加"file://" } else { //filepath = "file://" + UnityEngine.Application.streamingAssetsPath + "/" + _fileName; // 在Windows中实例化WWW必须要在路径前面加"file:// } yield return new WaitForSeconds(waitTime); SunmArchive loadArchiveed = new SunmArchive(filepath); List<SunmArchiveBean> _ArchiveList = loadArchiveed.GetDataFromXml(); for (int i = 0; i < _ArchiveList.Count; ++i) { SunmArchiveBean ob = _ArchiveList[i]; ///< 设置占据位置 Vector3 position = new Vector3(ob.x, ob.y, ob.z); SunmGameInit.setThreeArray(position, ob.matarialId); SunmCubeOpt.AddCube(position, SunmConstant.rootCube.transform.rotation, ob.matarialId); // ArchiveMessageProcessing(new object[] { ob.matarialId, position }); /////< 加入新的存档 SunmArchiveBean item = new SunmArchiveBean(ob.matarialId, position.x, position.y, position.z, SunmConstant.level + ""); aArchive.AddRole(item); } _ArchiveList.Clear(); _ArchiveList = null; }
/// <summary> /// 存档信息写入XML /// </summary> /// <param name="_martId"></param> /// <param name="_position"></param> /// <returns></returns> private IEnumerator WriteArchiveInfo(byte _martId, Vector3 _position) { SunmArchiveBean item = new SunmArchiveBean(_martId, _position.x, _position.y, _position.z, SunmConstant.level + ""); aArchive.AddRole(item); yield return 0; }
/// <summary> /// Gets the data from xml.先打开xml然后读取xml里面的内容 /// </summary> /// <returns>The data from xml.</returns> /// <param name="r_and_s">R_and_s.</param> public List<SunmArchiveBean> GetDataFromXml() { _xmlDoc.Load(XmlSave_Path); if (null == dataSetList) { dataSetList = new List<SunmArchiveBean>(); } if (_xmlDoc.DocumentElement.HasChildNodes) { dataSetList.Clear(); XmlNodeList _chilidlist = _xmlDoc.DocumentElement.ChildNodes; foreach (XmlNode xn in _chilidlist) { XmlElement xe = (XmlElement)xn; SunmArchiveBean xds = new SunmArchiveBean( Convert.ToByte(xe.ChildNodes[0].InnerText), Convert.ToSingle(xe.ChildNodes[1].InnerText), Convert.ToSingle(xe.ChildNodes[2].InnerText), Convert.ToSingle(xe.ChildNodes[3].InnerText), xe.ChildNodes[4].InnerText); xds.id = xe.Attributes[0].InnerText; dataSetList.Add(xds); } } _xmlDoc.Save(XmlSave_Path); return dataSetList; }