/// <summary> /// 查找资源的依赖,并生成默认的分组,将依赖的资源也单独打包处理 /// </summary> /// <param name="isShowProgressBar"></param> internal static void FindAndAddAutoGroup(bool isShowProgressBar = false) { DeleteAutoGroup(); AssetBundleTagConfig tagConfig = Util.FileUtil.ReadFromBinary <AssetBundleTagConfig>(BundlePackUtil.GetTagConfigPath()); AssetDependFinder finder = CreateAssetDependFinder(tagConfig, isShowProgressBar); Dictionary <string, int> repeatAssetDic = finder.GetRepeatUsedAssets(); AssetBundleGroupData gData = new AssetBundleGroupData(); gData.GroupName = AUTO_REPEAT_GROUP_NAME; gData.IsMain = false; foreach (var kvp in repeatAssetDic) { AssetAddressData aaData = new AssetAddressData(); aaData.AssetAddress = aaData.AssetPath = kvp.Key; aaData.BundlePath = HashHelper.Hash_MD5_32(kvp.Key, false);//AssetDatabase.AssetPathToGUID(kvp.Key); gData.AssetDatas.Add(aaData); } if (gData.AssetDatas.Count > 0) { tagConfig.GroupDatas.Add(gData); } Util.FileUtil.SaveToBinary <AssetBundleTagConfig>(BundlePackUtil.GetTagConfigPath(), tagConfig); }
private int m_GroupIndex = 0; //索引 /// <summary> /// 执行 /// </summary> /// <param name="filterResult"></param> /// <param name="operationResult"></param> /// <returns></returns> public override AssetOperationResult Execute(AssetFilterResult filterResult, AssetOperationResult operationResult) { if (operationResult == null) { operationResult = new AssetAddressOperationResult(); } AssetAddressOperationResult result = operationResult as AssetAddressOperationResult; foreach (var assetPath in filterResult.m_AssetPaths) { if (!result.m_AddressDataDic.TryGetValue(assetPath, out AssetAddressData addressData)) { addressData = new AssetAddressData(); addressData.AssetPath = assetPath; result.m_AddressDataDic.Add(assetPath, addressData); } string rootFolder = Path.GetDirectoryName(assetPath).Replace("\\", "/"); string bundPathStr = GetAssetBundle(rootFolder, assetPath).ToLower(); //设置AB set Name switch (m_BundNameMode) { case AssetBundleNameMode.PathString: addressData.BundlePath = bundPathStr; break; case AssetBundleNameMode.PathMd5: addressData.BundlePath = GetHash(bundPathStr, false); break; } } return(result); }
public void UpdateAddressData(AssetAddressData addressData) { string assetPath = addressData.assetPath; addressData.assetAddress = GetAddressName(assetPath); addressData.bundlePath = GetBundleName(assetPath); addressData.labels = GetLabels(); addressData.isScene = IsScene(assetPath); }
/// <summary> /// 执行保存到二进制中 /// </summary> /// <returns></returns> public override AssetAssemblyResult Execute() { AssetAddressAssemblyResult result = new AssetAddressAssemblyResult(); foreach (var group in m_AssetGroups) { group.Execute(result); } //读取配置 AssetBundleTagConfig tagConfig = Util.FileUtil.ReadFromBinary <AssetBundleTagConfig>(BundlePackUtil.GetTagConfigPath()); if (tagConfig.GroupDatas == null) { tagConfig.GroupDatas = new List <AssetBundleGroupData>(); } else { tagConfig.GroupDatas.Clear(); } foreach (var groupResult in result.m_GroupResults) { AssetAddressGroupResult gResult = groupResult as AssetAddressGroupResult; AssetBundleGroupData groupData = new AssetBundleGroupData(); groupData.GroupName = gResult.m_GroupName; groupData.IsGenAddress = gResult.m_IsGenAddress; groupData.IsMain = gResult.m_IsMain; groupData.IsPreload = gResult.m_IsPreload; tagConfig.GroupDatas.Add(groupData); foreach (var operationResult in gResult.m_OperationResults) { AssetAddressOperationResult oResult = operationResult as AssetAddressOperationResult; foreach (var kvp in oResult.m_AddressDataDic) { AssetAddressData aaData = new AssetAddressData(); AssetAddressData kvpValue = kvp.Value as AssetAddressData; aaData.AssetAddress = kvpValue.AssetAddress; aaData.AssetPath = kvpValue.AssetPath; aaData.BundlePath = kvpValue.BundlePath; aaData.Labels = new List <string>(kvpValue.Labels).ToArray(); groupData.AssetDatas.Add(aaData); } } } //保存配置 Util.FileUtil.SaveToBinary <AssetBundleTagConfig>(BundlePackUtil.GetTagConfigPath(), tagConfig); return(result); }
public static Dictionary <string, string> CollectionAssetPathToBundleNames() { Dictionary <string, string> pathToNames = new Dictionary <string, string>(); pathToNames[AssetAddressConfig.CONFIG_PATH] = AssetAddressConfig.CONFIG_ASSET_BUNDLE_NAME.ToLower(); #region Collection AssetBundleTagConfig tagConfig = Util.FileUtil.ReadFromBinary <AssetBundleTagConfig>(BundlePackUtil.GetTagConfigPath()); AssetAddressData[] datas = (from groupData in tagConfig.GroupDatas from detailData in groupData.AssetDatas select detailData).ToArray(); long elapsedMS = Leyoutech.Utility.DebugUtility.GetMillisecondsSinceStartup(); for (int iData = 0; iData < datas.Length; iData++) { AssetAddressData iterData = datas[iData]; string assetPath = iterData.AssetPath; string bundleName = iterData.BundlePath.ToLower(); pathToNames[assetPath] = bundleName; if (Path.GetExtension(assetPath).ToLower() != ".spriteatlas") { continue; } SpriteAtlas atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(assetPath); if (atlas == null) { continue; } UnityObject[] packables = atlas.GetPackables(); for (int iPackable = 0; iPackable < packables.Length; iPackable++) { UnityObject iterPackable = packables[iPackable]; if (iterPackable.GetType() == typeof(Sprite)) { pathToNames[AssetDatabase.GetAssetPath(iterPackable)] = bundleName; } else if (iterPackable.GetType() == typeof(DefaultAsset)) { string folderPath = AssetDatabase.GetAssetPath(iterPackable); string[] assets = AssetDatabaseUtil.FindAssetInFolder <Sprite>(folderPath); for (int iAsset = 0; iAsset < assets.Length; iAsset++) { pathToNames[assets[iAsset]] = bundleName; } } } } elapsedMS = Leyoutech.Utility.DebugUtility.GetMillisecondsSinceStartup() - elapsedMS; Leyoutech.Utility.DebugUtility.Log(Leyoutech.BuildPipeline.BuildPipelineGraph.LOG_TAG, $"Collection all bundleName count ({pathToNames.Count}) elapsed {Leyoutech.Utility.DebugUtility.FormatMilliseconds(elapsedMS)}"); #endregion return(pathToNames); }
public AssetAddressData GetAddressData(string assetPath) { AssetAddressData addressData = new AssetAddressData(); addressData.assetAddress = GetAddressName(assetPath); addressData.assetPath = assetPath; addressData.bundlePath = GetBundleName(assetPath); addressData.labels = GetLabels(); addressData.isScene = IsScene(assetPath); return(addressData); }
/// <summary> /// 根据筛选条件筛选内容 /// </summary> /// <param name="detailData"></param> /// <returns></returns> private bool FilterAssetDetailData(AssetAddressData detailData) { if (string.IsNullOrEmpty(m_SearchText)) { return(true); } bool isValid = false; if (m_SelecteddSearchParamIndex == 0 || m_SelecteddSearchParamIndex == 1) { if (!string.IsNullOrEmpty(detailData.AssetAddress)) { isValid = detailData.AssetAddress.IndexOf(m_SearchText, StringComparison.OrdinalIgnoreCase) >= 0; } } if (!isValid) { if (m_SelecteddSearchParamIndex == 0 || m_SelecteddSearchParamIndex == 2) { if (!string.IsNullOrEmpty(detailData.AssetPath)) { isValid = detailData.AssetPath.IndexOf(m_SearchText, StringComparison.OrdinalIgnoreCase) >= 0; } } } if (!isValid) { if (m_SelecteddSearchParamIndex == 0 || m_SelecteddSearchParamIndex == 3) { if (!string.IsNullOrEmpty(detailData.BundlePath)) { isValid = detailData.BundlePath.IndexOf(m_SearchText, StringComparison.OrdinalIgnoreCase) >= 0; } } } if (!isValid) { string label = string.Join(",", detailData.Labels); if (m_SelecteddSearchParamIndex == 0 || m_SelecteddSearchParamIndex == 4) { if (!string.IsNullOrEmpty(label)) { isValid = label.IndexOf(m_SearchText, StringComparison.OrdinalIgnoreCase) >= 0; } } } return(isValid); }
/// <summary> /// 执行 /// </summary> /// <param name="filterResult"></param> /// <param name="operationResult"></param> /// <returns></returns> public override AssetOperationResult Execute(AssetFilterResult filterResult, AssetOperationResult operationResult) { if (operationResult == null) { operationResult = new AssetAddressOperationResult(); } AssetAddressOperationResult result = operationResult as AssetAddressOperationResult; foreach (var assetPath in filterResult.m_AssetPaths) { if (!result.m_AddressDataDic.TryGetValue(assetPath, out AssetAddressData addressData)) { addressData = new AssetAddressData(); addressData.AssetPath = assetPath; result.m_AddressDataDic.Add(assetPath, addressData); } addressData.AssetAddress = GetAssetAddress(assetPath); } return(result); }
protected override void RowGUI(RowGUIArgs args) { var item = (TreeViewItem <TreeElementWithData <AssetBundleGroupTreeData> >)args.item; AssetBundleGroupTreeData groupTreeData = item.data.Data; Rect contentRect = args.rowRect; contentRect.x += GetContentIndent(item); contentRect.width -= GetContentIndent(item); GUILayout.BeginArea(contentRect); { AssetBundleGroupData groupData = groupTreeData.GroupData; if (groupTreeData.IsGroup) { EditorGUILayout.BeginHorizontal(); { string groupName = groupData.GroupName; if (groupData.IsMain) { groupName += "(Main)"; } groupName += " " + groupData.AssetDatas.Count; EditorGUILayout.LabelField(new GUIContent(groupName)); if (groupTreeData.IsAddressRepeat) { if (GUILayout.Button(m_AddressRepeatContent)) { SetExpanded(args.item.id, true); } } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); { if (groupTreeData.IsAddressRepeat)//如果资源有重复的添加提示 { if (GUILayout.Button(m_AddressRepeatContent, GUILayout.Width(24))) { Vector2 pos = GUIUtility.GUIToScreenPoint(Input.mousePosition); AssetAddressRepeatPopupWindow.GetWindow().ShowWithParam(groupTreeData.RepeatAddressList, pos); } } else { GUILayout.Label(GUIContent.none, GUILayout.Width(24)); } EditorGUIUtil.BeginLabelWidth(60); { AssetAddressData assetData = groupData.AssetDatas[groupTreeData.DataIndex]; EditorGUILayout.LabelField(new GUIContent("" + groupTreeData.DataIndex), GUILayout.Width(20)); EditorGUILayout.TextField("address:", assetData.AssetAddress); GUILayout.BeginVertical(); { EditorGUILayout.TextField("path:", assetData.AssetPath); EditorGUILayout.TextField("bundle:", assetData.BundlePath); EditorGUILayout.TextField("labels:", string.Join(",", assetData.Labels)); } GUILayout.EndVertical(); } EditorGUIUtil.EndLableWidth(); } GUILayout.EndHorizontal(); } } GUILayout.EndArea(); }
/// <summary> /// 生成TreeView需要的数据 /// </summary> private void FilterTreeModel() { TreeModel <TreeElementWithData <AssetBundleGroupTreeData> > treeModel = m_DetailGroupTreeView.treeModel; TreeElementWithData <AssetBundleGroupTreeData> treeModelRoot = treeModel.root; treeModelRoot.children?.Clear(); if (m_TagConfig.GroupDatas == null) { return; } List <AssetAddressData> dataList = (from groupData in m_TagConfig.GroupDatas where groupData.IsMain from detailData in groupData.AssetDatas select detailData).ToList(); for (int i = 0; i < m_TagConfig.GroupDatas.Count; i++) { AssetBundleGroupData groupData = m_TagConfig.GroupDatas[i]; TreeElementWithData <AssetBundleGroupTreeData> groupElementData = new TreeElementWithData <AssetBundleGroupTreeData>( new AssetBundleGroupTreeData() { IsGroup = true, GroupData = groupData, }, "", 0, (i + 1) * 100); treeModel.AddElement(groupElementData, treeModelRoot, treeModelRoot.hasChildren ? treeModelRoot.children.Count : 0); bool isAddressRepeat = false; for (int j = 0; j < groupData.AssetDatas.Count; ++j) { AssetAddressData detailData = groupData.AssetDatas[j]; List <AssetAddressData> repeatList = (from data in dataList where data.AssetAddress == detailData.AssetAddress select data).ToList(); if (FilterAssetDetailData(detailData)) { TreeElementWithData <AssetBundleGroupTreeData> elementData = new TreeElementWithData <AssetBundleGroupTreeData>( new AssetBundleGroupTreeData() { IsGroup = false, DataIndex = j, GroupData = groupData, }, "", 1, (i + 1) * 100 + (j + 1)); if (repeatList.Count > 1) { elementData.Data.IsAddressRepeat = true; elementData.Data.RepeatAddressList = repeatList; if (!isAddressRepeat) { isAddressRepeat = true; } } treeModel.AddElement(elementData, groupElementData, groupElementData.hasChildren ? groupElementData.children.Count : 0); } } groupElementData.Data.IsAddressRepeat = isAddressRepeat; } }