Skip to content

Commit ba650f5

Browse files
committed
changes to support multiple scenes in a single bundle.
1 parent 4e3aff1 commit ba650f5

File tree

5 files changed

+123
-67
lines changed

5 files changed

+123
-67
lines changed

UnityEngine.AssetBundles/Editor/AssetBundleBrowser/AssetBundleModel/ABModelAssetInfo.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public bool ContainsChild(AssetInfo asset)
6767
public class AssetInfo
6868
{
6969
public bool isScene { get; set; }
70+
public bool isFolder { get; set; }
7071
public long fileSize;
7172

7273
private HashSet<string> m_Parents;
@@ -81,6 +82,7 @@ public AssetInfo(string inName, string bundleName="")
8182
m_BundleName = bundleName;
8283
m_Parents = new HashSet<string>();
8384
isScene = false;
85+
isFolder = false;
8486
}
8587

8688
public string fullAssetName
@@ -133,9 +135,15 @@ public MessageType HighestMessageLevel()
133135
{
134136
var message = displayName + "\n";
135137
if (isScene)
136-
message += "Is a scene that is in a bundle with other assets. Scene bundles must have a single scene as the only asset.";
138+
message += "Is a scene that is in a bundle with non-scene assets. Scene bundles must have only one or more scene assets.";
137139
else
138-
message += "Is included in a bundle with a scene. Scene bundles must have a single scene as the only asset.";
140+
message += "Is included in a bundle with a scene. Scene bundles must have only one or more scene assets.";
141+
messages.Add(new MessageSystem.Message(message, MessageType.Error));
142+
}
143+
if(IsMessageSet(MessageSystem.MessageFlag.DependencySceneConflict))
144+
{
145+
var message = displayName + "\n";
146+
message += MessageSystem.GetMessage(MessageSystem.MessageFlag.DependencySceneConflict).message;
139147
messages.Add(new MessageSystem.Message(message, MessageType.Error));
140148
}
141149
if (IsMessageSet(MessageSystem.MessageFlag.AssetsDuplicatedInMultBundles))

UnityEngine.AssetBundles/Editor/AssetBundleBrowser/AssetBundleModel/ABModelBundleInfo.cs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,31 @@ public override void RefreshAssetList()
307307
}
308308
m_DependentAssets.Clear();
309309
m_BundleDependencies.Clear();
310-
311-
bool sceneInDependency = false;
310+
311+
bool assetInBundle = false;
312+
bool sceneError = false;
312313
var assets = AssetBundleModel.Model.DataSource.GetAssetPathsFromAssetBundle(m_Name.fullNativeName);
313314
foreach(var assetName in assets)
314315
{
316+
if (AssetDatabase.GetMainAssetTypeAtPath(assetName) == typeof(SceneAsset))
317+
{
318+
m_IsSceneBundle = true;
319+
if(assetInBundle)
320+
sceneError = true;
321+
}
322+
else
323+
{
324+
assetInBundle = true;
325+
if (m_IsSceneBundle)
326+
sceneError = true;
327+
}
328+
315329
var bundleName = Model.GetBundleName(assetName);
316330
if (bundleName == string.Empty)
317331
{
318332
///we get here if the current asset is only added due to being in an explicitly added folder
319333

334+
320335
var partialPath = assetName;
321336
while(
322337
partialPath != string.Empty &&
@@ -329,24 +344,14 @@ public override void RefreshAssetList()
329344
if(bundleName != string.Empty)
330345
{
331346
var folderAsset = Model.CreateAsset(partialPath, bundleName);
347+
folderAsset.isFolder = true;
332348
if (m_ConcreteAssets.FindIndex(a => a.displayName == folderAsset.displayName) == -1)
333349
{
334350
m_ConcreteAssets.Add(folderAsset);
335351
}
336-
352+
337353
m_DependentAssets.Add(Model.CreateAsset(assetName, folderAsset));
338354
m_TotalSize += m_DependentAssets.Last().fileSize;
339-
340-
if (AssetDatabase.GetMainAssetTypeAtPath(assetName) == typeof(SceneAsset))
341-
{
342-
m_IsSceneBundle = true;
343-
if(sceneInDependency)
344-
{
345-
//we've hit more than one.
346-
m_BundleMessages.SetFlag(MessageSystem.MessageFlag.DependencySceneConflict, true);
347-
}
348-
sceneInDependency = true;
349-
}
350355
}
351356
}
352357
else
@@ -364,15 +369,24 @@ public override void RefreshAssetList()
364369
}
365370
}
366371

