public ArrayList loadSpecialItemXmlToArray() { //保存路径 string filepath = "Config/Materiral/SpecialItem"; string _result = Resources.Load(filepath).ToString(); ArrayList specialItemList = new ArrayList(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(_result); XmlNodeList nodeList = xmlDoc.SelectSingleNode("SpecialItemList").ChildNodes; foreach (XmlElement special in nodeList) { Materiral.SpecialItem _sitem = new Materiral.SpecialItem(); //读取node内属性,把string转化为对应的属性 if (special.GetAttribute("ID") != "") { _sitem.ID = int.Parse(special.GetAttribute("ID")); } if (special.GetAttribute("Name") != "") { _sitem.Name = special.GetAttribute("Name"); } if (special.GetAttribute("Image") != "") { _sitem.IMG = special.GetAttribute("Image"); } if (special.GetAttribute("Type") != "") { _sitem.Type = int.Parse(special.GetAttribute("Type")); } if (special.GetAttribute("Price") != "") { _sitem.Price = int.Parse(special.GetAttribute("Price")); } if (special.GetAttribute("Property") != "") { string[] _proStr = special.GetAttribute("Property").Split(','); _sitem.Property = new int[_proStr.Length]; for (int i = 0; i < _proStr.Length; i++) { _sitem.Property[i] = int.Parse(_proStr[i]); } } if (special.GetAttribute("des") != "") { _sitem.Des = special.GetAttribute("des"); } //添加进itemList中 specialItemList.Add(_sitem); } return(specialItemList); }
static public int AddGoodsByID(int materialType, int ID) { Goods newgoods = new Goods(); newgoods.ID = ID; newgoods.Number = 1; newgoods.Property = Materiral.GetMaterialProperty(materialType, ID); newgoods.Quality = 80; if (materialType == 0) { Materiral.Items _item = Materiral.FindItemByID(ID); newgoods.Name = _item.Name; newgoods.Price = _item.Price; newgoods.Type = _item.Type; } //item else if (materialType == 1) { Materiral.Minds _mind = Materiral.FindMindByID(ID); newgoods.Name = _mind.Name; newgoods.Price = _mind.Price; newgoods.Type = _mind.Type; newgoods.MateriralType = 1; } //mind else if (materialType == 2) { Materiral.SpecialItem _sepcial = Materiral.FindSpecialItemByID(ID); newgoods.Name = _sepcial.Name; newgoods.Price = _sepcial.Price; newgoods.Type = _sepcial.Type; newgoods.MateriralType = 2; } //specail //添加物品 int uid = AddGoods(newgoods); return(uid); }