using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Xml; using UnityEngine; namespace HxGame.Data { public enum Direction { RightUp, //右上 Right, //右 RightDown, //右下 Down, //下 LeftDown, //左下 Left, //左 LeftUp, //左上 Up, //上 } public class NpcConfig { public int id; public Vector2Int pos; //刷怪中心点 public Direction dir; public List paths = new List(); } public class NpcsConfig { public List npcConfigs = new List(); public void SaveXML(int mapId) { string path = PathUtil.GetXmlPath(mapId, "NpcsConfig"); 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");//节点Settings xml.DocumentElement.AppendChild(xmlSettings); xmlSettings.SetAttribute("mapID", mapId.ToString()); XmlElement Npcs = xml.CreateElement("Npcs");//节点Settings xml.DocumentElement.AppendChild(Npcs); SaveNpcs(xml, Npcs); xml.Save(path); UIWindow.Instance.ShowMessage("保存NPC配置成功"); } private void SaveNpcs(XmlDocument xml, XmlElement xmlElement) { XmlElement child = null; for (int i = 0; i < npcConfigs.Count; i++) { child = xml.CreateElement("Npc"); child.SetAttribute("id", npcConfigs[i].id.ToString()); child.SetAttribute("indexX", npcConfigs[i].pos.x.ToString()); child.SetAttribute("indexY", npcConfigs[i].pos.y.ToString()); child.SetAttribute("dir", ((int)npcConfigs[i].dir).ToString()); XmlElement NpcPaths = xml.CreateElement("NpcPaths"); for(int m=0; m