Esempio n. 1
0
        /// <summary>
        /// 点击输出AssetBundle文件
        /// </summary>
        void OnClickOutputAssetBundle()
        {
            //> 确定目标平台
            BuildTarget selection = EditorUserBuildSettings.activeBuildTarget;

            if (BuildTargetDropdown.Visible)
            {
                selection = (BuildTarget)BuildTargetDropdown.Value;
            }

            //> 确定输出模块
            var foldersObject = FolderList.GetChooseFolder();

            if (foldersObject.Count == 0)
            {
                Debug.LogError("Invalid build:Chose at least one module.");
            }

            AssetDatabase.RemoveUnusedAssetBundleNames();
            var allAssetBundleNames = AssetDatabase.GetAllAssetBundleNames();
            var outputPath1         = EAssetBundleToolUtil.GetDiskPath("AssetBundlePool/" + selection.ToString());
            var outputPath2         = EAssetBundleToolUtil.GetDiskPath(Config.AssetBundleOutput + "/" + selection.ToString());

            if (!Directory.Exists(outputPath1))
            {
                Directory.CreateDirectory(outputPath1);
            }
            if (!Directory.Exists(outputPath2))
            {
                Directory.CreateDirectory(outputPath2);
            }

            List <FileVersionInfo> versionList = new List <FileVersionInfo>();

            //> 构建AB文件到资源池
            foreach (var v in foldersObject)
            {
                var names = EAssetBundleToolUtil.GetAssetBundleNamesByModule(allAssetBundleNames, v.FolderName.ToLower());

                var buildMap = EAssetBundleToolUtil.GetBuildMapByAssetBundleNames(names);

                if (buildMap.Count == 0)
                {
                    continue;
                }

                string finalOutputPath1 = outputPath1;
                string finalOutputPath2 = outputPath2;
                if (Config.IsModuleStructure)
                {
                    finalOutputPath1 += "/" + v.FolderName.ToLower();
                    finalOutputPath2 += "/" + v.FolderName.ToLower();
                    if (!Directory.Exists(finalOutputPath1))
                    {
                        Directory.CreateDirectory(finalOutputPath1);
                    }
                    if (!Directory.Exists(finalOutputPath2))
                    {
                        Directory.CreateDirectory(finalOutputPath2);
                    }
                }

                BuildPipeline.BuildAssetBundles(finalOutputPath1, buildMap.ToArray(), BuildAssetBundleOptions.StrictMode, selection);
                //> 拷贝AB文件到输出目录
                List <FileVersionInfo> moduleVersion = new List <FileVersionInfo>();

                foreach (var f in names)
                {
                    if (File.Exists(finalOutputPath1 + "/" + f))
                    {
                        File.Copy(finalOutputPath1 + "/" + f, finalOutputPath2 + "/" + f, true);
                        //> 创建版本文件信息
                        moduleVersion.Add(TiyVersionListCreator.GetVersionInfoByFile(outputPath2, finalOutputPath2 + "/" + f, v.FolderName.ToLower()));
                    }
                    else
                    {
                        Debug.LogErrorFormat("File is missing:{0}", finalOutputPath1 + "/" + f);
                    }
                }

                if (Config.IsCreateVersionList)
                {
                    if (Config.IsModuleStructureForVersion)
                    {
                        string versionFilePath = "";
                        if (Config.IsModuleStructure)
                        {
                            versionFilePath = outputPath2 + "/" + v.FolderName.ToLower() + "/" + "version.list";
                        }
                        else
                        {
                            versionFilePath = outputPath2 + "/" + v.FolderName.ToLower() + "." + "version.list";
                        }
                        TiyVersionListCreator.CreateVersionListByTemplate(moduleVersion, Config.FullVersionListTemplateFile, versionFilePath);
                    }
                    else
                    {
                        versionList.AddRange(moduleVersion);
                    }
                }
            }

            if (Config.IsCreateVersionList && versionList.Count > 0)
            {
                TiyVersionListCreator.CreateVersionListByTemplate(versionList, Config.FullVersionListTemplateFile, outputPath2 + "/version.list");
            }


            System.Diagnostics.Process.Start(outputPath2);
            Debug.Log("Build Complete!");
            GUIUtility.ExitGUI();
        }