コード例 #1
0
ファイル: BuildPlayer.cs プロジェクト: mengtest/RewriteFrame
    private static void InnerBuildAssetBundles(BuildTarget buildTarget, string channelName, bool writeConfig)
    {
        // 更改打包的压缩方式LZ4 BuildAssetBundleOptions.ChunkBasedCompression  默认LZMA 压缩
        // (1)随包资源StreamingAssets:
        // 未压缩或LZ4压缩:LoadFromFile;
        // LZMA压缩:可使用 WWW.LoadFromCacheOrDownload解压缩到本地磁盘。
        // (2)热更新资源:LZMA + WWW.LoadFromCacheOrDownload + Caching.compressionEnabled;
        // (3)加密资源: LZ4 + LoadFromMemory;
        // (4)自己压缩的资源:UncompressAssetBundle的AssetBundle包 + 自己的算法压缩 + LoadFromFileAsync。
        // WWW.LoadFromCacheOrDownload会被UnityWebRequest取代
        //目前采取的是UnityWebRequest加载
        BuildAssetBundleOptions buildOption = BuildAssetBundleOptions.IgnoreTypeTreeChanges | BuildAssetBundleOptions.DeterministicAssetBundle;//| BuildAssetBundleOptions.ChunkBasedCompression;
        string outputPath            = PackageUtils.GetAssetBundleOutputPath(buildTarget, channelName);
        AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(outputPath, buildOption, buildTarget);

        if (manifest != null && writeConfig)
        {
            AssetsPathMappingEditor.BuildPathMapping(manifest);
            VariantMappingEditor.BuildVariantMapping(manifest);
            BuildPipeline.BuildAssetBundles(outputPath, buildOption, buildTarget);
            Debug.Log("输出路径" + outputPath);
        }
        WriteChannelNameFile(buildTarget, channelName);
        WriteAssetBundleSize(buildTarget, channelName);
        AssetDatabase.Refresh();
    }
コード例 #2
0
ファイル: PackageTool.cs プロジェクト: mengtest/FrameWork
    public static string ReadResVersionFile(BuildTarget target, ChannelType channel)
    {
        // 从资源版本号文件(当前渠道AB输出目录中)加载资源版本号
        string rootPath = PackageUtils.GetAssetBundleOutputPath(target, channel.ToString());

        return(GameUtility.SafeReadAllText(Path.Combine(rootPath, BuildUtils.ResVersionFileName)));
    }
コード例 #3
0
    // 此处存储的VersionConfig和VersionFile重复,暂时不用
    //public static void ReadVersionConfig()
    //{
    //    // 从数据库加载资源版本号
    //    AssetBundleResVersionConfig config = AssetDatabase.LoadAssetAtPath(AssetBundleResVersionConfig.RES_PATH, typeof(AssetBundleResVersionConfig)) as AssetBundleResVersionConfig;
    //    if (config == null)
    //    {
    //        config = CreateInstance<AssetBundleResVersionConfig>();
    //        AssetDatabase.CreateAsset(config, AssetBundleResVersionConfig.RES_PATH);
    //        AssetDatabase.Refresh();
    //    }
    //    appVersion = config.appVersion;
    //    resVersion = config.resVersion;
    //}
    //public static void SaveVersionConfig()
    //{
    //    // 保存资源版本号到数据库
    //    AssetBundleResVersionConfig config = AssetDatabase.LoadAssetAtPath(AssetBundleResVersionConfig.RES_PATH, typeof(AssetBundleResVersionConfig)) as AssetBundleResVersionConfig;
    //    if (config == null)
    //    {
    //        config = CreateInstance<AssetBundleResVersionConfig>();
    //        AssetDatabase.CreateAsset(config, AssetBundleResVersionConfig.RES_PATH);
    //        AssetDatabase.Refresh();
    //    }
    //    config.appVersion = appVersion;
    //    config.resVersion = resVersion;
    //    EditorUtility.SetDirty(config);
    //    AssetDatabase.SaveAssets();
    //    AssetDatabase.Refresh();
    //}

    public static bool ReadLocalVersionFile(BuildTarget target, ChannelType channel)
    {
        // 从资源版本号文件(当前渠道AB输出目录中)加载资源版本号
        string rootPath = PackageUtils.GetAssetBundleOutputPath(target, channel.ToString());

        string app_path = rootPath + "/" + BuildUtils.AppVersionFileName;

        app_path    = GameUtility.FormatToUnityPath(app_path);
        appVersion  = "0.0.0";
        resVersion  = "0.0.0";
        channelType = ChannelType.Test;

        string content = GameUtility.SafeReadAllText(app_path);

        if (content == null)
        {
            return(false);
        }

        Debug.Log("Load local version :" + content);
        var arr = content.Split('|');

        if (arr.Length >= 3)
        {
            appVersion  = arr[0];
            resVersion  = arr[1];
            channelType = (ChannelType)Enum.Parse(typeof(ChannelType), arr[2]);
        }

        return(true);
    }
