Skip to content

Commit

Permalink
added move duplicates separate by asset name
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelo committed Jun 14, 2022
1 parent 4b32053 commit 826e7f7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog (unofficial)

## [1.3.0] - 2022-06-14
- Added Move duplicates separate by asset name into <dependencies> folder (right-click on a bundle in AssetBundle Browser Plus)
- Added Move duplicates by selected and separate by asset name into <dependencies> folder (right-click on multi-bundle in AssetBundle Browser Plus)

## [1.2.3] - 2022-06-14
- Optimized LevenshteinDistance algorithm.

Expand Down
27 changes: 22 additions & 5 deletions Editor/AssetBundleModel/ABModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,8 @@ internal static BundleInfo FindBundle(BundleNameData name)
}
}

internal static BundleInfo HandleDedupeBundles(IEnumerable<BundleInfo> bundles, bool onlyOverlappedAssets)
internal static BundleInfo HandleDedupeBundles(IEnumerable<BundleInfo> bundles, bool onlyOverlappedAssets, bool separateByAssetName)
{
var newBundle = CreateEmptyBundle();
HashSet<string> dupeAssets = new HashSet<string>();
HashSet<string> fullAssetList = new HashSet<string>();

Expand Down Expand Up @@ -543,9 +542,27 @@ internal static BundleInfo HandleDedupeBundles(IEnumerable<BundleInfo> 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)
Expand Down
17 changes: 13 additions & 4 deletions Editor/AssetBundleTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dependencies> folder"), false, DedupeSepareteBundles, selectedNodes);
}
menu.AddItem(new GUIContent("Rename"), false, RenameBundle, selectedNodes);
menu.AddItem(new GUIContent("Delete " + selectedNodes[0].displayName), false, DeleteBundles, selectedNodes);

Expand All @@ -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 <dependencies> folder"), false, DedupeSepareteBundles, selectedNodes);
menu.AddItem(new GUIContent("Delete " + selectedNodes.Count + " selected bundles"), false, DeleteBundles, selectedNodes);
}
menu.ShowAsContext();
Expand Down Expand Up @@ -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<AssetBundleModel.BundleTreeItem>;
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<int>();
selection.Add(newBundle.nameHashCode);
ReloadAndSelect(selection);
}
else if (separateByAssetName) Refresh();
else
{
if (onlyOverlappedAssets)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 826e7f7

Please sign in to comment.