367-
if(isSceneBundle && m_ConcreteAssets.Count > 1)
372+
if(sceneError)
368373
{
369-
m_BundleMessages.SetFlag(MessageSystem.MessageFlag.SceneBundleConflict, true);
370374
foreach (var asset in m_ConcreteAssets)
371375
{
372-
asset.SetMessageFlag(MessageSystem.MessageFlag.SceneBundleConflict, true);
376+
if (asset.isFolder)
377+
{
378+
asset.SetMessageFlag(MessageSystem.MessageFlag.DependencySceneConflict, true);
379+
m_BundleMessages.SetFlag(MessageSystem.MessageFlag.DependencySceneConflict, true);
380+
}
381+
else
382+
{
383+
asset.SetMessageFlag(MessageSystem.MessageFlag.SceneBundleConflict, true);
384+
m_BundleMessages.SetFlag(MessageSystem.MessageFlag.SceneBundleConflict, true);
385+
}
373386
}
374387
}
375388

389+
376390
m_ConcreteCounter = 0;
377391
m_DependentCounter = 0;
378392
m_Dirty = true;

UnityEngine.AssetBundles/Editor/AssetBundleBrowser/AssetBundleTree.cs

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected override void ContextClickedItem(int id)
177177
{
178178
menu.AddItem(new GUIContent("Move duplicates shared by selected"), false, DedupeOverlappedBundles, selectedNodes);
179179
menu.AddItem(new GUIContent("Move duplicates existing in any selected"), false, DedupeAllBundles, selectedNodes);
180-
menu.AddItem(new GUIContent("Delete multiple bundles"), false, DeleteBundles, selectedNodes);
180+
menu.AddItem(new GUIContent("Delete " + selectedNodes.Count + " selected bundles"), false, DeleteBundles, selectedNodes);
181181
}
182182
menu.ShowAsContext();
183183
}
@@ -424,7 +424,7 @@ protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args)
424424
case DragAndDropPosition.OutsideItems:
425425
if (data.draggedNodes != null)
426426
{
427-
visualMode = DragAndDropVisualMode.Copy;// Generic;
427+
visualMode = DragAndDropVisualMode.Copy;
428428
if (data.args.performDrop)
429429
{
430430
AssetBundleModel.Model.HandleBundleReparent(data.draggedNodes, null);
@@ -433,10 +433,10 @@ protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args)
433433
}
434434
else if(data.paths != null)
435435
{
436-
visualMode = DragAndDropVisualMode.Copy;//Generic;
436+
visualMode = DragAndDropVisualMode.Copy;
437437
if (data.args.performDrop)
438438
{
439-
DragPathsToNewSpace(data.paths, null, data.hasScene);
439+
DragPathsToNewSpace(data.paths, null);
440440
}
441441
}
442442
break;
@@ -451,31 +451,39 @@ private DragAndDropVisualMode HandleDragDropUpon(DragAndDropData data)
451451
if (targetDataBundle != null)
452452
{
453453
if (targetDataBundle.isSceneBundle)
454-
visualMode = DragAndDropVisualMode.Rejected;
454+
{
455+
if(data.hasNonScene)
456+
return DragAndDropVisualMode.Rejected;
457+
}
455458
else
456459
{
457-
if( (data.hasBundleFolder) || (data.hasScene && !targetDataBundle.IsEmpty()))
460+
if (data.hasBundleFolder)
458461
{
459462
return DragAndDropVisualMode.Rejected;
460463
}
461-
else
464+
else if (data.hasScene && !targetDataBundle.IsEmpty())
462465
{
463-
if (data.args.performDrop)
464-
{
465-
if (data.draggedNodes != null)
466-
{
467-
AssetBundleModel.Model.HandleBundleMerge(data.draggedNodes, targetDataBundle);
468-
ReloadAndSelect(targetDataBundle.nameHashCode, false);
469-
}
470-
else if (data.paths != null)
471-
{
472-
AssetBundleModel.Model.MoveAssetToBundle(data.paths, targetDataBundle.m_Name.bundleName, targetDataBundle.m_Name.variant);
473-
AssetBundleModel.Model.ExecuteAssetMove();
474-
ReloadAndSelect(targetDataBundle.nameHashCode, false);
475-
}
476-
}
466+
return DragAndDropVisualMode.Rejected;
477467
}
468+
478469
}
470+
471+
472+
if (data.args.performDrop)
473+
{
474+
if (data.draggedNodes != null)
475+
{
476+
AssetBundleModel.Model.HandleBundleMerge(data.draggedNodes, targetDataBundle);
477+
ReloadAndSelect(targetDataBundle.nameHashCode, false);
478+
}
479+
else if (data.paths != null)
480+
{
481+
AssetBundleModel.Model.MoveAssetToBundle(data.paths, targetDataBundle.m_Name.bundleName, targetDataBundle.m_Name.variant);
482+
AssetBundleModel.Model.ExecuteAssetMove();
483+
ReloadAndSelect(targetDataBundle.nameHashCode, false);
484+
}
485+
}
486+
479487
}
480488
else
481489
{
@@ -491,7 +499,7 @@ private DragAndDropVisualMode HandleDragDropUpon(DragAndDropData data)
491499
}
492500
else if (data.paths != null)
493501
{
494-
DragPathsToNewSpace(data.paths, folder, data.hasScene);
502+
DragPathsToNewSpace(data.paths, folder);
495503
}
496504
}
497505
}
@@ -525,7 +533,7 @@ private DragAndDropVisualMode HandleDragDropBetween(DragAndDropData data)
525533
}
526534
else if (data.paths != null)
527535
{
528-
DragPathsToNewSpace(data.paths, folder, data.hasScene);
536+
DragPathsToNewSpace(data.paths, folder);
529537
}
530538
}
531539
}
@@ -534,28 +542,46 @@ private DragAndDropVisualMode HandleDragDropBetween(DragAndDropData data)
534542
return visualMode;
535543
}
536544

