Example #1
0
    static void BuildLua()
    {
        ResmapUtility.canAuto2Resmap = false; //不自动导入到resmap中

        // 创建文件夹
        Directory.CreateDirectory(ORIGINABPATH);

        // 重命名assetbundle
        FileInfo oldFile = new FileInfo(ORIGINABPATH + "/assetbundle");

        if (oldFile.Exists)
        {
            oldFile.MoveTo(ORIGINABPATH + "/Tmp");
        }

        ABNameUtility.ClearAllABNames();
        DeleteFiles("lua_");

        EditorUtility.DisplayProgressBar("打包前准备", "正在处理Lua文件...", 0.1f);
        LuaEncode.StartEncode(EditorUserBuildSettings.activeBuildTarget);
        ABNameUtility.SetLuaABNames();

        EditorUtility.DisplayProgressBar("打包", "正在打包Lua文件...", 0.5f);
        BuildPipeline.BuildAssetBundles(ORIGINABPATH, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget);

        LuaEncode.EndEncode();
        EditorUtility.DisplayProgressBar("收尾", "Lua还原中...", 0.7f);

        ABNameUtility.ClearLuaABNames();
        EditorUtility.DisplayProgressBar("收尾", "Lua加密中...", 0.9f);
        EncryptAB("lua_");
        EditorUtility.ClearProgressBar();
        // 删除新assetbundle
        UnityEditor.FileUtil.DeleteFileOrDirectory(ORIGINABPATH + "/assetbundle");
        // 还原文件
        if (oldFile.Exists)
        {
            oldFile.MoveTo(ORIGINABPATH + "/assetbundle");
        }
        AssetDatabase.Refresh();
    }
Example #2
0
    static void BuildAll()
    {
        ResmapUtility.canAuto2Resmap = false; //不自动导入到resmap中
        // 创建文件夹
        Directory.CreateDirectory(ORIGINABPATH);
        if (Directory.Exists(ABPATH))
        {
            FileUtil.DeleteFileOrDirectory(ABPATH);
        }
        //记录所有的ab包,打包后,对无用的资源进行删除
        EditorUtility.DisplayProgressBar("打包前准备", "收集已有AB资源...", 0.05f);
        Dictionary <string, ABInfo> _infoDic = new Dictionary <string, ABInfo>();

        string[] files = Directory.GetFiles(ORIGINABPATH);
        for (int i = 0; i < files.Length; i++)
        {
            string path = files[i];
            if (path.EndsWith(".meta") || path.EndsWith(".manifest"))
            {
                continue;
            }
            string fileName = Path.GetFileNameWithoutExtension(path);
            if (fileName.Equals("assetbundle"))
            {
                continue;
            }
            _infoDic.Add(fileName, new ABInfo()
            {
                abName = fileName,
                path   = path
            });
        }
        ABNameUtility.ClearAllABNames();
        EditorUtility.DisplayProgressBar("打包前准备", "开始处理多语言资源...", 0.1f);
        MultiLngResDetach.StartDeal();
        EditorUtility.DisplayProgressBar("打包前准备", "正在重新生成Resmap文件...", 0.2f);
        ResmapUtility.AddAllAsset();
        EditorUtility.DisplayProgressBar("打包前准备", "Lua文件加密中...", 0.25f);
        LuaEncode.StartEncode(EditorUserBuildSettings.activeBuildTarget);
        EditorUtility.DisplayProgressBar("打包前准备", "配置文件加密中...", 0.3f);
        FileEncrypt.Encrypt();
        AssetDatabase.Refresh();

        EditorUtility.DisplayProgressBar("开始打包", "正在自动设置AB名...", 0.4f);
        ABNameUtility.SetAllABNames();
        // 打包
        EditorUtility.DisplayProgressBar("打包", "AB打包中...", 0.6f);
        AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(ORIGINABPATH, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget);

        string[] bundles = manifest.GetAllAssetBundles();
        for (int i = 0; i < bundles.Length; i++)
        {
            if (_infoDic.ContainsKey(bundles[i]))
            {
                _infoDic.Remove(bundles[i]);
            }
        }
        //删除老旧的ab包
        foreach (KeyValuePair <string, ABInfo> pair in _infoDic)
        {
            ABInfo info = pair.Value;
            UnityEditor.FileUtil.DeleteFileOrDirectory(info.path);
            UnityEditor.FileUtil.DeleteFileOrDirectory(info.path + ".manifest");
        }
        EditorUtility.DisplayProgressBar("收尾", "配置文件还原中...", 0.75f);
        FileEncrypt.Decrypt();//还原txt
        EditorUtility.DisplayProgressBar("收尾", "Lua文件还原中...", 0.8f);
        LuaEncode.EndEncode();
        EditorUtility.DisplayProgressBar("收尾", "多语言资源还原中...", 0.85f);
        MultiLngResDetach.Revert();
        EditorUtility.DisplayProgressBar("收尾", "清除AB名...", 0.9f);
        ABNameUtility.ClearAllABNames();
        EditorUtility.ClearProgressBar();

        AssetDatabase.Refresh();
        ResmapUtility.canAutoToResmap = true;
    }