A different architecture could lead to better results.
Specifically this:
Do you? Why? This seems like a brute-force solution.
If a user created, renamed, moved or deleted one or more assets that you are interested in, you write an AssetPostprocessor and implement OnPostprocessAllAssets and for each check if this is an asset you are interested in. The most lightweight check comes first of course, such as if itâs not a .cs or .asset extension you skip the rest.
You would then register and unregister the assets you are interested in by using another (ScriptableObject) asset. Only on first use or when running manually (ie âforce refreshâ) would you need to actually go looking through the entire assets tree.
Alternatively, require them to be in a specific folder.
Lastly ⌠provide us with the use case for this script and we may be able to tell you that perhaps Unity already has this or that for exactly that purpose. Thatâs all in the âwhy are you doing thisâ part that you did not mention.
I am writing a dependency injection system that will only run on the editor.
Instead of manually drag-dropping, I will add [Auto] attributes to my scripts and it will try to get data from classes with IService interface.
My goal is to first find all fields with the [Auto] attribute, both in the scene and in the project.
Then find all asset/prefab/scene game objects that have the IService interface. If the IService data and type match, assign this data to the auto field. This is my purpose
How are you going to make that assignment on a SO, on a component in a scene, and a component in a prefab? That seems like the bigger challenge in case you havenât done that part yet.
Also be sure to use TypeCache, donât enumerate AppDomain Assemblies.
I do wonder, say I have this:
[Auto, SerializeReference] private field MySOBase so1;
[Auto, SerializeReference] private field MySOBase so2;
Both are base class references where base class implements IService (bad name btw because itâs extremely generic, same goes for âAutoâ) but I have several subclass implementations and corresponding assets in the project. Which of my SO implementations is this going to find and inject?
Have you researched whether thereâs already a tool like yours?
If so, you could just use that.
If not, perhaps there may be a good reason why there isnât one, because it may just stop short of being useful due to technical limitations. Scan for those âedge casesâ, try to find workable solutions first.