132 lines
4.6 KiB
C#
132 lines
4.6 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Xml;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace HxGame.Data
|
|||
|
|
{
|
|||
|
|
public class FuBenConfig
|
|||
|
|
{
|
|||
|
|
public int order; //ˢ<><CBA2>˳<EFBFBD><CBB3>
|
|||
|
|
public int monsterId;
|
|||
|
|
public Vector2Int pos; //ˢ<><CBA2><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>
|
|||
|
|
public int radius; //<2F>뾶
|
|||
|
|
public int num; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
public int delayTime; //ˢ<><CBA2>ʱ<EFBFBD><CAB1>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public class FuBensConfig
|
|||
|
|
{
|
|||
|
|
public List<FuBenConfig> fubenConfigs = new List<FuBenConfig>();
|
|||
|
|
|
|||
|
|
public void SaveXML(int mapId)
|
|||
|
|
{
|
|||
|
|
string path = PathUtil.GetXmlPath(mapId, "FuBensConfig");
|
|||
|
|
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 Fubens = xml.CreateElement("FuBens");//<2F>ڵ<EFBFBD>Settings
|
|||
|
|
xml.DocumentElement.AppendChild(Fubens);
|
|||
|
|
|
|||
|
|
SaveFuBens(xml, Fubens);
|
|||
|
|
|
|||
|
|
xml.Save(path);
|
|||
|
|
UIWindow.Instance.ShowMessage("<22><><EFBFBD>渱<EFBFBD><E6B8B1><EFBFBD><EFBFBD><EFBFBD>óɹ<C3B3>");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SaveFuBens(XmlDocument xml, XmlElement xmlElement)
|
|||
|
|
{
|
|||
|
|
XmlElement child = null;
|
|||
|
|
for (int i = 0; i < fubenConfigs.Count; i++)
|
|||
|
|
{
|
|||
|
|
child = xml.CreateElement("FuBen");
|
|||
|
|
child.SetAttribute("order", fubenConfigs[i].order.ToString());
|
|||
|
|
child.SetAttribute("monsterId", fubenConfigs[i].monsterId.ToString());
|
|||
|
|
child.SetAttribute("indexX", fubenConfigs[i].pos.x.ToString());
|
|||
|
|
child.SetAttribute("indexY", fubenConfigs[i].pos.y.ToString());
|
|||
|
|
child.SetAttribute("radius", fubenConfigs[i].radius.ToString());
|
|||
|
|
child.SetAttribute("num", fubenConfigs[i].num.ToString());
|
|||
|
|
child.SetAttribute("delayTime", fubenConfigs[i].delayTime.ToString());
|
|||
|
|
|
|||
|
|
xmlElement.AppendChild(child);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public bool LoadXML(int mapId)
|
|||
|
|
{
|
|||
|
|
string path = PathUtil.GetXmlPath(mapId, "FuBensConfig");
|
|||
|
|
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 xmlFuBens = xmlRoot.SelectSingleNode("FuBens");
|
|||
|
|
LoadFuBens(xmlFuBens);
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void LoadFuBens(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 != "FuBen")
|
|||
|
|
continue;
|
|||
|
|
|
|||
|
|
FuBenConfig mc = new FuBenConfig();
|
|||
|
|
|
|||
|
|
mc.order = Convert.ToInt32(xmlNode.Attributes.GetNamedItem("order").Value);
|
|||
|
|
mc.monsterId = Convert.ToInt32(xmlNode.Attributes.GetNamedItem("monsterId").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);
|
|||
|
|
mc.num = Convert.ToInt32(xmlNode.Attributes.GetNamedItem("num").Value);
|
|||
|
|
mc.delayTime = Convert.ToInt32(xmlNode.Attributes.GetNamedItem("delayTime").Value);
|
|||
|
|
|
|||
|
|
fubenConfigs.Add(mc);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|