Skip to content

Commit

Permalink
fix assets are abandoned
Browse files Browse the repository at this point in the history
  • Loading branch information
locus84 committed Jun 4, 2023
1 parent 6729bdb commit 328a99c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
19 changes: 7 additions & 12 deletions Editor/AssetDependencyTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static ProcessResult ProcessDependencyTree(IEnumerable<AssetBundleBuild>
context.AtlasedSprites = AssetDatabase.FindAssets("t:spriteatlas")
.Select(guid => AssetDatabase.GUIDToAssetPath(guid))
.Where(path => SpriteAtlasExtensions.IsIncludeInBuild(AssetDatabase.LoadAssetAtPath<SpriteAtlas>(path)))
.SelectMany(path => AssetDatabase.GetDependencies(path, true).Select(dep => (path, dep)))
.SelectMany(path => AssetDatabase.GetDependencies(path, true).Where(dep => dep != path).Select(dep => (path, dep)))
.GroupBy(tuple => tuple.dep)
.ToDictionary(grp => grp.Key, grp => grp.Select(tuple => tuple.path).ToList());
#endif
Expand Down Expand Up @@ -151,10 +151,7 @@ public class Node
{
public RootNode Root { get; protected set; }
public string Path { get; private set; }
public Dictionary<string, Node> Children = new Dictionary<string, Node>();
public bool IsRoot => Root == this;
public bool HasChild => Children.Count > 0;

public Node(string path, RootNode root)
{
Root = root;
Expand All @@ -164,22 +161,21 @@ public Node(string path, RootNode root)
public void RemoveFromTree(Context context)
{
context.IndirectNodes.Remove(Path);
foreach (var kv in Children) kv.Value.RemoveFromTree(context);
}

public void CollectNodes(Context context, bool fromAtlas = false)
{
var childDeps = AssetDatabase.GetDependencies(Path, false);

#if BUNDLE_SPRITE_ATLAS
//if sprite atlas, set from atlas to true
//to prevent stack overflow
if(Path.EndsWith(".spriteatlas")) fromAtlas = true;

if(!fromAtlas && context.AtlasedSprites.TryGetValue(Path, out var atlases))
{
childDeps = childDeps.Union(atlases).Distinct().ToArray();
}

//if sprite atlas, set from atlas to true
//to prevent stack overflow
if(!fromAtlas && Path.EndsWith(".spriteatlas")) fromAtlas = true;
#endif

//if it's a scene unwarp placed prefab directly into the scene
Expand Down Expand Up @@ -210,7 +206,6 @@ public void CollectNodes(Context context, bool fromAtlas = false)
//if not, add to indirect node
var childNode = new Node(child, Root);
context.IndirectNodes.Add(child, childNode);
Children.Add(child, childNode);

//continue collect
childNode.CollectNodes(context, fromAtlas);
Expand All @@ -219,8 +214,8 @@ public void CollectNodes(Context context, bool fromAtlas = false)

//skip if it's from same bundle
if (node.Root.BundleName == Root.BundleName) continue;
node.RemoveFromTree(context);

context.IndirectNodes.Remove(child);
var newRoot = RootNode.CreateShared(child);

//add deps
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.locus.bundlesystem",
"displayName": "Locus Bundle System",
"version": "1.1.23",
"version": "1.1.24",
"description": "Simpler Assetbundle Build System using Scriptable Build Pipeline. Alternative to Unity Addressables. \n Visit https://github.com/locus84/Locus-Bundle-System for more informations.",
"unity": "2018.4",
"dependencies": {
Expand Down

0 comments on commit 328a99c

Please sign in to comment.