Skip to content

Commit 56c94dd

Browse files
author
MichaelO
committed
added rename manifest
1 parent 93c010c commit 56c94dd

File tree

8 files changed

+226
-12
lines changed

8 files changed

+226
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog (unofficial)
22

3+
## [1.9.0] - 2022-11-02
4+
- Added Rename Manifest feature (optional).
5+
- Modified BundleBuildMap.BuildAssetBundles() static method params (added renameManifest param).
6+
37
## [1.8.2] - 2022-10-25
48
- Fixed replace by hash and md5 for bundle name has file name match issue, use (bundleName == manifestName) instead.
59

6.19 KB
Loading

Documentation/images/desc_img_10.png.meta

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/AssetBundleBuildTab.cs

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ internal class AssetBundleBuildTab
2121
[SerializeField]
2222
private Vector2 m_ScrollPosition;
2323

24-
2524
class ToggleData
2625
{
2726
internal ToggleData(
@@ -56,6 +55,7 @@ internal ToggleData(
5655
List<ToggleData> m_ToggleData;
5756
ToggleData m_ForceRebuild;
5857
ToggleData m_CopyToStreaming;
58+
ToggleData m_RenameManifest;
5959
GUIContent m_TargetContent;
6060
GUIContent m_CompressionContent;
6161
GUIContent m_BundleNameContent;
@@ -184,6 +184,12 @@ internal void OnEnable(EditorWindow parent)
184184
"Copy to StreamingAssets",
185185
"After build completes, will copy all build content to " + m_streamingPath + " for use in stand-alone player.",
186186
m_UserData.m_OnToggles);
187+
m_RenameManifest = new ToggleData(
188+
false,
189+
"Rename Manifest File",
190+
"After build completes, will rename main manifest file",
191+
m_UserData.m_OnToggles);
192+
187193

188194
m_TargetContent = new GUIContent("Build Target", "Choose target platform to build for.");
189195
m_CompressionContent = new GUIContent("Compression", "Choose no compress, standard (LZMA), or chunk based (LZ4)");
@@ -277,6 +283,33 @@ internal void OnGUI()
277283
m_UserData.m_OnToggles.Remove(m_CopyToStreaming.content.text);
278284
m_CopyToStreaming.state = newState;
279285
}
286+
EditorGUILayout.BeginHorizontal();
287+
newState = GUILayout.Toggle(
288+
m_RenameManifest.state,
289+
m_RenameManifest.content);
290+
if (newState != m_RenameManifest.state)
291+
{
292+
if (newState)
293+
{
294+
m_UserData.m_OnToggles.Add(m_RenameManifest.content.text);
295+
296+
}
297+
else
298+
m_UserData.m_OnToggles.Remove(m_RenameManifest.content.text);
299+
m_RenameManifest.state = newState;
300+
}
301+
EditorGUILayout.Space();
302+
if (newState)
303+
{
304+
var newManifestName = EditorGUILayout.TextField("", m_UserData.m_ManifestName);
305+
if (!System.String.IsNullOrEmpty(newManifestName) && newManifestName != m_UserData.m_ManifestName)
306+
{
307+
m_UserData.m_ManifestName = newManifestName;
308+
}
309+
}
310+
GUILayout.FlexibleSpace();
311+
EditorGUILayout.EndHorizontal();
312+
280313
}
281314

282315
// advanced options
@@ -347,6 +380,7 @@ private void ExecuteBuild()
347380
return;
348381
}
349382

383+
string renameManifest = string.Empty;
350384
if (AssetBundleModel.Model.DataSource.CanSpecifyBuildOutputDirectory)
351385
{
352386
if (string.IsNullOrEmpty(m_UserData.m_OutputPath))
@@ -383,6 +417,11 @@ private void ExecuteBuild()
383417
}
384418
if (!Directory.Exists(m_UserData.m_OutputPath))
385419
Directory.CreateDirectory(m_UserData.m_OutputPath);
420+
421+
if (m_RenameManifest.state)
422+
{
423+
renameManifest = m_UserData.m_ManifestName;
424+
}
386425
}
387426

388427
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
@@ -417,6 +456,7 @@ private void ExecuteBuild()
417456
ABBuildInfo buildInfo = new ABBuildInfo();
418457

419458
buildInfo.outputDirectory = m_UserData.m_OutputPath;
459+
buildInfo.renameManifest = renameManifest;
420460
buildInfo.options = opt;
421461
buildInfo.extdOptions = extdOpt;
422462
buildInfo.buildTarget = (BuildTarget)m_UserData.m_BuildTarget;
@@ -622,6 +662,45 @@ internal static bool Md5ForBundleName(string outputDirectory)
622662
return true;
623663
}
624664