537-
private void DragPathsToNewSpace(string[] paths, AssetBundleModel.BundleFolderInfo root, bool hasScene)
545+
private string[] dragToNewSpacePaths = null;
546+
private AssetBundleModel.BundleFolderInfo dragToNewSpaceRoot = null;
547+
private void DragPathsAsOneBundle()
538548
{
539-
if (hasScene)
549+
var newBundle = AssetBundleModel.Model.CreateEmptyBundle(dragToNewSpaceRoot);
550+
AssetBundleModel.Model.MoveAssetToBundle(dragToNewSpacePaths, newBundle.m_Name.bundleName, newBundle.m_Name.variant);
551+
AssetBundleModel.Model.ExecuteAssetMove();
552+
ReloadAndSelect(newBundle.nameHashCode, true);
553+
}
554+
private void DragPathsAsManyBundles()
555+
{
556+
List<int> hashCodes = new List<int>();
557+
foreach (var assetPath in dragToNewSpacePaths)
540558
{
541-
List<int> hashCodes = new List<int>();
542-
foreach (var assetPath in paths)
543-
{
544-
var newBundle = AssetBundleModel.Model.CreateEmptyBundle(root, System.IO.Path.GetFileNameWithoutExtension(assetPath).ToLower());
545-
AssetBundleModel.Model.MoveAssetToBundle(assetPath, newBundle.m_Name.bundleName, newBundle.m_Name.variant);
546-
hashCodes.Add(newBundle.nameHashCode);
547-
}
548-
AssetBundleModel.Model.ExecuteAssetMove();
549-
ReloadAndSelect(hashCodes);
559+
var newBundle = AssetBundleModel.Model.CreateEmptyBundle(dragToNewSpaceRoot, System.IO.Path.GetFileNameWithoutExtension(assetPath).ToLower());
560+
AssetBundleModel.Model.MoveAssetToBundle(assetPath, newBundle.m_Name.bundleName, newBundle.m_Name.variant);
561+
hashCodes.Add(newBundle.nameHashCode);
550562
}
551-
else
563+
AssetBundleModel.Model.ExecuteAssetMove();
564+
ReloadAndSelect(hashCodes);
565+
}
566+
567+
private void DragPathsToNewSpace(string[] paths, AssetBundleModel.BundleFolderInfo root)
568+
{
569+
dragToNewSpacePaths = paths;
570+
dragToNewSpaceRoot = root;
571+
if (paths.Length > 1)
552572
{
553-
var newBundle = AssetBundleModel.Model.CreateEmptyBundle(root);
554-
AssetBundleModel.Model.MoveAssetToBundle(paths, newBundle.m_Name.bundleName, newBundle.m_Name.variant);
555-
AssetBundleModel.Model.ExecuteAssetMove();
556-
ReloadAndSelect(newBundle.nameHashCode, true);
573+
GenericMenu menu = new GenericMenu();
574+
menu.AddItem(new GUIContent("Create 1 Bundle"), false, DragPathsAsOneBundle);
575+
var message = "Create ";
576+
message += paths.Length;
577+
message += " Bundles";
578+
menu.AddItem(new GUIContent(message), false, DragPathsAsManyBundles);
579+
menu.ShowAsContext();
557580
}
581+
else
582+
DragPathsAsManyBundles();
558583
}
584+
559585
protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
560586
{
561587
DragAndDrop.PrepareStartDrag();
@@ -575,7 +601,6 @@ protected override void SetupDragAndDrop(SetupDragAndDropArgs args)
575601

576602
protected override bool CanStartDrag(CanStartDragArgs args)
577603
{
578-
//args.draggedItemIDs = GetSelection();
579604
return true;
580605
}
581606

UnityEngine.AssetBundles/Editor/AssetBundleBrowser/AssetListTree.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,23 @@ protected bool IsValidDragDrop(DragAndDropArgs args)
276276
if(data.IsEmpty())
277277
return true;
278278

279-
if (data.isSceneBundle)
280-
return false;
281-
282279

283-
foreach (var assetPath in DragAndDrop.paths)
280+
if (data.isSceneBundle)
284281
{
285-
if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(SceneAsset))
286-
return false;
282+
foreach (var assetPath in DragAndDrop.paths)
283+
{
284+
if ((AssetDatabase.GetMainAssetTypeAtPath(assetPath) != typeof(SceneAsset)) &&
285+
(!AssetDatabase.IsValidFolder(assetPath)))
286+
return false;
287+
}
288+
}
289+
else
290+
{
291+
foreach (var assetPath in DragAndDrop.paths)
292+
{
293+
if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) == typeof(SceneAsset))
294+
return false;
295+
}
287296
}
288297

