/// <summary> /// xml转二进制 /// </summary> /// <param name="name"></param> private static void XmlToBinary(string name) { if (string.IsNullOrEmpty(name)) { return; } try { Type type = null; foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { Type tempType = asm.GetType(name); if (tempType != null) { type = tempType; break; } } if (type != null) { string xmlPath = XmlPath + name + ".xml"; string binaryPath = BinaryPath + name + ".bytes"; object obj = BinarySerializeOpt.XmlDeserialize(xmlPath, type); BinarySerializeOpt.BinarySerilize(binaryPath, obj); Debug.Log(name + "xml转二进制成功,二进制路径为:" + binaryPath); } } catch { Debug.LogError(name + "xml转二进制失败!"); } }
/// <summary> /// 反序列化xml到类 /// </summary> /// <param name="name"></param> /// <returns></returns> private static object GetObjFormXml(string name) { Type type = null; foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { Type tempType = asm.GetType(name); if (tempType != null) { type = tempType; break; } } if (type != null) { string xmlPath = XmlPath + name + ".xml"; return(BinarySerializeOpt.XmlDeserialize(xmlPath, type)); } return(null); }
/// <summary> /// 拷贝AB包,生成XML /// </summary> /// <param name="changeList"></param> /// <param name="hotCount"></param> static void CopyABAndGeneratXml(List <string> changeList, string hotCount) { if (!Directory.Exists(m_HotPath)) { Directory.CreateDirectory(m_HotPath); } BuildApp.DeleteDir(m_HotPath); //从AB包目录中,将变化的AB包拷贝到热更目录 foreach (string str in changeList) { if (!str.EndsWith(".manifest")) { File.Copy(m_BundleTargetPath + "/" + str, m_HotPath + "/" + str); } } //生成服务器Patch文件 DirectoryInfo directory = new DirectoryInfo(m_HotPath); FileInfo[] files = directory.GetFiles("*", SearchOption.AllDirectories); Pathces patches = new Pathces(); patches.Version = 1; patches.Des = ""; patches.Files = new List <Patch>(); for (int i = 0; i < files.Length; ++i) { Patch patch = new Patch(); patch.Md5 = MD5Manager.Instance.BuildFileMd5(files[i].FullName); patch.Name = files[i].Name; patch.Size = files[i].Length / 1024.0f; patch.Platform = EditorUserBuildSettings.activeBuildTarget.ToString(); patch.Url = FrameConstr.m_ResServerIp + "AssetBundle/" + PlayerSettings.bundleVersion + "/" + hotCount + "/" + files[i].Name; patches.Files.Add(patch); } BinarySerializeOpt.Xmlserialize(m_HotPath + "/Patch.xml", patches); }
/// <summary> /// 写入AB包的MD5信息 /// </summary> static void WriteABMD5() { //获取AssetBundle文件夹下的所有信息 DirectoryInfo directoryInfo = new DirectoryInfo(m_BundleTargetPath); FileInfo[] files = directoryInfo.GetFiles("*", SearchOption.AllDirectories); ABMD5 abmd5 = new ABMD5(); abmd5.ABMD5List = new List <ABMD5Base>(); for (int i = 0; i < files.Length; ++i) { //过滤meta文件和mainfest文件 if (!files[i].Name.EndsWith(".meta") && !files[i].Name.EndsWith(".manifest")) { ABMD5Base abmd5Base = new ABMD5Base(); abmd5Base.Name = files[i].Name; abmd5Base.Md5 = MD5Manager.Instance.BuildFileMd5(files[i].FullName); abmd5Base.Size = files[i].Length / 1024.0f; abmd5.ABMD5List.Add(abmd5Base); } } string ABMD5Path = Application.dataPath + "/Resources/ABMD5.bytes"; BinarySerializeOpt.BinarySerilize(ABMD5Path, abmd5); //将打包的版本拷贝到外部进行储存 if (!Directory.Exists(m_VersionsMd5Path)) { Directory.CreateDirectory(m_VersionsMd5Path); } string targetPath = m_VersionsMd5Path + "/ABMD5_" + PlayerSettings.bundleVersion + ".bytes"; if (File.Exists(targetPath)) { File.Delete(targetPath); } File.Copy(ABMD5Path, targetPath); }
/// <summary> /// 实际的类转XML /// </summary> /// <param name="name"></param> private static void ClassToXml(string name) { if (string.IsNullOrEmpty(name)) { return; } try { Type type = null; foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { Type tempType = asm.GetType(name); if (tempType != null) { type = tempType; break; } } if (type != null) { var temp = Activator.CreateInstance(type); if (temp is ExcelBase) { (temp as ExcelBase).Construction(); } string xmlPath = XmlPath + name + ".xml"; BinarySerializeOpt.Xmlserialize(xmlPath, temp); Debug.Log(name + "类转xml成功,xml路径为:" + xmlPath); } } catch { Debug.LogError(name + "类转xml失败!"); } }