Example #1
0
    private void EncryptFiles(string[] allAssetBundles)
    {
        ShowBuildLog($"开始加密资源文件");

        // 初始化加密器
        InitAssetEncrypter();

        int progressBarCount = 0;

        foreach (string assetName in allAssetBundles)
        {
            string path = $"{OutputPath}/{assetName}";
            if (AssetEncrypterCheck(path))
            {
                byte[] fileData = File.ReadAllBytes(path);

                // 通过判断文件合法性,规避重复加密一个文件。
                if (EditorTools.CheckBundleFileValid(fileData))
                {
                    byte[] bytes = AssetEncrypterEncrypt(fileData);
                    File.WriteAllBytes(path, bytes);
                    ShowBuildLog($"文件加密完成:{path}");
                }
            }

            // 进度条
            progressBarCount++;
            EditorUtility.DisplayProgressBar("进度", $"加密资源包:{progressBarCount}/{allAssetBundles.Length}", (float)progressBarCount / allAssetBundles.Length);
        }
        EditorUtility.ClearProgressBar();
        progressBarCount = 0;
    }