From 826e7f7ad7eea430d92b820974b9e8850c22e451 Mon Sep 17 00:00:00 2001 From: michaelo Date: Tue, 14 Jun 2022 20:44:24 +0800 Subject: [PATCH] added move duplicates separate by asset name --- CHANGELOG.md | 4 ++++ Editor/AssetBundleModel/ABModel.cs | 27 ++++++++++++++++++++++----- Editor/AssetBundleTree.cs | 17 +++++++++++++---- package.json | 2 +- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d24c5bb..9d4036e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog (unofficial) +## [1.3.0] - 2022-06-14 +- Added Move duplicates separate by asset name into folder (right-click on a bundle in AssetBundle Browser Plus) +- Added Move duplicates by selected and separate by asset name into folder (right-click on multi-bundle in AssetBundle Browser Plus) + ## [1.2.3] - 2022-06-14 - Optimized LevenshteinDistance algorithm. diff --git a/Editor/AssetBundleModel/ABModel.cs b/Editor/AssetBundleModel/ABModel.cs index 4e8249d..d7e28ea 100644 --- a/Editor/AssetBundleModel/ABModel.cs +++ b/Editor/AssetBundleModel/ABModel.cs @@ -512,9 +512,8 @@ internal static BundleInfo FindBundle(BundleNameData name) } } - internal static BundleInfo HandleDedupeBundles(IEnumerable bundles, bool onlyOverlappedAssets) + internal static BundleInfo HandleDedupeBundles(IEnumerable bundles, bool onlyOverlappedAssets, bool separateByAssetName) { - var newBundle = CreateEmptyBundle(); HashSet dupeAssets = new HashSet(); HashSet fullAssetList = new HashSet(); @@ -543,9 +542,27 @@ internal static BundleInfo HandleDedupeBundles(IEnumerable bundles, if (dupeAssets.Count == 0) return null; - MoveAssetToBundle(dupeAssets, newBundle.m_Name.bundleName, string.Empty); - ExecuteAssetMove(); - return newBundle; + if (!separateByAssetName) + { + var newBundle = CreateEmptyBundle(); + MoveAssetToBundle(dupeAssets, newBundle.m_Name.bundleName, string.Empty); + ExecuteAssetMove(); + return newBundle; + } + else + { + foreach (var assetName in dupeAssets) + { + string groupName = "dependencies"; + var pathIndex = (assetName.LastIndexOf("/") == -1 ? assetName.LastIndexOf("\\") : assetName.LastIndexOf("/")) + 1; + var variantCount = assetName.Length - (assetName.LastIndexOf(".") == -1 ? 0 : assetName.LastIndexOf(".")); + string bundleName = assetName.Substring(pathIndex, assetName.Length - variantCount - pathIndex); + MoveAssetToBundle(assetName, $"{groupName}/{bundleName}".ToLower(), string.Empty); + ExecuteAssetMove(); + } + } + + return null; } internal static BundleInfo HandleConvertToVariant(BundleDataInfo bundle) diff --git a/Editor/AssetBundleTree.cs b/Editor/AssetBundleTree.cs index 0f99bf0..6c86447 100644 --- a/Editor/AssetBundleTree.cs +++ b/Editor/AssetBundleTree.cs @@ -212,7 +212,10 @@ protected override void ContextClickedItem(int id) } } if (selectedNodes[0].bundle.IsMessageSet(MessageSystem.MessageFlag.AssetsDuplicatedInMultBundles)) + { menu.AddItem(new GUIContent("Move duplicates to new bundle"), false, DedupeAllBundles, selectedNodes); + menu.AddItem(new GUIContent("Move duplicates separate by asset name into folder"), false, DedupeSepareteBundles, selectedNodes); + } menu.AddItem(new GUIContent("Rename"), false, RenameBundle, selectedNodes); menu.AddItem(new GUIContent("Delete " + selectedNodes[0].displayName), false, DeleteBundles, selectedNodes); @@ -221,6 +224,7 @@ protected override void ContextClickedItem(int id) { menu.AddItem(new GUIContent("Move duplicates shared by selected"), false, DedupeOverlappedBundles, selectedNodes); menu.AddItem(new GUIContent("Move duplicates existing in any selected"), false, DedupeAllBundles, selectedNodes); + menu.AddItem(new GUIContent("Move duplicates by selected and separate by asset name into folder"), false, DedupeSepareteBundles, selectedNodes); menu.AddItem(new GUIContent("Delete " + selectedNodes.Count + " selected bundles"), false, DeleteBundles, selectedNodes); } menu.ShowAsContext(); @@ -341,24 +345,29 @@ void ConvertToVariant(object context) } } + void DedupeSepareteBundles(object context) + { + DedupeBundles(context, false, true); + } void DedupeOverlappedBundles(object context) { - DedupeBundles(context, true); + DedupeBundles(context, true, false); } void DedupeAllBundles(object context) { - DedupeBundles(context, false); + DedupeBundles(context, false, false); } - void DedupeBundles(object context, bool onlyOverlappedAssets) + void DedupeBundles(object context, bool onlyOverlappedAssets, bool separateByAssetName) { var selectedNodes = context as List; - var newBundle = AssetBundleModel.Model.HandleDedupeBundles(selectedNodes.Select(item => item.bundle), onlyOverlappedAssets); + var newBundle = AssetBundleModel.Model.HandleDedupeBundles(selectedNodes.Select(item => item.bundle), onlyOverlappedAssets, separateByAssetName); if (newBundle != null) { var selection = new List(); selection.Add(newBundle.nameHashCode); ReloadAndSelect(selection); } + else if (separateByAssetName) Refresh(); else { if (onlyOverlappedAssets) diff --git a/package.json b/package.json index 9e5520e..3613884 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ { "name": "com.unity.assetbundlebrowser.plus", "displayName": "Asset Bundle Browser Plus", - "version": "1.2.3", + "version": "1.3.0", "unity": "2018.1", "description": "The Asset Bundle Browser tool enables the user to view and edit the configuration of asset bundles for their Unity project. It will block editing that would create invalid bundles, and inform you of any issues with existing bundles. It also provides basic build functionality.\n\nUse this tool as an alternative to selecting assets and setting their asset bundle manually in the inspector. It can be dropped into any Unity project with a version of 5.6 or greater. It will create a new menu item in Window > AssetBundle Browser. The bundle configuration, build functionality, and built-bundle inspection are split into three tabs within the new window.", "keywords": ["asset", "bundle", "bundles", "assetbundles"],