コード例 #1
0
    static void BuildRes()
    {
        //准备工作
        var rootDir     = new DirectoryInfo(GameConst.BUILD_ROOT);
        var rootABDir   = new DirectoryInfo(Path.Combine(rootDir.FullName, "./AssetBundles"));
        var versionFile = new FileInfo(Path.Combine(rootDir.FullName, "./Version"));

        if (!Directory.Exists(rootABDir.FullName))
        {
            Directory.CreateDirectory(rootABDir.FullName);
            Debug.Log("Build - AB文件夹不存在,重新创建");
        }
        if (!Directory.Exists(rootDir.FullName))
        {
            Directory.CreateDirectory(rootDir.FullName);
            Debug.Log("Build文件夹不存在,重新创建");
        }
        foreach (var fileInfo in rootABDir.GetFiles())
        {
            //清空导出AB包文件
            fileInfo.Delete();
        }
        //构建资源
        List <ABVObject> abVObjectList = new List <ABVObject>();

        string[] blackFilesName = new string[] { "AssetBundles" };
        foreach (var file in new DirectoryInfo(GameConst.BUILD_AB_ROOT).GetFiles())
        {
            //Debug.Log(string.Format("文件路径:{0} 后缀名:{1} 文件名{2}",VARIABLE,Path.GetExtension(VARIABLE),Path.GetFileNameWithoutExtension(VARIABLE)) );
            //存在后缀名则跳过
            if (Path.GetExtension(file.FullName) == ".manifest")
            {
                continue;
            }
            //黑名单存在则跳过
            if (Array.IndexOf(blackFilesName, Path.GetFileName(file.FullName)) != -1)
            {
                continue;
            }
            var bytes = Util.Encrypt.AesEncrypt(Util.File.ReadBytes(file.FullName));
            var name  = Path.GetFileNameWithoutExtension(file.FullName);
            var size  = bytes.Length;
            var hash  = Util.File.ComputeHash(bytes);

            //build AB File
            Util.File.WriteBytes(Path.Combine(rootABDir.FullName, name), bytes);
            Debug.Log(string.Format("Build AB Res >>>> name:{0} size:{1} hask:{2}", name, size, hash));

            //build version File
            abVObjectList.Add(new ABVObject()
            {
                name = name, size = size, hash = hash
            });
        }
        VObject vObject = new VObject();

        vObject.Version       = "1.0.1";
        vObject.ClientVersion = Application.version;
        vObject.IsRestart     = true;
        vObject.Content       = "我是更新描述!";
        vObject.ABs           = abVObjectList.ToArray();

        string json = vObject.toString();

        Debug.Log("Version Json:" + json);

        Util.Encrypt.WriteString(versionFile.FullName, json);
    }