//PE park build
        public static void Build()
        {
            string confPath = CommonHelper.PathCombine(ExportAsset.workPath, "abc.yaml");

            Debug.Log(ExportAsset.workPath);

            //加载资源目录
            artConfig = new ArtPathConfig();
            if (!artConfig.Load())
            {
                return;
            }
            //加载特殊后缀目录
            ignoreConfig = new IgnoreFileConfig();
            if (!ignoreConfig.Load())
            {
                return;
            }

            resFileList.Clear();
            foreach (var path in artConfig.ArtPath)
            {
                var resDir = CommonHelper.PathCombine(Application.dataPath, path);
                if (!Directory.Exists(resDir))
                {
                    Debug.LogError("res path not exists : " + resDir);
                    return;
                }
                //遍历所有目录及具体资源并剔除特殊后缀资源
                GetAssetInFolder(resDir);
            }

            foreach (var scene in EditorBuildSettings.scenes)
            {
                //if (scene.path.EndsWith("loading.unity"))
                //    continue;
                resFileList.Add(scene.path);
            }

            //分析资源依赖关系
            resNodeDic.Clear();
            DirectedGraphs2Tree();

            Dictionary <string, AssetBundleSerializer> abc = new Dictionary <string, AssetBundleSerializer>();

            foreach (var node in resNodeDic)
            {
                var assetsAB = node.Value;
                if (!string.IsNullOrEmpty(assetsAB.AssetsBundleName))
                {
                    AssetBundleSerializer ab = null;
                    if (!abc.TryGetValue(assetsAB.AssetsBundleName, out ab))
                    {
                        ab      = new AssetBundleSerializer();
                        ab.Name = assetsAB.AssetsBundleName;
                        abc[assetsAB.AssetsBundleName] = ab;
                    }
                    ab.Assets.Add(assetsAB.assetsPath);
                    List <ResNode> dependencies = new List <ResNode>();
                    assetsAB.GetDependenciesAssetBundleAll(assetsAB, dependencies);
                    for (int i = 0; i < dependencies.Count; i++)
                    {
                        ab.AddDependence(dependencies[i].AssetsBundleName);
                    }
                }
            }

            // AssetDatabase.Refresh();
            //生成文件
            using (var writer = File.CreateText(confPath))
            {
                var serializer = new Serializer();
                var list       = abc.Values.ToList();
                list.Sort((x, y) =>
                {
                    return(x.Name.CompareTo(y.Name));
                });
                serializer.Serialize(writer, list);
            }
        }
Exemple #2
0
        //wx2 park
        private static void WX2PARK(string workPath, BuildTarget target, bool encrypted, string[] inputTopDirs, string[] scenePaths, string resRootPath)
        {
            artConfig = new ArtPathConfig();
            artConfig.Load();
            List <string> configPath = new List <string>();

            foreach (var path in artConfig.ArtPath)
            {
                Debug.Log("从配置中获取的目录 = " + path);
                var resDir = CommonHelper.PathCombine(Application.dataPath, path);
                configPath.Add(resDir);
                //检查下获取的路径是否存在
                if (!Directory.Exists(resDir))
                {
                    Debug.LogError("res path not exists : " + resDir);
                    return;
                }
                //在Assets下拿ResPath  Assets/Game/Res
                //GetAssetInFolder(resDir);
            }

            //默认其实是true
            bool bExportAll = (inputTopDirs == null && scenePaths == null);


            //获取要打包成AB的目录
            //顶层文件夹
            if (inputTopDirs == null)
            {
                // inputTopDirs = new string[] { CommonHelper.PathCombine(Application.dataPath, "/Art") };
                inputTopDirs = configPath.ToArray();
            }

            Debug.Log("获取子文件夹");
            //获取子文件夹
            List <DirectoryInfo> inputSubDirs = new List <DirectoryInfo>();

            for (int i = 0; i < inputTopDirs.Length; i++)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(inputTopDirs[i]);
                Debug.Log("子文件夹 dir = " + dirInfo);
                inputSubDirs.Add(dirInfo);
            }

            //要打包的文件
            List <FileInfo> inputFiles = new List <FileInfo>();

            //从输入目录和输入场景文件中获取将要生成的AB名称
            List <string> resPaths = new List <string>();

            //递归所有子文件夹 获取全部输入路径
            for (int i = 0; i < inputSubDirs.Count; i++)
            {
                GetResInputPath(inputSubDirs[i], resPaths);
            }

            //将来场景打包后加进去
            //for (int i = 0; i < inputFiles.Count; i++)
            //{
            //    resPaths.Add(inputFiles[i].FullName);
            //}

            //如果打包全部资源,删除无效的AB
            if (bExportAll)
            {
                //删除上次存在这次不生成的AB
                // DeleteInvalidRes(target, encrypted, resPaths, resRootPath);
            }

            ExportRes(target, inputSubDirs.ToArray(), inputFiles.ToArray(), resRootPath);
        }