289298
return true;

UnityEngine.AssetBundles/Editor/AssetBundleBrowser/MessageSystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ private static void InitMessages()
190190
m_MessageLookup.Add(MessageFlag.AssetsDuplicatedInMultBundles, new Message("Assets being pulled into this bundle due to dependencies are also being pulled into another bundle. This will cause duplication in memory", MessageType.Warning));
191191
m_MessageLookup.Add(MessageFlag.VariantBundleMismatch, new Message("Variants of a given bundle must have exactly the same assets between them based on a Name.Extension (without Path) comparison. These bundle variants fail that check.", MessageType.Warning));
192192
m_MessageLookup.Add(MessageFlag.ErrorInChildren, new Message("Error in child(ren)", MessageType.Error));
193-
m_MessageLookup.Add(MessageFlag.SceneBundleConflict, new Message("A bundle with a scene must only contain that one scene. This bundle has more than one explicitly added bundles.", MessageType.Error));
194-
m_MessageLookup.Add(MessageFlag.DependencySceneConflict, new Message("The folder added to this bundle has pulled in more than one scene which is not allowed.", MessageType.Error));
193+
m_MessageLookup.Add(MessageFlag.SceneBundleConflict, new Message("A bundle with one or more scenes must only contain scenes. This bundle has scenes and non-scene assets.", MessageType.Error));
194+
m_MessageLookup.Add(MessageFlag.DependencySceneConflict, new Message("The folder added to this bundle has pulled in scenes and non-scene assets. A bundle must only have one type or the other.", MessageType.Error));
195195
}
196196
}
197197

0 commit comments

Comments
 (0)