/// <summary> /// Load item's datas from Resources /// </summary> /// <param name="fileName">File's name</param> /// <returns>ItemData array</returns> static public ItemData[] LoadItemData(string fileName) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(Resources.Load <TextAsset>(fileName).text); XmlNode itemMes = xmlDoc.SelectSingleNode("ItemMes"); XmlNodeList elements = itemMes.ChildNodes; ItemData[] nodes = new ItemData[elements.Count]; for (int i = 0; i < nodes.Length; i++) { XmlElement element = (XmlElement)elements[i]; nodes[i].id = Convert.ToInt32(element.GetAttribute("ID")); nodes[i].itemType = EnumParse.ToItemType(element.GetAttribute("type")); XmlNodeList childList = element.ChildNodes; nodes[i].repeatable = Convert.ToBoolean(childList.Item(0).InnerText); nodes[i].level = EnumParse.ToItemLevel(childList.Item(1).InnerText); nodes[i].equipmentType = EnumParse.ToEquipmentType(childList.Item(2).InnerText); nodes[i].maxSum = Convert.ToInt32(childList.Item(3).InnerText); nodes[i].picName = childList.Item(4).InnerText; nodes[i].num = 1; } return(nodes); }
public void Load(XmlElement items) { if (items.Name != "inventory_items") { print(items.Name); return; } List <ItemData> data = new List <ItemData>(); ItemData temp = new ItemData(); XmlNodeList nodes = items.ChildNodes; foreach (XmlNode item in nodes) { temp.dataID = XmlConvert.ToInt32(item.Attributes["dataID"].InnerText); print(temp.dataID); temp.id = XmlConvert.ToInt32(item.Attributes["id"].InnerText); print(temp.id); temp.itemType = EnumParse.ToItemType(item.ChildNodes[0].InnerText); print(temp.itemType); temp.picName = item.ChildNodes[1].InnerText; print(temp.picName); temp.repeatable = XmlConvert.ToBoolean(item.ChildNodes[2].InnerText.ToLower()); if (temp.repeatable) { temp.num = XmlConvert.ToInt32(item.ChildNodes[3].InnerText); temp.maxSum = XmlConvert.ToInt32(item.ChildNodes[4].InnerText); } else { if (temp.itemType == ItemType.Equipment) { temp.level = EnumParse.ToItemLevel(item.ChildNodes[3].InnerText); temp.equipmentType = EnumParse.ToEquipmentType(item.ChildNodes[4].InnerText); } } data.Add(temp); } Load(data); }