Ejemplo n.º 1
0
    public object[] Import(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return(null);
        }

        if (!path.EndsWith(".xml"))
        {
            path += ".xml";
        }

        string allPath = string.Concat(ApplicationPath.PersistentRootPath, path);

        if (!File.Exists(allPath))
        {
            UnityEngine.Debug.LogWarning("<<XmlLocalData , Import>> Cant find file . path is " + allPath);
            return(null);
        }

        XmlDocument doc = new XmlDocument();

        doc.LoadXml(File.ReadAllText(allPath));

        XmlNode rootNode = doc.SelectSingleNode("data");

        List <object> deserialieList        = new List <object>();
        Dictionary <string, object> dataDic = new Dictionary <string, object>();

        foreach (XmlNode childNode in rootNode.ChildNodes)
        {
            dataDic.Clear();
            readXml(childNode, dataDic);

            string nodeName    = childNode.Name;
            Type   classType   = Type.GetType(nodeName);
            object objInstance = InjectDataBinder.BindingData(classType, dataDic);

            deserialieList.Add(objInstance);
        }
        return(deserialieList.ToArray());
    }
Ejemplo n.º 2
0
    public object[] Import(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return(null);
        }
        if (!path.EndsWith(".json"))
        {
            path += ".json";
        }

        string txt = FileGameUtil.ReadText(path);

        if (string.IsNullOrEmpty(txt))
        {
            return(null);
        }

        List <object> instanceList = new List <object>();
        ArrayList     dataJson     = MiniJson.jsonDecode(txt) as ArrayList;

        foreach (object obj in dataJson)
        {
            Hashtable itemTab   = obj as Hashtable;
            Type      classType = Type.GetType(Convert.ToString(itemTab["type"]));

            Hashtable dataTab = itemTab["data"] as Hashtable;
            Dictionary <string, object> reflectDic = CopyTo(dataTab);
            object instance = InjectDataBinder.BindingData(classType, reflectDic);
            if (instance != null)
            {
                instanceList.Add(instance);
            }
        }
        return(instanceList.ToArray());
    }