Exemple #1
0
 private static void Xml2Binary(string className)
 {
     if (string.IsNullOrEmpty(className))
     {
         return;
     }
     try
     {
         Type type = null;
         foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
         {
             Type tempTyep = asm.GetType(className);
             if (tempTyep != null)
             {
                 type = tempTyep;
                 break;
             }
         }
         if (type != null)
         {
             string        xmlPath    = XmlDataPath + className + ".xml";
             string        binaryPath = BinaryPath + className + ".bytes";
             System.Object obj        = SerializeOperate.XmlDeserialize4Editor(xmlPath, type);
             SerializeOperate.BinarySerialize(binaryPath, obj);
             Debug.Log("Xml转类,类再转二进制成功...");
         }
     }
     catch (Exception exception)
     {
         Debug.LogError("Xml转类,类再转二进制失败. " + exception.Message);
     }
 }
Exemple #2
0
        //加载配置表, path为二进制路径
        public T LoadXmlData <T>(string path) where T : XmlDataBase
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }
            if (m_allXmlDataDict.ContainsKey(path))
            {
                Debug.LogError("重复加载了相同的XmlData数据.");
                return(m_allXmlDataDict[path] as T);
            }

            T xmlData = SerializeOperate.BinaryDeserialize <T>(path);

#if UNITY_EDITOR
            if (xmlData == null)
            {
                Debug.Log(path + "不存在, 从对应的Xml文件加载数据.");
                string xmlPath = path.Replace(".bytes", ".xml");
                xmlData = SerializeOperate.XmlDeserialize4Editor <T>(xmlPath);
            }
#endif
            if (null != xmlData)
            {
                xmlData.Init();
            }
            m_allXmlDataDict.Add(path, xmlData);
            return(xmlData);
        }