示例#1
0
        /// <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>
        /// 写入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);
        }