- Home /
CustomEditor show an instance of a Class inside a Class
This is a question for C#
I've been making a custom editor to make my class a bit more neat int he inspector. Its a lot easier to just make a custom one than to do [HideInInspector] on every property. Besides that I need create some tools in the editor for the class to help me with things. The problem I'm having since I've never used custom editor before and all the documentation seems to just be javascript. Even then, I cant seem to find a solution to my issue.
When you put System.Serializable over a class, it makes the instance of that class inside a class appear in the inspector. I need this. However when I make a custom inspector I cant find any way to have the class drawn in. There is a EditorGUILayout field for almost everything, but none for classes. It would be a lot of work making a custom editor for every class within the class, unnecessarily so, Unity draws it on its on in the default inspector. So shouldn't there be a method to draw it again just like for the other fields?
Here is the first legs of the custom editor. Instead of that DrawDefaultInspector, I'd like a way to make theTarget.theclass appear just as it would in the default inspector.
public bool Movement;
public override void OnInspectorGUI()
{
playerFSM theTarget = ((playerFSM)target);
DrawDefaultInspector();
Movement = EditorGUILayout.Foldout(Movement, "Movement Details");
if (Movement)
{
theTarget.speed = EditorGUILayout.FloatField(" Speed", theTarget.speed);
theTarget.jumpSpeed = EditorGUILayout.FloatField(" Jump Speed", theTarget.jumpSpeed);
theTarget.gravity = EditorGUILayout.FloatField(" Gravity", theTarget.gravity);
theTarget.rayLength = EditorGUILayout.FloatField(" Ray Length", theTarget.rayLength);
}
}
If this isn't possible that would be nice to know too, so that I know not to waste my time with it. I'd rather just hide inspector on everything I dont want to show, instead of writing a custom editor for the class inside a class with its arrays and things I need drawn in the inspector. xD