Exemplo n.º 1
0
        public static Dictionary <string, object> loadXML(string fileName, Type type)
        {
            int    num   = 0;
            string text  = string.Empty;
            string empty = string.Empty;

            try
            {
                TextAsset textAsset = Resources.Load("Data/BinData/" + fileName, typeof(TextAsset)) as TextAsset;
                if (textAsset != null)
                {
                    StringReader stringReader = new StringReader(textAsset.text);
                    XmlReader    xmlReader    = XmlReader.Create(stringReader);
                    XmlDocument  xmlDocument  = new XmlDocument();
                    string       text2        = stringReader.ReadToEnd();
                    text2.Replace("&", "&amp;");
                    xmlDocument.LoadXml(text2);
                    xmlDocument.Load(Application.dataPath + "Resources/Data/BinData/" + fileName + ".xml");
                    xmlReader.Close();
                    XmlNodeList xmlNodeList = xmlDocument.SelectNodes("root/item");
                    int         count       = xmlNodeList.Count;
                    if (count > 0)
                    {
                        Dictionary <string, object> dictionary = new Dictionary <string, object>();
                        foreach (XmlNode xmlNode in xmlNodeList)
                        {
                            text = string.Concat(new string[]
                            {
                                "<",
                                fileName,
                                ">",
                                xmlNode.InnerXml,
                                "</",
                                fileName,
                                ">"
                            });
                            object value = SerializerUtils.xmlDeserialize(type, text);
                            dictionary.Add(xmlNode.FirstChild.InnerText, value);
                            num++;
                        }
                        return(dictionary);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(string.Concat(new string[]
                {
                    " ==> loadXML failed : fileName = ",
                    fileName,
                    " _itemData=",
                    text,
                    " error=",
                    ex.Message
                }));
            }
            return(null);
        }
Exemplo n.º 2
0
 public static void ZipSerialize(string path, object data, int level = 2)
 {
     using (FileStream fileStream = File.Create(path))
     {
         using (MemoryStream memoryStream = new MemoryStream())
         {
             BinaryFormatter binaryFormatter = new BinaryFormatter();
             binaryFormatter.Serialize(memoryStream, data);
             memoryStream.Seek(0L, SeekOrigin.Begin);
             SerializerUtils.ZipStream(memoryStream, fileStream, level);
         }
     }
 }
Exemplo n.º 3
0
 public static string xmlSerialize(object pObject, Type type)
 {
     try
     {
         MemoryStream  memoryStream  = new MemoryStream();
         XmlSerializer xmlSerializer = new XmlSerializer(type);
         XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
         xmlSerializer.Serialize(xmlTextWriter, pObject);
         memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
         return(SerializerUtils.UTF8ByteArrayToString(memoryStream.ToArray()));
     }
     catch (Exception ex)
     {
         Debug.LogError("warn\n" + ex.Message);
     }
     return(null);
 }
Exemplo n.º 4
0
        public static object ZipDeserialize(string path)
        {
            object result;

            using (FileStream fileStream = File.OpenRead(path))
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    SerializerUtils.UnzipStream(fileStream, memoryStream);
                    BinaryFormatter binaryFormatter = new BinaryFormatter
                    {
                        Binder = new UBinder()
                    };
                    memoryStream.Seek(0L, SeekOrigin.Begin);
                    object obj = binaryFormatter.Deserialize(memoryStream);
                    result = obj;
                }
            }
            return(result);
        }