Esempio n. 1
0
        /// <summary>
        /// 构建资源关系图
        /// </summary>
        public static void BuildAssetDependenctGraph()
        {
            var asset = BuildUtils.BuildAndSave();

            var dic = new Dictionary <string, string[]>();

            if (asset != null)
            {
                Debug.Log("This way can fast analysis resources relationship.");
                using (new ExecuteTimer("Compute cache file dependencies"))
                {
                    var resourceDependenct = asset.data.GetDic();

                    var res = resourceDependenct.GetEnumerator();

                    while (res.MoveNext())
                    {
                        dic.Add(res.Current.Key, res.Current.Value.dependencies);
                    }
                }
            }
            else
            {
                Debug.Log("This way need some time analysis resources relationship.");

                string rpath = "Assets/Resources/";
                using (new ExecuteTimer("Compute which file that need analysis"))
                {
                    //var searchPattern = AssetFileType.GetSearchPattern();

                    //var filePaths = searchPattern.SelectMany(i => Directory.GetFiles(rpath, i, SearchOption.AllDirectories)).Distinct().ToArray();

                    //prefabfiles = filePaths;

                    prefabfiles = AssetsDependenctGenerateEditor.GetAllFile();
                }

                using (new ExecuteTimer("Compute Resource dependencies."))
                {
                    for (int i = 0; i < prefabfiles.Length; i++)
                    {
                        var assetPath = prefabfiles[i] = BuildUtils.GetUnityPath(prefabfiles[i]);

                        var assetsDependencies = BuildUtils.GetDependencies(assetPath);

                        assetsDependencies = BuildUtils.ExceptScriptAndDll(assetsDependencies);

                        dic.Add(assetPath, assetsDependencies);
                    }
                }
            }

            using (new ExecuteTimer("Compute Resouce Relationship" + dic.Count))
            {
                //根据当前的资源引用关系数据,刷新构建图形数据结构
                resourceGraph = new AssetDependenctGraph(dic);

                state = AssetDependenctTreeBuildState.NodeGraph;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 开始构建 AssetBundle
        /// </summary>
        /// <param name="target"></param>
        static void BuildAssetBundle(BuildTarget buildTarget, int compre_type, bool is_force_build, string[] build_asset_arr)
        {
            //生成资源的依赖关系
            AssetsDependenctGenerateEditor.UpdateAssetDependenct();

            //构建引用关系图形
            AssetDependenctTree.BuildAssetDependenctGraph();

            //更新资源打包后缀
            UpAssetExtension(buildTarget);

            //获取所有需要打包的资源数据引用
            var dic = AllNeedBuildAssetDependenct(build_asset_arr);

            //获取资源进行单独打包的列表
            var singles = BuildSinglePackage(dic);

            //获取目录资源打包
            var directory = BuildDirectoryPackage(dic);

            //获取资源进行除单独打包的列表
            var resources = BuildAllResourceEx(dic);

            //获取总共需要进行打包的资源数据
            var builds = ArrayTools.Concat(singles, directory, resources);

            //var exportDir = BuildUtils.CreateAssetBundleDir(buildTarget, out_path);//构建不同平台的子目录

            //var fullversion = BuildUtils.GetCurrentPackageVersion();

            //var bundleName = BuildUtils.GetAssetBundleName(buildTarget);

            //int major, minor, build;

            //VersionJson.GetResVersion(fullversion, out major, out minor, out build);

            //var version = build.ToString().PadLeft(VersionJson.VersionCount, '0');

            //var versionPath = BuildUtils.GenVersionPath(__versionPath, version);

            //AssetBundleManifest assetBundlemainfest;

            //if (build > 0)//小版本的情况
            //{
            //    Debug.Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!build version" + version);

            //    //如果某一个版本的文件存在 就全部删除掉.
            //    if (Directory.Exists(versionPath))
            //    {
            //        Directory.Delete(versionPath, true);
            //    }

            //    //不强制打包 小幅度增加版本号,以上一个版本的数据比较变动
            //    assetBundlemainfest = BuildBundlesUnity5(exportDir, __compressType, __buildTarget, false, builds);

            //    if (assetBundlemainfest != null)
            //    {
            //        var staticManifest = BuildUtils.GetStaticAssetBundleManifest(lastVersionPath, bundleName);

            //        var filePath = lastVersionPath;

            //        if (staticManifest != null)
            //        {
            //            string[] addResource, deleteResource, updateResource;

            //            BuildUtils.BuildVersionMergeInfomation(filePath, exportDir, staticManifest, assetBundlemainfest, out addResource, out deleteResource, out updateResource);

            //            CopyResourceToVersionFile(addResource, updateResource, exportDir, versionPath);

            //            CopyAssetBundleManifestFile(exportDir, versionPath, __buildTarget);

            //            CreateVersionFile(versionPath, fullversion, __buildTarget);

            //            //生成信息中需要包含新增资源 删除资源 更新资源
            //            GenLittleVersionChange(addResource, updateResource, deleteResource, versionPath);
            //        }
            //        else
            //        {
            //            Debug.LogError("Error!!,Last Version Is Empty!" + version);
            //        }
            //    }
            //    else
            //    {
            //        Debug.LogError("Error! AssetBundleMainfest is Null.");
            //    }
            //}
            //else//大版本的情况
            //{
            //    if (Directory.Exists(versionPath))
            //    {
            //        Directory.Delete(versionPath, true);
            //    }

            //    Debug.Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!build version" + version);

            //    //强制重新生成,全部拷贝到一个新的目录 更新大版本 生成到StreamingPath
            //    assetBundlemainfest = BuildBundlesUnity5(exportDir, __compressType, __buildTarget, true, builds);

            //    if (assetBundlemainfest != null)
            //    {
            //        //到version目录 1 2 3
            //        CopyAssetBundleManifestFile(exportDir, versionPath, __buildTarget);

            //        //备份文件到Version文件版本库中 虽然以后不用使用 但是需要提取版本变化文件
            //        CopyResourceToVersionFile(assetBundlemainfest.GetAllAssetBundles(), null, exportDir, versionPath);

            //        CreateVersionFile(versionPath, fullversion, __buildTarget);

            //        //到streaming目录 1 2 3
            //        CopyResouceToStreamingAssets(assetBundlemainfest, exportDir, __buildTarget);

            //        CopyVersionToStreamingAssets(versionPath, __buildTarget);

            //        CopyAssetBundleManifestToStreamingAssets(exportDir, __buildTarget);
            //        //拷贝到游戏里面 供下一个打包流程使用
            //    }
            //    else
            //    {
            //        Debug.LogError("Error! AssetBundleMainfest is Null.");
            //    }
            //}

            ////比对文件
            //if (__withMD5 && assetBundlemainfest != null)
            //{
            //    var bundlexList = CreateBundleMD5(assetBundlemainfest, exportDir);

            //    ProcessVersion(exportDir, bundlexList);

            //    //处理StreamingAsset里面的资源
            //    ChangeBundleNameToMd5(exportDir, bundlexList);
            //}

            //获取AssetBundle输出目录
            string out_path = GetAssetBundleOutPath();

            AssetBundleManifest assetBundlemainfest;

            //不强制打包 小幅度增加版本号,以上一个版本的数据比较变动
            assetBundlemainfest = BuildAssetBundle(out_path, compre_type, buildTarget, is_force_build, builds);

            if (assetBundlemainfest != null)
            {
                Debug.Log("资源数据打包完成  ~~~ ");

                //存储引用数据记录
                ManifestTools.OnSaveManifest(out_path + "/Data", assetBundlemainfest);

                //var staticManifest = BuildUtils.GetStaticAssetBundleManifest(lastVersionPath, bundleName);

                //var filePath = lastVersionPath;

                //if (staticManifest != null)
                //{
                //    string[] addResource, deleteResource, updateResource;

                //    BuildUtils.BuildVersionMergeInfomation(filePath, exportDir, staticManifest, assetBundlemainfest, out addResource, out deleteResource, out updateResource);

                //    CopyResourceToVersionFile(addResource, updateResource, exportDir, versionPath);

                //    CopyAssetBundleManifestFile(exportDir, versionPath, __buildTarget);

                //    CreateVersionFile(versionPath, fullversion, __buildTarget);

                //    //生成信息中需要包含新增资源 删除资源 更新资源
                //    GenLittleVersionChange(addResource, updateResource, deleteResource, versionPath);
                //}
                //else
                //{
                //    Debug.LogError("Error!!,Last Version Is Empty!" + version);
                //}
            }
            else
            {
                Debug.LogError("Error! AssetBundleMainfest is Null.");
            }

            //清理环境
            EditorUtility.UnloadUnusedAssetsImmediate();

            //更新资源列表
            BuildUtils.Refresh();
        }