Ejemplo n.º 1
0
    public void ReleaseIOS(string save_path, bool nobundle, string key)
    {
        try
        {
            var locationPath = Application.dataPath.Replace("jyjh/Assets", "") + "xcode_proj";
            Apk_Save_Path = locationPath + "/" + (string.IsNullOrEmpty(save_path) ? DateTime.Now.ToString("yyyyMMdd") : save_path);
            IOSGenerateHelper.GenerateNewCrypto(key);
            SetKey();
            if (!nobundle)
            {
                // 2. 清除AB名
                ClearABName();
                // 3. 设置AB名
                SetAbName();
                // 3.打包ab
                BuildAssetBundle();
                // 4.建立ab映射文件
                BuildBundleNameMapFile();
                // 5.记录压缩前文件大小和md5码,以及资源类型(是否包含于整包,是否是补丁资源)
                RecordFileRealSize();
                // 6.打包lua以及压缩资源
                BuildLuaAndCopyResources();
                // 8.复制整包资源到StreamingAssets目录下
                CopyAllBundles();
            }
            // 3.拷贝config
            BuildPlayer(true, false);
            // 4.重置config.txt
            ResetConfig();

            Resources.UnloadUnusedAssets();
            GC.Collect();
        }
        catch (Exception e)
        {
            Debug.LogException(e);
        }
    }
Ejemplo n.º 2
0
    void BuildPlayer(bool packAllRes, bool forceUpdate)
    {
        var option = BuildOptions.None;

        if (debug)
        {
            option |= BuildOptions.AllowDebugging;
        }
        if (development)
        {
            option |= BuildOptions.Development;
        }
        if (autoConnectProfile)
        {
            option |= BuildOptions.ConnectWithProfiler;
        }
        var temps = Apk_Save_Path.Replace("\\", "/").Split('/');

        if ((ABPackHelper.GetBuildTarget() == BuildTarget.Android ||
             ABPackHelper.GetBuildTarget() == BuildTarget.StandaloneWindows64 ||
             ABPackHelper.GetBuildTarget() == BuildTarget.StandaloneWindows) &&
            sdkConfig != null)
        {
            string lastChannel = string.Empty;
            for (int i = 0; i < sdkConfig.items.Count; ++i)
            {
                StringBuilder final_path = new StringBuilder();
                for (int j = 0; j < temps.Length - 1; ++j)
                {
                    final_path.Append(temps[j] + "/");
                }
                var item = sdkConfig.items[i];
                if (item.need_subpack == 0 && !packAllRes)
                {
                    continue;
                }
                if (ABPackHelper.GetBuildTarget() == BuildTarget.StandaloneWindows64 || ABPackHelper.GetBuildTarget() == BuildTarget.StandaloneWindows)
                {
                    final_path.Append(DateTime.Now.ToString("yyyyMMdd") + "/");
                    if (!Directory.Exists(final_path.ToString()))
                    {
                        Directory.CreateDirectory(final_path.ToString());
                    }
                    final_path.Append(item.game_name + "_v");
                }
                else
                {
                    if (packAllRes)
                    {
                        if (item.development == 1)
                        {
                            option |= BuildOptions.Development;
                            final_path.Append(item.game_name + DateTime.Now.ToString("yyyyMMdd") + "_allpack_dev_v");
                        }
                        else if (item.use_sdk == 1)
                        {
                            final_path.Append(item.game_name + DateTime.Now.ToString("yyyyMMdd") + "_allpack_sdk_v");
                        }
                        else
                        {
                            final_path.Append(item.game_name + DateTime.Now.ToString("yyyyMMdd") + "_allpack_test_v");
                        }
                    }
                    else
                    {
                        if (item.development == 1)
                        {
                            option |= BuildOptions.Development;
                            final_path.Append(item.game_name + DateTime.Now.ToString("yyyyMMdd") + "_subpack_dev_v");
                        }
                        else if (item.use_sdk == 1)
                        {
                            final_path.Append(item.game_name + DateTime.Now.ToString("yyyyMMdd") + "_subpack_sdk_v");
                        }
                        else
                        {
                            final_path.Append(item.game_name + DateTime.Now.ToString("yyyyMMdd") + "_subpack_test_v");
                        }
                    }
                }
                final_path.Append(gameVersion.ToString());
                if (ABPackHelper.GetBuildTarget() == BuildTarget.Android)
                {
                    final_path.Append(".apk");
                    if (File.Exists(final_path.ToString()))
                    {
                        File.Delete(final_path.ToString());
                    }
                    // 写入并保存sdk启用配置
                    item.CopyConfig();
                    item.CopySDK();
                    item.SetPlayerSetting(sdkConfig.splash_image);
                    item.SaveSDKConfig();
                    item.SplitAssets(sdkConfig.split_assets);
                    IncreaseLEBIAN_VERCODE(forceUpdate, item.update_along);
                    if (item.update_along == 0 && forceUpdate)
                    {
                        if (Directory.Exists(Application.streamingAssetsPath))
                        {
                            Directory.Delete(Application.streamingAssetsPath, true);
                        }
                    }
                }
                else if (ABPackHelper.GetBuildTarget() == BuildTarget.StandaloneWindows64 || ABPackHelper.GetBuildTarget() == BuildTarget.StandaloneWindows)
                {
                    final_path.Append(".exe");
                    if (Directory.Exists(final_path.ToString()))
                    {
                        Directory.Delete(final_path.ToString(), true);
                    }
                    item.CopyConfig();
                }
                AssetDatabase.Refresh();
                BuildPipeline.BuildPlayer(ABPackHelper.GetBuildScenes(), final_path.ToString(), ABPackHelper.GetBuildTarget(), option);
                AssetDatabase.Refresh();
                item.ClearSDK();

                SVNHelper.UpdateAll();
            }
        }
        else if (ABPackHelper.GetBuildTarget() == BuildTarget.iOS)
        {
            // 在上传目录新建一个ios_check.txt文件用于判断当前包是否出于提审状态
            string checkFile = ABPackHelper.ASSET_PATH + LuaConst.osDir + "/ios_check.txt";
            if (File.Exists(checkFile))
            {
                File.Delete(checkFile);
            }
            File.WriteAllText(checkFile, "1");

            XCConfigItem configItem = XCConfigItem.ParseXCConfig(XCodePostProcess.config_path);
            if (configItem != null)
            {
                PlayerSettings.applicationIdentifier = configItem.bundleIdentifier;
                PlayerSettings.productName           = configItem.product_name;
                configItem.CopyConfig();
            }
            IOSGenerateHelper.IOSConfusing();
            AssetDatabase.Refresh();
            BuildPipeline.BuildPlayer(ABPackHelper.GetBuildScenes(), Apk_Save_Path, ABPackHelper.GetBuildTarget(), option);
            AssetDatabase.Refresh();
        }

        Resources.UnloadUnusedAssets();
        GC.Collect();

        Debug.Log("<color=green>Build success!</color>");
    }
