How to get a class inheriting from MonoBehaviour to show variables in the inspector of another class?

I have a LevelSystem Class that inherits from MonoBehaviour to use coroutines, which is a variable in the Stats class. At the moment, LevelSystem appears in the Stats inspector similar to a GameObject field, rather than showing the individual variables in LevelSystem.

122026-capture.png

Removing LevelSystem’s inheritance from MonoBehaviour would fix this:

122027-capture-2.png

However I would have to move the coroutine it contains to the Stats class- it’s something that I could do, but would mean making copies of this coroutine for every class with a LevelSystem variable, which isn’t particularly desirable. Is there a way to make the default inspector for LevelSystem (while it inherits from MonoBehaviour) appear in the Stats class inspector?

It is possible… though it’s not trivial:
s
You will need to delve a bit into editor scripting:
You will need to create a Custom Editor for your Stats-class, within this editor you will need to Create an instance of the editor of the LevelSystem.
similar to what is done here: Unity - Scripting API: Editor.OnPreviewGUI
but targeted on your LevelSystem Component:

Editor levelSystemEditor = CreateEditor(((Stats)target).levelSystem);

After doing so you can draw the levelsystem’s editor by calling

levelSystemEditor.OnInspectorGUI();

somewhere in the StatsEditor’s OnInspectorGUI()-call.


here’s some more information on the topic:
https://forum.unity.com/threads/custompropertydrawer-and-monobehaviours.448060/