Project Window behavior:
Right/context click on a folder in the Project view and click on “Select Dependencies” and it will select every asset underneath it. How do I achieve this with script?
EditorUtility.CollectDependencies(Selection.objects) //where objects is a length of 1 and consists of the highlighted folder
will return 0 results. Am I stuck using AssetDatabase.LoadAssetAtPath( ) and iterating through the file structure?
it should work but keep in mind that it will require a real object, not a folder as a folder never has any dependency.
if you apply it to a folder you must manually fill the selection with multiple objects, any in the folder you tried to get the dependencies for
I’d like to clone the behavior of the “Right click on folder, Select Dependencies” functionality of the editor window. It seems that it simply skips over objects that are of type DefaultAsset. Is there any way to determine how Unity goes about doing this? I can manually populate the list but I’d love to see how Unity handled it heh
To replicate that, you would need to:
- Get all childs in the folder you selected. Thats something you will need to do manually
- For each object you find that way, select its dependencies
- For each folder found that way, return to 1 and repeat
- Once done, return the full bomb of objects, if you want to visualize you additionally need to set the selection to this object array you have