public AssetInfo(string assetPath) { AssetPath = assetPath; IsCollectAsset = BuildSettingData.IsCollectAsset(assetPath); IsSceneAsset = AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(SceneAsset); IsVideoAsset = AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(UnityEngine.Video.VideoClip); }
/// <summary> /// 检测标签名是否有冲突 /// 注意:因为AssetBundle文件后缀格式为统一格式。在同一目录下,相同名字的不同类型的文件会发生冲突。 /// </summary> private void CheckTagNameConflict() { int progressBarCount = 0; Dictionary <string, string> allElements = new Dictionary <string, string>(); // 获取所有的打包路径 List <string> collectPathList = BuildSettingData.GetAllCollectPath(); if (collectPathList.Count == 0) { return; } // 获取所有资源 string[] guids = AssetDatabase.FindAssets(string.Empty, collectPathList.ToArray()); foreach (string guid in guids) { string assetPath = AssetDatabase.GUIDToAssetPath(guid); if (ValidateAsset(assetPath) == false) { continue; } string[] dependArray = AssetDatabase.GetDependencies(assetPath, true); foreach (string dependPath in dependArray) { if (ValidateAsset(dependPath) == false) { continue; } string extension = Path.GetExtension(dependPath); string tagName = dependPath.Remove(dependPath.LastIndexOf(".")); // 注意:去掉文件格式 if (allElements.ContainsKey(tagName)) { if (allElements[tagName] != extension) { throw new Exception($"发现重复的标签在同一个目录下:{tagName} {allElements[tagName]} {extension}"); } } else { allElements.Add(tagName, extension); } } // 进度条 progressBarCount++; EditorUtility.DisplayProgressBar("进度", $"重名文件检测:{progressBarCount}/{guids.Length}", (float)progressBarCount / guids.Length); } EditorUtility.ClearProgressBar(); progressBarCount = 0; }
private void OnGUI() { // 列表显示 EditorGUILayout.Space(); EditorGUILayout.LabelField($"Pack Path List"); for (int i = 0; i < BuildSettingData.Setting.Elements.Count; i++) { string folderPath = BuildSettingData.Setting.Elements[i].FolderPath; BuildSetting.EFolderPackRule packRule = BuildSettingData.Setting.Elements[i].PackRule; BuildSetting.EBundleNameRule nameRule = BuildSettingData.Setting.Elements[i].NameRule; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(folderPath); BuildSetting.EFolderPackRule newPackRule = (BuildSetting.EFolderPackRule)EditorGUILayout.EnumPopup(packRule, GUILayout.MaxWidth(150)); if (newPackRule != packRule) { packRule = newPackRule; BuildSettingData.ModifyElement(folderPath, packRule, nameRule); } BuildSetting.EBundleNameRule newNameRule = (BuildSetting.EBundleNameRule)EditorGUILayout.EnumPopup(nameRule, GUILayout.MaxWidth(150)); if (newNameRule != nameRule) { nameRule = newNameRule; BuildSettingData.ModifyElement(folderPath, packRule, nameRule); } if (GUILayout.Button("-", GUILayout.MaxWidth(40))) { BuildSettingData.RemoveElement(folderPath); break; } } EditorGUILayout.EndHorizontal(); } // 添加按钮 if (GUILayout.Button("+")) { string resultPath = EditorTools.OpenFolderPanel("+", _lastOpenFolderPath); if (resultPath != null) { _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath); BuildSettingData.AddElement(_lastOpenFolderPath); } } }
/// <summary> /// 检测预制件是否损坏 /// </summary> private void CheckAllPrefabValid() { // 获取所有的打包路径 List <string> packPathList = BuildSettingData.GetAllCollectPath(); if (packPathList.Count == 0) { throw new Exception("[BuildPackage] 打包路径列表不能为空"); } // 获取所有资源列表 int checkCount = 0; int invalidCount = 0; string[] guids = AssetDatabase.FindAssets(string.Empty, packPathList.ToArray()); foreach (string guid in guids) { string assetPath = AssetDatabase.GUIDToAssetPath(guid); string ext = System.IO.Path.GetExtension(assetPath); if (ext == ".prefab") { UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object)); if (prefab == null) { invalidCount++; Debug.LogError($"[Build] 发现损坏预制件:{assetPath}"); } } // 进度条相关 checkCount++; EditorUtility.DisplayProgressBar("进度", $"检测预制件文件是否损坏:{checkCount}/{guids.Length}", (float)checkCount / guids.Length); } EditorUtility.ClearProgressBar(); if (invalidCount == 0) { Debug.Log($"没有发现损坏预制件"); } }
/// <summary> /// 设置资源的打包标签 /// </summary> private void SetAssetPackingTag(AssetInfo assetInfo) { string tagName = BuildSettingData.GetAssetTagName(assetInfo.AssetPath); assetInfo.AssetBundleName = $"{tagName}{PatchDefine.StrBundleSuffixName}"; }
/// <summary> /// 准备工作 /// </summary> private List <AssetInfo> PrepareWork() { int progressBarCount = 0; Dictionary <string, AssetInfo> allAsset = new Dictionary <string, AssetInfo>(); // 获取所有的打包路径 List <string> packPathList = BuildSettingData.GetAllCollectPath(); if (packPathList.Count == 0) { throw new Exception("[BuildPackage] 配置的打包路径列表为空"); } // 获取所有资源列表 string[] guids = AssetDatabase.FindAssets(string.Empty, packPathList.ToArray()); foreach (string guid in guids) { string assetPath = AssetDatabase.GUIDToAssetPath(guid); if (BuildSettingData.IsIgnoreAsset(assetPath)) { continue; } if (ValidateAsset(assetPath)) { List <AssetInfo> depends = GetDependencies(assetPath); for (int i = 0; i < depends.Count; i++) { AssetInfo assetInfo = depends[i]; if (allAsset.ContainsKey(assetInfo.AssetPath)) { AssetInfo cacheInfo = allAsset[assetInfo.AssetPath]; cacheInfo.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]); } // 设置资源的打包标签 foreach (KeyValuePair <string, AssetInfo> pair in allAsset) { SetAssetPackingTag(pair.Value); // 进度条 progressBarCount++; EditorUtility.DisplayProgressBar("进度", $"设置打包标签:{progressBarCount}/{allAsset.Count}", (float)progressBarCount / allAsset.Count); } EditorUtility.ClearProgressBar(); progressBarCount = 0; // 构建资源列表 List <AssetInfo> result = new List <AssetInfo>(); foreach (KeyValuePair <string, AssetInfo> pair in allAsset) { result.Add(pair.Value); } return(result); }
/// Add a new build setting in the list /// @param name Build setting name public void AddNewBuildSetting(string name) { BuildSettingData bs = new BuildSettingData(name); m_buildSettings.Add(bs); int index = RefreshBuildSettingsLists(); m_currentBuildSettingIndex = index - 1; }