private void OnGUIFileInfo(AssetBundleBuildInfo info) { EditorGUILayout.BeginHorizontal(); if (!info.IsInAssetDataBase) { GUI.color = Color.red; GUI.enabled = false; } if (info.IsMenifest) { GUI.color = Color.green; GUI.enabled = false; } if (info.IsNew) { GUI.color = Color.yellow; } if (info.IsNew) { GUI.color = Color.cyan; } info.IsPublish = EditorGUILayout.ToggleLeft(info.AssetBundleName, info.IsPublish, EditorStyles.boldLabel, GUILayout.Width(150f)); string relativePath = EnvUtil.MakeRelative(info.FullPath, AssetBundleBuildSetting.AbsoluteOutputPath); EditorGUILayout.LabelField(relativePath); EditorGUILayout.EndHorizontal(); GUI.color = Color.white; GUI.enabled = true; }
public static AssetBundleManifest BuildAssetBundle(BuildTarget buildTarget) { TestResourcesEditorSettingsData settings = TestResourcesEditorSettings.Settings.GetData(); AssetBundleBuildInfo build = GetAssetBundleBuildInfo(settings.AssetBundleName, settings.Folders); string outputPath = TestResourcesEditorSettings.GetAssetBundleOutputPath(); Directory.CreateDirectory(outputPath); return(AssetBundleBuildUtility.Build(new[] { build }, outputPath, buildTarget, settings.AssetBundleOptions)); }
private void CurrentAssetBundlesGUI() { // //区域的视图范围:左上角位置固定在上一个区域的底部,宽度固定(240),高度为窗口高度的一半再减去空隙(15),上下都有空隙 _currentABViewRect = new Rect(5, (int)position.height / 2 + 10, 240, (int)position.height / 2 - 15); _currentABScollRect = new Rect(5, (int)position.height / 2 + 10, 240, _currentABViewHeight); _currentABScroll = GUI.BeginScrollView(_currentABViewRect, _currentABScroll, _currentABScollRect); GUI.BeginGroup(_currentABScollRect, box); _currentABViewHeight = 5; if (_currentAB != -1) { AssetBundleBuildInfo build = _assetBundle.AssetBundles[_currentAB]; for (int i = 0; i < build.Assets.Count; ++i) { //同理,遍历到当前选中的资源对象,在原地画蓝色高亮背景框 if (_currentABAsset == i) { GUI.Box(new Rect(10, _currentABViewHeight, 200, 15), "", _LRSelect); GUIContent content = EditorGUIUtility.ObjectContent(null, build.Assets[i].AssetType); content.text = build.Assets[i].AssetName; GUI.Label(new Rect(20, _currentABViewHeight, 205, 15), content); //绘制减号按钮 if (GUI.Button(new Rect(180, _currentABViewHeight, 20, 15), "", _OLMinus)) { build.RemoveAsset(build.Assets[i]); _currentABAsset = -1; } } else { //原地绘制Button控件,当点击时,此资源对象被选中 GUIContent content = EditorGUIUtility.ObjectContent(null, build.Assets[i].AssetType); content.text = build.Assets[i].AssetName; if (GUI.Button(new Rect(5, _currentABViewHeight, 205, 15), content)) { _currentABAsset = i; } } _currentABViewHeight += 20; } } _currentABViewHeight += 5; if (_currentABViewHeight < _currentABViewRect.height) { _currentABViewHeight = (int)_currentABViewRect.height; } GUI.EndGroup(); GUI.EndScrollView(); }
/// <summary> /// 读取资源文件夹下的所有子资源 /// </summary> public static void ReadAssetsInChildren(AssetInfo asset) { if (asset.AssetFileType != FileType.Folder) { return; } DirectoryInfo di = new DirectoryInfo(asset.AssetFullPath); FileSystemInfo[] fileinfo = di.GetFileSystemInfos(); foreach (FileSystemInfo fi in fileinfo) { if (fi is DirectoryInfo) { if (IsValidFolder(fi.Name)) { AssetInfo ai = new AssetInfo(fi.FullName, fi.Name, false); asset.childAssetInfo.Add(ai); //继续深层遍历这个文件夹 ReadAssetsInChildren(ai); } } else { if (fi.Extension != ".meta") { AssetInfo ai = new AssetInfo(fi.FullName, fi.Name, fi.Extension); asset.childAssetInfo.Add(ai); if (ai.AssetFileType != FileType.InValidFile) { AssetBundleEditor._validAssets.Add(ai); } AssetImporter importer = AssetImporter.GetAtPath(ai.AssetPath); if (importer.assetBundleName != "") { //ai.Bundled = importer.assetBundleName; ai.IsChecked = true; AssetBundleBuildInfo one = AssetBundleEditor._assetBundle.IsExistName(importer.assetBundleName); if (one == null) { one = new AssetBundleBuildInfo(importer.assetBundleName); AssetBundleEditor._assetBundle.AssetBundles.Add(one); } one.AddAsset(ai); } } } } }
public static void CleareAsset(this AssetBundleBuildInfo build) { if (build == null || build.Assets == null || build.Assets.Count <= 0) { return; } for (int i = 0; i < build.Assets.Count; ++i) { build.Assets[i].Bundled = ""; AssetImporter importer = AssetImporter.GetAtPath(build.Assets[i].AssetPath); importer.assetBundleName = ""; } build.Assets.Clear(); }
private void MapBundles() { var bundlesMap = new Dictionary <string, AssetBundleBuildInfo>(); foreach (string assetPath in ScanningUtils.ItemsProcessor(_buildAssets, "Mapping asset to bundles", p => Path.GetFileName(p))) { string matchAssetPath = assetPath.ToLower().Substring("assets/".Length); var rule = _bundlesConfig.MatchRules(matchAssetPath); if (rule != null && rule.Type == AssetBundlesConfig.RuleType.Include && !string.IsNullOrEmpty(rule.BundleName)) { bool isSceneAsset = Path.GetExtension(assetPath) == ".unity"; string bundleName = rule.GetReplacedBundleName(matchAssetPath); AssetBundleBuildInfo bundleInfo; if (!bundlesMap.TryGetValue(bundleName, out bundleInfo)) { bundleInfo = new AssetBundleBuildInfo(bundleName, rule, isSceneAsset); bundlesMap.Add(bundleName, bundleInfo); } if (isSceneAsset) { if (!bundleInfo.IsScene) { throw new UnityException("Scenes can only be added to scene bundles"); } } else { var importer = AssetImporter.GetAtPath(assetPath); if (importer != null) { AudioImporter audioImporter = importer as AudioImporter; if (audioImporter != null) { //if (audioImporter.loadType == AudioImporterLoadType.StreamFromDisc) // throw new UnityException("Can't add streamed audio clips to asset bundles: " + assetPath); } } } bundleInfo.AssetsPaths.Add(assetPath); } } _bundles = bundlesMap.Values.OrderBy(b => b.Order).ThenBy(b => b.Name).ToList(); }
public static void TryAddBundleInfo(AssetInfo assetInfo) { if (_instance != null) { if (assetInfo != null && !string.IsNullOrEmpty(assetInfo.Bundled)) { AssetBundleBuildInfo info = _instance.TryGetByName(assetInfo.Bundled); if (info == null) { info = new AssetBundleBuildInfo(assetInfo.Bundled); _instance.AssetBundles.Add(info); } info.AddAsset(assetInfo); } } }
private void CurrentAssetBundlesGUI() { _currentABViewRect = new Rect(5, (int)position.height / 2 + 10, 240, (int)position.height / 2 - 15); _currentABScrollRect = new Rect(5, (int)position.height / 2 + 10, 240, _currentABViewHeight); _currentABScroll = GUI.BeginScrollView(_currentABViewRect, _currentABScroll, _currentABScrollRect); GUI.BeginGroup(_currentABScrollRect, _box); _currentABViewHeight = 5; //这里是我们加入的内容,判断条件:只有当前选中任意AB包对象后,此区域的内容才生效(_currentAB != -1) if (_currentAB != -1) { //遍历build.Assets(当前选中的AB包对象的资源列表) AssetBundleBuildInfo build = _assetBundle.AssetBundles[_currentAB]; for (int i = 0; i < build.Assets.Count; i++) { //同理,遍历到当前选中的资源对象,在原地画蓝色高亮背景框 if (_currentABAsset == i) { GUI.Box(new Rect(0, _currentABViewHeight, 240, 15), "", _LRSelect); } //原地绘制Button控件,当点击时,此资源对象被选中 GUIContent content = EditorGUIUtility.ObjectContent(null, build.Assets[i].AssetType); content.text = build.Assets[i].AssetName; if (GUI.Button(new Rect(5, _currentABViewHeight, 205, 15), content, _prefabLabel)) { _currentABAsset = i; } //在Button控件右方绘制减号Button控件,当点击时,删除此资源对象在当前选中的AB包中 if (GUI.Button(new Rect(215, _currentABViewHeight, 20, 15), "", _oLMinus)) { build.RemoveAsset(build.Assets[i]); _currentABAsset = -1; } _currentABViewHeight += 20; } } _currentABViewHeight += 5; if (_currentABViewHeight < _currentABViewRect.height) { _currentABViewHeight = (int)_currentABViewRect.height; } GUI.EndGroup(); GUI.EndScrollView(); }
private void CachedFileInfo() { var di = new System.IO.DirectoryInfo(AssetBundleBuildSetting.RelativeOutputPath); if (!di.Exists) { return; } var files = di.GetFiles("*.manifest", System.IO.SearchOption.AllDirectories); assetBundleList = new List <AssetBundleBuildInfo>(); foreach (var fi in files) { var info = new AssetBundleBuildInfo(fi, EditorUserBuildSettings.activeBuildTarget, AssetBundleBuildSetting.AbsoluteOutputPath); info.IsNew = false; assetBundleList.Add(info); } }
public static AssetBundleBuildInfo GetAssetBundleBuildInfo(string assetBundleName, IReadOnlyList <string> folders) { if (string.IsNullOrEmpty(assetBundleName)) { throw new ArgumentException("Value cannot be null or empty.", nameof(assetBundleName)); } if (folders == null) { throw new ArgumentNullException(nameof(folders)); } var assets = new Dictionary <string, string>(); GetAssets(assets, folders); var info = new AssetBundleBuildInfo(assetBundleName); foreach (KeyValuePair <string, string> pair in assets) { info.AddAsset(pair.Key, pair.Value); } return(info); }
/// <summary> /// 准备工作 /// </summary> private List <AssetInfo> GetBuildMap(ref Dictionary <string, AssetBundleBuildInfo> abbuildinfomap) { int progressBarCount = 0; Dictionary <string, AssetInfo> allAsset = new Dictionary <string, AssetInfo>(); // 获取所有的收集路径 List <string> collectDirectorys = AssetBundleCollectSettingData.GetAllCollectDirectory(); if (collectDirectorys.Count == 0) { throw new Exception("[BuildPatch] 配置的资源收集路径为空"); } // 获取所有资源 string[] guids = AssetDatabase.FindAssets(string.Empty, collectDirectorys.ToArray()); foreach (string guid in guids) { string mainAssetPath = AssetDatabase.GUIDToAssetPath(guid); if (AssetBundleCollectSettingData.IsIgnoreAsset(mainAssetPath)) { continue; } if (ValidateAsset(mainAssetPath) == false) { continue; } List <AssetInfo> depends = GetDependencies(mainAssetPath); for (int i = 0; i < depends.Count; i++) { AssetInfo assetInfo = depends[i]; if (allAsset.ContainsKey(assetInfo.AssetPath)) { allAsset[assetInfo.AssetPath].DependCount++; } else { allAsset.Add(assetInfo.AssetPath, assetInfo); } } // 进度条 progressBarCount++; EditorUtility.DisplayProgressBar("进度", $"依赖文件分析:{progressBarCount}/{guids.Length}", (float)progressBarCount / guids.Length); } EditorUtility.ClearProgressBar(); progressBarCount = 0; // 移除零依赖的资源 List <string> removeList = new List <string>(); foreach (KeyValuePair <string, AssetInfo> pair in allAsset) { if (pair.Value.IsCollectAsset) { continue; } if (pair.Value.DependCount == 0) { removeList.Add(pair.Value.AssetPath); } } for (int i = 0; i < removeList.Count; i++) { allAsset.Remove(removeList[i]); Debug.Log($"移除零依赖资源:{removeList[i]}"); } // 设置资源标签 foreach (KeyValuePair <string, AssetInfo> pair in allAsset) { SetAssetBundleLabelAndVariant(pair.Value); // 进度条 progressBarCount++; EditorUtility.DisplayProgressBar("进度", $"设置资源标签:{progressBarCount}/{allAsset.Count}", (float)progressBarCount / allAsset.Count); } // 整理Asset所有有效的Asset依赖 // 设置资源标签 TimeCounter timercounter = new TimeCounter(); timercounter.Start("AB依赖分析"); progressBarCount = 0; foreach (KeyValuePair <string, AssetInfo> pair in allAsset) { AssetBundleBuildInfo abbuildinfo = null; if (!abbuildinfomap.TryGetValue(pair.Value.AssetBundleLabel, out abbuildinfo)) { // 统一小写,确保和AssetBuildInfo那方一致 var assetbundlelabletolower = pair.Value.AssetBundleLabel.ToLower(); abbuildinfo = new AssetBundleBuildInfo(assetbundlelabletolower); abbuildinfomap.Add(pair.Value.AssetBundleLabel, abbuildinfo); } var directdepends = AssetDatabase.GetDependencies(pair.Key, false); foreach (var directdepend in directdepends) { AssetInfo assetinfo = null; // allAsset里包含的才是有效的Asset if (allAsset.TryGetValue(directdepend, out assetinfo)) { // 统一小写,确保和AssetBuildInfo那方一致 var assetablablelower = assetinfo.AssetBundleLabel.ToLower(); if (!pair.Value.AssetBundleLabel.Equals(assetinfo.AssetBundleLabel) && !abbuildinfo.DepABPathList.Contains(assetablablelower)) { abbuildinfo.DepABPathList.Add(assetablablelower); } } } // 进度条 progressBarCount++; EditorUtility.DisplayProgressBar("进度", $"整理AB依赖关系:{progressBarCount}/{allAsset.Count}", (float)progressBarCount / allAsset.Count); } timercounter.End(); EditorUtility.ClearProgressBar(); // 返回结果 return(allAsset.Values.ToList()); }
/// <summary> /// 清空AB包中的资源 /// </summary> public static void ClearAsset(AssetBundleBuildInfo build) { AssetDatabase.RemoveAssetBundleName(build.Name, true); }
private void TitleGUI() { if (GUI.Button(new Rect(5, 5, 60, 15), "Create", _preButton)) { AssetBundleBuildInfo build = new AssetBundleBuildInfo("ab" + System.DateTime.Now.ToString("yyyyMMddHHmmss")); _assetBundle.AssetBundles.Add(build); } //当前未选中任何一个AB包的话 禁用之后的所有UI控件 GUI.enabled = _currentAB == -1 ? false : true; //重命名当前选中的AB包(必须选中任意一个AB包后方可生效); if (GUI.Button(new Rect(65, 5, 60, 15), "Rename", _preButton)) { _isRename = true; _renameValue = ""; } //清空当前选中的AB包中的所有资源(必须选中任意一个AB包后方可生效); if (GUI.Button(new Rect(125, 5, 60, 15), "Clear", _preButton)) { if (EditorUtility.DisplayDialog("Prompt", "Clear" + _assetBundle.AssetBundles[_currentAB].Name + " ?", "Yes", "No")) { _assetBundle.AssetBundles[_currentAB].CleareAsset(); } } //删除当前的AB包,同时会自动执行Clear操作(必须选中任意一个AB包后方可生效); if (GUI.Button(new Rect(185, 5, 60, 15), "Delete", _preButton)) { if (EditorUtility.DisplayDialog("Prompt", "Delete" + _assetBundle.AssetBundles[_currentAB].Name + " ?", "Yes", "No")) { _assetBundle.DeleteAssetBundle(_currentAB); _currentAB = -1; } } //被勾选的资源添加到当前选中的AB包(必须选中任意一个AB包后方可生效); if (GUI.Button(new Rect(250, 5, 100, 15), "Add Assets", _preButton)) { List <AssetInfo> assets = _validAssets.GetCheckedAssets(); for (int i = 0; i < assets.Count; i++) { _assetBundle.AssetBundles[_currentAB].AddAsset(assets[i]); } } GUI.enabled = true; // _hideInvalidAsset =; _hideBundleAsset = GUI.Toggle(new Rect(460, 5, 100, 15), _hideBundleAsset, "Hide Bundled"); if (GUI.Toggle(new Rect(360, 5, 100, 15), _hideInvalidAsset, "Hide Invalid") != _hideInvalidAsset) { _hideInvalidAsset = !_hideInvalidAsset; } if (GUI.Button(new Rect(250, 25, 60, 15), "Open", _preButton)) { if (_buildPath != "") { Application.OpenURL(_buildPath); } } if (GUI.Button(new Rect(310, 25, 60, 15), "Browse", _preButton)) { _buildPath = EditorUtility.OpenFolderPanel("BuildPath", string.Empty, string.Empty); EditorPrefs.SetString("BuildPath", _buildPath); } if (_buildPath == "") { _buildPath = EditorPrefs.GetString("BuildPath", ""); } GUI.Label(new Rect(370, 25, 70, 15), "Build Path:"); _buildPath = GUI.TextField(new Rect(440, 25, 300, 15), _buildPath); BuildTarget buildTarget = (BuildTarget)EditorGUI.EnumPopup(new Rect((int)position.width - 205, 5, 150, 15), _buildTarget, _preDropDown); if (GUI.Button(new Rect((int)position.width - 55, 5, 50, 15), "Build", _preButton)) { AssetBundleTool.BuildAssetBundles(); } }
private void TitleGUI() { if (GUI.Button(new Rect(5, 5, 60, 15), "Create", _preButton)) { //新建一个AB包对象,并将之加入到AB包配置信息对象中 AssetBundleBuildInfo build = new AssetBundleBuildInfo("ab" + System.DateTime.Now.ToString("yyyyMMddHHmmss")); _assetBundle.AssetBundles.Add(build); } //当前未选中任一AB包的话,禁用之后的所有UI控件 GUI.enabled = _currentAB == -1 ? false : true; if (GUI.Button(new Rect(65, 5, 60, 15), "Rename", _preButton)) { _isRename = true; } if (GUI.Button(new Rect(125, 5, 60, 15), "Clear", _preButton)) { if (EditorUtility.DisplayDialog("Prompt", "Clear " + _assetBundle.AssetBundles[_currentAB].Name + " ?", "Yes", "No")) { _assetBundle.AssetBundles[_currentAB].ClearAsset(); } } if (GUI.Button(new Rect(185, 5, 60, 15), "Delete", _preButton)) { if (EditorUtility.DisplayDialog("Prompt", "Delete " + _assetBundle.AssetBundles[_currentAB].Name + "?This will clear all assets!", "Yes", "No")) { _assetBundle.DeleteAssetBundle(_currentAB); _currentAB = -1; } } if (GUI.Button(new Rect(250, 5, 100, 15), "Add Assets", _preButton)) { List <AssetInfo> assets = _asset.GetCheckedAssets(); for (int i = 0; i < assets.Count; i++) { _assetBundle.AssetBundles[_currentAB].AddAsset(assets[i]); } } //取消UI控件的禁用 GUI.enabled = true; _hideInvalidAsset = GUI.Toggle(new Rect(360, 5, 100, 15), _hideInvalidAsset, "Hide Invalid"); _hideBundleAsset = GUI.Toggle(new Rect(460, 5, 100, 15), _hideBundleAsset, "Hide Bundled"); if (GUI.Button(new Rect(250, 25, 60, 15), "Open", _preButton)) { OpenCMDDirectory(string.IsNullOrEmpty(_buildPath) ? "C:\\" : _buildPath); } if (GUI.Button(new Rect(310, 25, 60, 15), "Browse", _preButton)) { SelectDirctory(); } GUI.Label(new Rect(370, 25, 70, 15), "Build Path:"); _buildPath = GUI.TextField(new Rect(440, 25, 300, 15), _buildPath); BuildTarget buildTarget = (BuildTarget)EditorGUI.EnumPopup(new Rect((int)position.width - 205, 5, 150, 15), _buildTarget, _preDropDown); if (buildTarget != _buildTarget) { _buildTarget = buildTarget; EditorPrefs.SetInt("BuildTarget", (int)_buildTarget); } if (GUI.Button(new Rect((int)position.width - 55, 5, 50, 15), "Build", _preButton)) { EditorTool.Build(_asset, _buildPath); Close(); } }