コード例 #4
0
ファイル: PackageTool.cs プロジェクト: mengtest/FrameWork
    public static void SaveAllVersionFile(BuildTarget target, ChannelType channel)
    {
        // 保存所有版本号信息到资源版本号文件(当前渠道AB输出目录中)
        string rootPath = PackageUtils.GetAssetBundleOutputPath(target, channel.ToString());

        GameUtility.SafeWriteAllText(Path.Combine(rootPath, BuildUtils.ResVersionFileName), resVersion);
        GameUtility.SafeWriteAllText(Path.Combine(rootPath, BuildUtils.NoticeVersionFileName), resVersion);
        GameUtility.SafeWriteAllText(Path.Combine(rootPath, BuildUtils.AppVersionFileName), bundleVersion);
    }
コード例 #5
0
    public static void SaveLocalVersionFile(BuildTarget target, ChannelType channel)
    {
        string rootPath = PackageUtils.GetAssetBundleOutputPath(target, channel.ToString());

        string path = rootPath + "/" + BuildUtils.AppVersionFileName;

        path = GameUtility.FormatToUnityPath(path);

        string content = appVersion + "|" + resVersion + "|" + channel;

        Debug.Log("save app_version.bytes->" + content);
        // 保存所有版本号信息到资源版本号文件(当前渠道AB输出目录中)
        GameUtility.SafeWriteAllText(path, content);
    }
コード例 #6
0
ファイル: BuildPlayer.cs プロジェクト: xiangry/MyFramework
    private static void InnerBuildAssetBundles(BuildTarget buildTarget, string channelName, bool writeConfig)
    {
        BuildAssetBundleOptions buildOption = BuildAssetBundleOptions.IgnoreTypeTreeChanges | BuildAssetBundleOptions.DeterministicAssetBundle;
        string outputPath            = PackageUtils.GetAssetBundleOutputPath(buildTarget, channelName);
        AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(outputPath, buildOption, buildTarget);

        if (manifest != null && writeConfig)
        {
            AssetsPathMappingEditor.BuildPathMapping(manifest);
            VariantMappingEditor.BuildVariantMapping(manifest);
            BuildPipeline.BuildAssetBundles(outputPath, buildOption, buildTarget);
        }
        WriteChannelNameFile(buildTarget, channelName);
        WriteAssetBundleSize(buildTarget, channelName);
        AssetDatabase.Refresh();
    }
