135 lines
4.8 KiB
C#
135 lines
4.8 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Xml;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace HxGame.Data
|
|||
|
|
{
|
|||
|
|
public class JuBaoConfig
|
|||
|
|
{
|
|||
|
|
public int id; //<2F>۱<EFBFBD>id
|
|||
|
|
public int killCount; //<2F><>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD>
|
|||
|
|
public int interval; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
public string curCount; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
|||
|
|
public string refreshCount; //ˢ<><CBA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
public Vector2Int pos; //ˢ<><CBA2><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>
|
|||
|
|
public int radius; //<2F>뾶
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public class JuBaosConfig
|
|||
|
|
{
|
|||
|
|
public List<JuBaoConfig> jubaoConfigs = new List<JuBaoConfig>();
|
|||
|
|
|
|||
|
|
public void SaveXML(int mapId)
|
|||
|
|
{
|
|||
|
|
string path = PathUtil.GetXmlPath(mapId, "JuBaosConfig");
|
|||
|
|
string tmp = path.Substring(0, path.LastIndexOf('/'));
|
|||
|
|
if (!Directory.Exists(tmp))
|
|||
|
|
Directory.CreateDirectory(tmp);
|
|||
|
|
|
|||
|
|
if (File.Exists(path))
|
|||
|
|
File.Delete(path);
|
|||
|
|
|
|||
|
|
XmlDocument xml = new XmlDocument();
|
|||
|
|
XmlDeclaration node = xml.CreateXmlDeclaration("1.0", "utf-8", "no");
|
|||
|
|
xml.AppendChild(node);
|
|||
|
|
|
|||
|
|
XmlElement Root = xml.CreateElement("config");
|
|||
|
|
xml.AppendChild(Root);
|
|||
|
|
|
|||
|
|
XmlElement xmlSettings = xml.CreateElement("Settings");//<2F>ڵ<EFBFBD>Settings
|
|||
|
|
xml.DocumentElement.AppendChild(xmlSettings);
|
|||
|
|
xmlSettings.SetAttribute("mapID", mapId.ToString());
|
|||
|
|
|
|||
|
|
XmlElement JuBaos = xml.CreateElement("JuBaos");//<2F>ڵ<EFBFBD>Settings
|
|||
|
|
xml.DocumentElement.AppendChild(JuBaos);
|
|||
|
|
|
|||
|
|
SaveJuBaos(xml, JuBaos);
|
|||
|
|
|
|||
|
|
xml.Save(path);
|
|||
|
|
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD><EFBFBD>۱<EFBFBD><DBB1><EFBFBD><EFBFBD>óɹ<C3B3>");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SaveJuBaos(XmlDocument xml, XmlElement xmlElement)
|
|||
|
|
{
|
|||
|
|
XmlElement child = null;
|
|||
|
|
for (int i = 0; i < jubaoConfigs.Count; i++)
|
|||
|
|
{
|
|||
|
|
child = xml.CreateElement("JuBao");
|
|||
|
|
child.SetAttribute("id", jubaoConfigs[i].id.ToString());
|
|||
|
|
child.SetAttribute("killCount", jubaoConfigs[i].killCount.ToString());
|
|||
|
|
child.SetAttribute("interval", jubaoConfigs[i].interval.ToString());
|
|||
|
|
child.SetAttribute("curCount", jubaoConfigs[i].curCount.ToString());
|
|||
|
|
child.SetAttribute("refreshCount", jubaoConfigs[i].refreshCount.ToString());
|
|||
|
|
child.SetAttribute("indexX", jubaoConfigs[i].pos.x.ToString());
|
|||
|
|
child.SetAttribute("indexY", jubaoConfigs[i].pos.y.ToString());
|
|||
|
|
child.SetAttribute("radius", jubaoConfigs[i].radius.ToString());
|
|||
|
|
|
|||
|
|
xmlElement.AppendChild(child);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public bool LoadXML(int mapId)
|
|||
|
|
{
|
|||
|
|
string path = PathUtil.GetXmlPath(mapId, "JuBaosConfig");
|
|||
|
|
if (!File.Exists(path))
|
|||
|
|
{
|
|||
|
|
UIWindow.Instance.ShowMessage("û<><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
XmlDocument xmlDocument = new XmlDocument();
|
|||
|
|
xmlDocument.Load(path);
|
|||
|
|
|
|||
|
|
XmlNode xmlRoot = xmlDocument.SelectSingleNode("config");
|
|||
|
|
XmlNode xmlSettings = xmlRoot.SelectSingleNode("Settings");
|
|||
|
|
|
|||
|
|
int id = Convert.ToInt32(xmlSettings.Attributes.GetNamedItem("mapID").Value);
|
|||
|
|
if (id != mapId)
|
|||
|
|
{
|
|||
|
|
UIWindow.Instance.ShowMessage("<22><>ͼID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>鸱<EFBFBD><E9B8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
XmlNode xmlJuBaos = xmlRoot.SelectSingleNode("JuBaos");
|
|||
|
|
LoadJuBaos(xmlJuBaos);
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void LoadJuBaos(XmlNode xmlNodes)
|
|||
|
|
{
|
|||
|
|
if (xmlNodes == null)
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
XmlNode xmlNode = null;
|
|||
|
|
XmlNodeList xmlNodeList = xmlNodes.ChildNodes;
|
|||
|
|
int x, y;
|
|||
|
|
for (int i = 0; i < xmlNodeList.Count; i++)
|
|||
|
|
{
|
|||
|
|
xmlNode = xmlNodeList.Item(i);
|
|||
|
|
if (xmlNode.Name != "JuBao")
|
|||
|
|
continue;
|
|||
|
|
|
|||
|
|
JuBaoConfig mc = new JuBaoConfig();
|
|||
|
|
|
|||
|
|
mc.id = Convert.ToInt32(xmlNode.Attributes.GetNamedItem("id").Value);
|
|||
|
|
mc.killCount = Convert.ToInt32(xmlNode.Attributes.GetNamedItem("killCount").Value);
|
|||
|
|
mc.interval = Convert.ToInt32(xmlNode.Attributes.GetNamedItem("interval").Value);
|
|||
|
|
mc.curCount = xmlNode.Attributes.GetNamedItem("curCount").Value;
|
|||
|
|
mc.refreshCount = xmlNode.Attributes.GetNamedItem("refreshCount").Value;
|
|||
|
|
x = Convert.ToInt32(xmlNode.Attributes.GetNamedItem("indexX").Value);
|
|||
|
|
y = Convert.ToInt32(xmlNode.Attributes.GetNamedItem("indexY").Value);
|
|||
|
|
mc.pos = new Vector2Int(x, y);
|
|||
|
|
mc.radius = Convert.ToInt32(xmlNode.Attributes.GetNamedItem("radius").Value);
|
|||
|
|
|
|||
|
|
jubaoConfigs.Add(mc);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|