Ejemplo n.º 3
0
    void CompressWithZSTD(long maxFileSize)
    {
        string outPutPath = Application.streamingAssetsPath + "/" + LuaConst.osDir;

        ABPackHelper.ShowProgress("Hold on...", 0);
        var dirInfo = new DirectoryInfo(outPutPath);
        var dirs    = dirInfo.GetDirectories();
        Dictionary <int, List <string> > allFiles = new Dictionary <int, List <string> >();
        // data原始包控制在10M左右
        long curSize  = 0;
        int  tmpIndex = 0;

        for (int i = 0; i < dirs.Length; ++i)
        {
            if (dirs[i].Name == "lua")
            {
                continue;
            }
            var abFileInfos = dirs[i].GetFiles("*.*", SearchOption.AllDirectories);
            for (int j = 0; j < abFileInfos.Length; ++j)
            {
                if (abFileInfos[j].FullName.EndsWith(".meta"))
                {
                    continue;
                }
                if (curSize >= maxFileSize)
                {
                    curSize = 0;
                    tmpIndex++;
                }
                if (curSize == 0)
                {
                    allFiles.Add(tmpIndex, new List <string>());
                }
                var fileName = ABPackHelper.GetRelativeAssetsPath(abFileInfos[j].FullName);
                allFiles[tmpIndex].Add(fileName);
                curSize += File.ReadAllBytes(fileName).Length;
            }
        }
        int index = 0;

        // 合并生成的bundle文件,合成10M左右的小包(二进制)
        foreach (var key in allFiles.Keys)
        {
            var tmpName = "data" + key;
#if UNITY_IOS
            tmpName = IOSGenerateHelper.RenameResFileWithRandomCode(tmpName);
#endif
            var savePath = string.Format("{0}/{1}.tmp", outPutPath, tmpName);
            ABPackHelper.ShowProgress("Streaming data...", (float)index++ / (float)allFiles.Count);
            using (var fs = new FileStream(savePath, FileMode.CreateNew))
            {
                using (var writer = new BinaryWriter(fs))
                {
                    for (int i = 0; i < allFiles[key].Count; ++i)
                    {
                        var bytes  = File.ReadAllBytes(allFiles[key][i]);
                        var abName = allFiles[key][i].Replace("Assets/StreamingAssets/" + LuaConst.osDir + "/", "");
                        writer.Write(abName);
                        writer.Write(bytes.Length);
                        writer.Write(bytes);
                    }
                }
            }
        }
        ABPackHelper.ShowProgress("Finished...", 1);
        for (int i = 0; i < dirs.Length; ++i)
        {
            if (dirs[i].Name == "lua")
            {
                continue;
            }
            Directory.Delete(dirs[i].FullName, true);
        }
        AssetDatabase.Refresh();

        // 对合并后的文件进行压缩
        ABPackHelper.ShowProgress("Hold on...", 0);
        var pakFiles = Directory.GetFiles(outPutPath, "*.tmp", SearchOption.AllDirectories);
        for (int i = 0; i < pakFiles.Length; ++i)
        {
            var savePath = string.Format("{0}/{1}.bin", outPutPath, Path.GetFileNameWithoutExtension(pakFiles[i]));
            ABPackHelper.ShowProgress("compress with zstd...", (float)i / (float)pakFiles.Length);
            var fileName = ABPackHelper.GetRelativeAssetsPath(pakFiles[i]);
            using (var compressFs = new FileStream(savePath, FileMode.CreateNew))
            {
                using (var compressor = new Compressor(new CompressionOptions(CompressionOptions.MaxCompressionLevel)))
                {
                    var bytes = compressor.Wrap(File.ReadAllBytes(fileName));
#if UNITY_IOS
                    bytes = Crypto.Encode(bytes);
#endif
                    compressFs.Write(bytes, 0, bytes.Length);
                }
            }
            File.Delete(fileName);
        }
        ABPackHelper.ShowProgress("Finished...", 1);

        // 生成包体第一次进入游戏解压缩配置文件
        StringBuilder builder  = new StringBuilder();
        string[]      allfiles = Directory.GetFiles(outPutPath, "*.*", SearchOption.AllDirectories);
        for (int i = 0; i < allfiles.Length; ++i)
        {
            if (allfiles[i].EndsWith(".meta"))
            {
                continue;
            }
            if (allfiles[i].EndsWith("datamap.ab"))
            {
                continue;
            }

            var fileName = allfiles[i].Replace(outPutPath, "").Replace("\\", "/").TrimStart('/');
            builder.Append(fileName);
            builder.Append('|');
            builder.Append(MD5.ComputeHashString(allfiles[i]));
            builder.Append("\n");
        }
        var packFlistPath = outPutPath + "/packlist.txt";
        if (File.Exists(packFlistPath))
        {
            File.Delete(packFlistPath);
        }
        File.WriteAllText(packFlistPath, builder.ToString());
        AssetDatabase.Refresh();
    }
