Beispiel #1
0
        public static TItem LoadItem <TItem>() where TItem : Item, new()
        {
            TItem       item     = new TItem();
            string      itemName = typeof(TItem).Name;
            XmlDocument xml      = new XmlDocument();

#if UNITY_EDITOR
            string path = Application.dataPath + "/Resources/ItemXml/" + itemName + ".xml";
            xml.Load(path);
#else
            string data = Resources.Load("ItemXml/" + itemName).ToString();
            xml.LoadXml(data);
#endif
            XmlElement root = (XmlElement)(xml.SelectSingleNode("Root"));
            item.SetName(root.GetAttribute("Name"));
            item.resourcesName_ = root.GetAttribute("Resources");
            int        parameterCount = int.Parse(root.GetAttribute("parameterCount"));
            XmlElement parameters     = (XmlElement)(root.SelectSingleNode("parameters"));
            item.parameters = new Dictionary <string, float>();
            for (int i = 0; i < parameterCount; i++)
            {
                item.parameters[parameters.Attributes[i].Name] = float.Parse(parameters.Attributes[i].Value);
            }
            if (item == null)
            {
                Debug.Log("ERROR TYPE!");
            }
            if (xml == null)
            {
                Debug.Log("XML FILE NOT FOUND!");
                return(null);
            }
            return(item);
        }