コード例 #7
0
    //[MenuItem("Tools/Copy Test", false, 0)]
    static void CopyVideo1()
    {
        BuildTarget buildTarget = BuildTarget.Android;
        //首先从资源路径复制所有音效资源到更新路径
        string pltname = PackageUtils.GetPlatformName(buildTarget);

        //取得音效的原始路径
        string sourcePath = PackageUtils.GetAudioSourceDataPath(pltname);
        //资源输出路径
        string AssetsPath = PackageUtils.GetAssetBundleOutputPath(buildTarget, "Test");
        //需要复制到的资源路径
        string destPath = Path.Combine(AssetsPath, AssetBundleConfig.AssetBundlesAudioFolderName_GEN);

        //加入平台
        destPath = Path.Combine(destPath, pltname);
        // 有毒,竟然在有的windows系统这个函数删除不了目录,不知道是不是Unity的Bug
        // GameUtility.SafeDeleteDir(destination);
        destPath   = GameUtility.FormatToUnityPath(destPath);
        sourcePath = GameUtility.FormatToUnityPath(sourcePath);
        //如果文件夹下面有meta文件的时候无法删除文件夹,因为meta文件是隐藏文件,需要权限
        GameUtility.SafeDeleteDir(destPath);
        //检测目标路路径是否存在
        //GameUtility.CheckDirAndCreateWhenNeeded(destPath);
        Debug.Log("Audio dst Path:" + destPath);
        Debug.Log("Audio src Path:" + sourcePath);

        try
        {
            FileUtil.CopyFileOrDirectory(sourcePath, destPath);
            var allfiles = GameUtility.GetSpecifyFilesInFolder(sourcePath);
            if (allfiles != null && allfiles.Length > 0)
            {
                for (int i = 0; i < allfiles.Length; i++)
                {
                    if (allfiles[i].IndexOf(".meta") >= 0)
                    {
                        GameUtility.SafeDeleteFile(allfiles[i]);
                    }
                }
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError("Something wrong: " + ex);
            return;
        }
    }
コード例 #8
0
ファイル: BuildPlayer.cs プロジェクト: xiangry/MyFramework
    public static void WriteAssetBundleSize(BuildTarget buildTarget, string channelName)
    {
        var           outputPath      = PackageUtils.GetAssetBundleOutputPath(buildTarget, channelName);
        var           allAssetbundles = UtilityGame.GetSpecifyFilesInFolder(outputPath, new string[] { ".assetbundle" });
        StringBuilder sb = new StringBuilder();

        if (allAssetbundles != null && allAssetbundles.Length > 0)
        {
            foreach (var assetbundle in allAssetbundles)
            {
                FileInfo fileInfo = new FileInfo(assetbundle);
                int      size     = (int)(fileInfo.Length / 1024) + 1;
                var      path     = assetbundle.Substring(outputPath.Length + 1);
                sb.AppendFormat("{0}{1}{2}\n", UtilityGame.FormatToUnityPath(path), AssetBundleConfig.CommonMapPattren, size);
            }
        }
        string content = sb.ToString().Trim();

        UtilityGame.SafeWriteAllText(Path.Combine(outputPath, UtilityBuild.AssetBundlesSizeFileName), content);
    }
コード例 #9
0
    static void MainistTest()
    {
        string outputPath = PackageUtils.GetAssetBundleOutputPath(BuildTarget.Android, "Test");

        AssetBundle assetBundle = AssetBundle.LoadFromFile(outputPath + "\\" + BuildUtils.ManifestBundleName);

        if (assetBundle != null)
        {
            AssetBundleManifest manifest       = assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
            string[]            self_name_list = manifest.GetAllAssetBundles();

            foreach (string name in self_name_list)
            {
                string   path = outputPath + "\\" + name;
                FileInfo file = new FileInfo(path);
                Logger.Log(name + "," + file.Length / 1024 + "," + PackageUtils.GetFileMD5(path) + "\n");
            }
            assetBundle.Unload(false);
        }
    }
コード例 #10
0
    private static void InnerBuildAssetBundles(BuildTarget buildTarget, string channelName, bool writeConfig)
    {
        BuildAssetBundleOptions buildOption = BuildAssetBundleOptions.IgnoreTypeTreeChanges | BuildAssetBundleOptions.DeterministicAssetBundle;
        string outputPath = PackageUtils.GetAssetBundleOutputPath(buildTarget, channelName);
//        var old_manifest = GetCurrentManifest();

        AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(outputPath, buildOption, buildTarget);

        if (manifest != null && writeConfig)
        {
            AssetsPathMappingEditor.BuildPathMapping(manifest);
            VariantMappingEditor.BuildVariantMapping(manifest);
            manifest = BuildPipeline.BuildAssetBundles(outputPath, buildOption, buildTarget);
        }

        WriteBundlesVersionFile(manifest);
        ClearUnuseFiles(outputPath, manifest);
        AssetDatabase.Refresh();

        //写入修改文件,刷新cdn
//        var new_manifest = GetCurrentManifest();
//        var updates = old_manifest.CompareTo(new_manifest);
//        SaveCDNFlushFile(updates);
    }
コード例 #11
0
ファイル: BuildPlayer.cs プロジェクト: xiangry/MyFramework
    public static void WriteChannelNameFile(BuildTarget buildTarget, string channelName)
    {
        var outputPath = PackageUtils.GetAssetBundleOutputPath(buildTarget, channelName);

        UtilityGame.SafeWriteAllText(Path.Combine(outputPath, UtilityBuild.ChannelNameFileName), channelName);
    }