665+
internal static bool RenameManifest(string outputDirectory, string newName)
666+
{
667+
// outputDirectory last path name = manifestName
668+
outputDirectory = outputDirectory.Replace("\\", "/");
669+
string[] pathArgs = outputDirectory.Split('/');
670+
string manifestName = pathArgs[pathArgs.Length - 1];
671+
672+
try
673+
{
674+
// get all files
675+
string[] files = Directory.GetFiles(outputDirectory, "*.*", SearchOption.AllDirectories);
676+
// replace all bundle file name by hash
677+
foreach (var file in files)
678+
{
679+
string bundleName = file.Replace(outputDirectory, string.Empty);
680+
bundleName = bundleName.Substring(1, bundleName.Length - 1);
681+
682+
// only process main manifest file
683+
if (bundleName == manifestName)
684+
{
685+
// file name (without extension)
686+
string fileName = Path.GetFileNameWithoutExtension(file);
687+
// replace it be new file (only replace last)
688+
int startIndex = file.LastIndexOf(bundleName);
689+
string newFile = file.Remove(startIndex, bundleName.Length).Insert(startIndex, newName);
690+
// copy override
691+
if (File.Exists(file)) File.Move(file, newFile);
692+
break;
693+
}
694+
}
695+
}
696+
catch
697+
{
698+
return false;
699+
}
700+
701+
return true;
702+
}
703+
625704
//Note: this is the provided BuildTarget enum with some entries removed as they are invalid in the dropdown
626705
internal enum ValidBuildTarget
627706
{
@@ -668,6 +747,7 @@ internal class BuildTabData
668747
internal BundleNameOptions m_BundleNameOption = BundleNameOptions.None;
669748
internal string m_OutputPath = string.Empty;
670749
internal bool m_UseDefaultPath = true;
750+
internal string m_ManifestName = string.Empty;
671751
}
672752
}
673753

Editor/AssetBundleDataSource/ABDataSource.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ public ExtendBuildAssetBundleOptions extdOptions
6363
set { m_extdOptions = value; }
6464
}
6565
private ExtendBuildAssetBundleOptions m_extdOptions;
66+
/// <summary>
67+
/// Rename main manifest file
68+
/// </summary>
69+
public string renameManifest
70+
{
71+
get { return m_renameManifest; }
72+
set { m_renameManifest = value; }
73+
}
74+
private string m_renameManifest;
6675
}
6776

6877
/// <summary>

Editor/BundleBuildMap.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Text;
88
using UnityEditor;
99
using UnityEngine;
10+
using static UnityEngine.GraphicsBuffer;
1011

1112
namespace AssetBundleBrowser.AssetBundleDataSource
1213
{
@@ -510,7 +511,7 @@ public bool BuildAssetBundles(ABBuildInfo info)
510511
string buildName = string.IsNullOrEmpty(this.customBuildMaps[i].buildName) ? this.customBuildMaps[i].bundleBuildMap.sourceName : this.customBuildMaps[i].buildName;
511512
string outputDirectory = $"{info.outputDirectory}/{this.customBuildMaps[i].bundleBuildMap.sourceName}/{buildName}";
512513

513-
if (BuildAssetBundles(outputDirectory, this.customBuildMaps[i].bundleBuildMap.GetBuildMap(), info.options, info.buildTarget, info.extdOptions, null))
514+
if (BuildAssetBundles(outputDirectory, this.customBuildMaps[i].bundleBuildMap.GetBuildMap(), info.options, info.buildTarget, info.extdOptions, info.renameManifest, info.onBuild))
514515
{
515516
stringBuilder.Append($"<color=#9DFF42>[Source Name: {this.customBuildMaps[i].bundleBuildMap.sourceName}, Build Name: {buildName}] Build Result => Success</color>\n");
516517
}
@@ -527,7 +528,7 @@ public bool BuildAssetBundles(ABBuildInfo info)
527528
}
528529
else
529530
{
530-
return BuildAssetBundles(info.outputDirectory, this.GetBuildMap(), info.options, info.buildTarget, info.extdOptions, info.onBuild);
531+
return BuildAssetBundles(info.outputDirectory, this.GetBuildMap(), info.options, info.buildTarget, info.extdOptions, info.renameManifest, info.onBuild);
531532
}
532533

