Open svermeulen opened 7 years ago
Hi @svermeulen
So is there any supported method for accessing the run-time container from a ZenjectEditorWindow, or are they completely isolated from one another?
I guess the way to mimic this is to create a MonoBehaviour, inject the instance into it, and write a custom inspector that output this content to the editor. But as I'm still not familiar with the way Unity + Zenject operate/is architected, I wanted to confirm there wasn't a better way before going down that route.
There is a way to access the runtime container from a ZenjectEditorWindow. You could do something like:
ProjectContext.Instance.Container.Resolve<SceneContextRegistry>().GetContainerForScene([Scene you want to look up]);
From there you could list all cached instances that are inside the DiContainer and use reflection to look up the contents of each instance. You could do this iterating over all the providers given by DiContainer.AllProviders
and maybe just checking for type CachedProvider
and then adding a getter property to CachedProvider
to return the cached instances to display. Not sure how to go from there to displaying them in the inspector however.
If you just want to use the inspector for tunables you can do that by using settings objects as described here
I've heard from some people that, after they start using less MonoBehaviours in favour of plain c# classes, that one feature that they miss about MonoBehaviours is the ability to inspect any data on it in the unity inspector. You can even monitor private fields by putting the inspector into debug mode.
A similar functionality might be useful in the form of an editor window that allows you to browse instances within the scene container and see their public and private members