Ejemplo n.º 4
0
        /// <summary>
        /// 压缩StreamAsset目录的资源
        /// </summary>
        /// <param name="maxFileSize"></param>
        protected void CompressWithZSTD(long maxFileSize)
        {
            string outPutPath = BuilderPreference.StreamingAssetsPlatormPath;

            var dirInfo = new DirectoryInfo(outPutPath);
            var dirs    = dirInfo.GetDirectories();



            Dictionary <int, List <string> > allFiles = new Dictionary <int, List <string> >();
            // data原始包控制在10M左右
            long curSize  = 0;
            int  tmpIndex = 0;

            for (int i = 0; i < dirs.Length; ++i)
            {
                if (dirs[i].Name == "lua")
                {
                    continue;
                }

                var abFileInfos = BuildUtil.SearchFiles(dirs[i].FullName, SearchOption.AllDirectories);

                for (int j = 0; j < abFileInfos.Count; ++j)
                {
                    var relativePath = abFileInfos[j];
                    var data         = new FileInfo(relativePath);
                    if (data.Length >= maxFileSize)
                    {
                        curSize = 0;
                        tmpIndex++;
                    }
                    else if (curSize >= maxFileSize)
                    {
                        curSize = 0;
                        tmpIndex++;
                    }

                    if (curSize == 0)
                    {
                        allFiles.Add(tmpIndex, new List <string>());
                    }

                    allFiles[tmpIndex].Add(relativePath);
                    curSize += data.Length;
                }
            }

            // 合并生成的bundle文件,合成10M左右的小包(二进制)
            Builder.AddBuildLog("<Copresss zstd> merge and compress with zstd...");
            compressIndex = 0;
            compressCount = allFiles.Count;

            foreach (var key in allFiles.Keys)
            {
                var tmpName = "data" + key;
#if UNITY_IOS
                tmpName = IOSGenerateHelper.RenameResFileWithRandomCode(tmpName);
#endif
                var savePath = string.Format("{0}/{1}.tmp", outPutPath, tmpName);

                List <string> mergePaths = allFiles[key];

                ThreadPool.QueueUserWorkItem(onThreadCompress, new object[] { savePath, outPutPath, mergePaths });
            }
        }