533534
return false;
@@ -541,9 +542,10 @@ public bool BuildAssetBundles(ABBuildInfo info)
541542
/// <param name="options"></param>
542543
/// <param name="buildTarget"></param>
543544
/// <param name="extdOptions"></param>
545+
/// <param name="renameManifest"></param>
544546
/// <param name="onBuild"></param>
545547
/// <returns></returns>
546-
public static bool BuildAssetBundles(string outputDirectory, AssetBundleBuild[] buildMap, BuildAssetBundleOptions options, BuildTarget buildTarget, ExtendBuildAssetBundleOptions extdOptions, Action<string> onBuild)
548+
public static bool BuildAssetBundles(string outputDirectory, AssetBundleBuild[] buildMap, BuildAssetBundleOptions options, BuildTarget buildTarget, ExtendBuildAssetBundleOptions extdOptions, string renameManifest = null, Action<string> onBuild = null)
547549
{
548550
if (!Directory.Exists(outputDirectory)) Directory.CreateDirectory(outputDirectory);
549551

@@ -584,8 +586,16 @@ public static bool BuildAssetBundles(string outputDirectory, AssetBundleBuild[]
584586
if (Convert.ToBoolean(extdOptions & ExtendBuildAssetBundleOptions.Md5ForBundleName))
585587
{
586588
bool completes = AssetBundleBuildTab.Md5ForBundleName(outputDirectory);
587-
if (!completes) Debug.Log("<color=#FF0000>Error in process Md5 for bundle name.</color>");
588-
else Debug.Log($"<color=#60ffb0>Replace all bundle name by Md5.</color>");
589+
if (!completes) Debug.Log("<color=#FF0000>Error in process md5 for bundle name.</color>");
590+
else Debug.Log($"<color=#60ffb0>Replace all bundle name by md5.</color>");
591+
}
592+
593+
// after build (rename main manifest file)
594+
if (!string.IsNullOrEmpty(renameManifest))
595+
{
596+
bool completes = AssetBundleBuildTab.RenameManifest(outputDirectory, renameManifest);
597+
if (!completes) Debug.Log("<color=#FF0000>Error in process rename manifest.</color>");
598+
else Debug.Log($"<color=#60ffb0>Rename manifest to \"{renameManifest}\".</color>");
589599
}
590600

591601
if (onBuild != null)
@@ -599,7 +609,7 @@ public static bool BuildAssetBundles(string outputDirectory, AssetBundleBuild[]
599609
return true;
600610
}
601611

602-
public static bool BuildAssetBundles(string outputDirectory, AssetBundleBuild[] buildMap, BuildAssetBundleOptions options, BuildTarget buildTarget, Action<string> onBuild)
612+
public static bool BuildAssetBundles(string outputDirectory, AssetBundleBuild[] buildMap, BuildAssetBundleOptions options, BuildTarget buildTarget, Action<string> onBuild = null)
603613
{
604614
if (!Directory.Exists(outputDirectory)) Directory.CreateDirectory(outputDirectory);
605615

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,29 @@ When enabled sync feature can sync asset data to other BuildMap <font color=#FF0
6363
// LZ4
6464
BuildAssetBundleOptions options = BuildAssetBundleOptions.ChunkBasedCompression;
6565
66-
// regular
67-
BundleBuildMap.BuildAssetBundles(outputDirectory, bundleBuildMap.GetBuildMap(), options, target, null);
68-
6966
// including extend options
7067
ExtendBuildAssetBundleOptions extdOptions = ExtendBuildAssetBundleOptions.None;
7168
extdOptions |= ExtendBuildAssetBundleOptions.WithoutManifest;
7269
// choose one [ReplaceByHash] or [Md5ForBundleName]
7370
// extdOptions |= ExtendBuildAssetBundleOptions.ReplaceByHash;
7471
// extdOptions |= ExtendBuildAssetBundleOptions.Md5ForBundleName
75-
BundleBuildMap.BuildAssetBundles(outputDirectory, bundleBuildMap.GetBuildMap(), options, target, extdOptions, null);
72+
73+
// rename manifest (if set it empty or null will not to do)
74+
string renameManifest = "myManifest";
75+
76+
// execute regular build
77+
BundleBuildMap.BuildAssetBundles(outputDirectory, bundleBuildMap.GetBuildMap(), options, target);
78+
79+
// execute extend build
80+
BundleBuildMap.BuildAssetBundles(outputDirectory, bundleBuildMap.GetBuildMap(), options, target, extdOptions, renameManifest);
7681
```
7782

83+
### Build Extension
84+
85+
- Rename Manifest : after build completes, will rename main manifest file.
86+
87+
![](https://github.com/michael811125/AssetBundles-Browser-Plus/blob/master/Documentation/images/desc_img_10.png)
88+
7889
### Advenced Settings Extension
7990

8091
- WithoutManifest : after build remove manifest file from build folder.
@@ -83,6 +94,8 @@ When enabled sync feature can sync asset data to other BuildMap <font color=#FF0
8394

8495
- Md5ForBundleName : after build get file name to make a md5 and to replace it.
8596

97+
**※Remark** : If use custom build tool for extend option **ReplaceByHash** or **Md5ForBundleName** choose one.
98+
8699
![](https://github.com/michael811125/AssetBundles-Browser-Plus/blob/master/Documentation/images/desc_img_9.png)
87100

88101
# Installation

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"name": "com.unity.assetbundlebrowser.plus",
44
"displayName": "Asset Bundle Browser Plus",
5-
"version": "1.8.2",
5+
"version": "1.9.0",
66
"unity": "2018.1",
77
"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.",
88
"keywords": ["asset", "bundle", "bundles", "assetbundles"],

0 commit comments

Comments
 (0)