Skip to content

Instantly share code, notes, and snippets.

@JohannesMP
Created February 26, 2017 02:38
Show Gist options
  • Save JohannesMP/baca0bf4b68a4ec9ce5dcdb6a51cf08f to your computer and use it in GitHub Desktop.
Save JohannesMP/baca0bf4b68a4ec9ce5dcdb6a51cf08f to your computer and use it in GitHub Desktop.
#if UNITY_EDITOR
[CanEditMultipleObjects]
[CustomEditor(typeof(BaseClass), true)]
public class BaseClassEditor : Editor
{
public override void OnInspectorGUI()
{
var t_baseTarget = typeof(BaseClass);
var t_baseEditor = typeof(BaseClassEditor);
// Always draw script reference of child first
CustomInspectorScripts.DrawScriptReference(this);
// Draw Inspector for base
GUILayout.BeginVertical(EditorStyles.helpBox);
this.DrawDefaultInspector(t_baseTarget);
/*
CUSTOM EDITOR STUFF HERE FOR BASE CLASS
*/
GUILayout.EndVertical();
// If we we are being used on a child of baseclass without a custom inspector
if (this.GetType() == t_baseEditor)
{
System.Type t_type = target.GetType();
var target_types = new List<System.Type>();
while (t_type != t_baseTarget)
{
target_types.Add(t_type);
t_type = t_type.BaseType;
}
target_types.Reverse();
foreach (var type in target_types)
this.DrawDefaultInspector(type, false);
}
}
}
#endif
#if UNITY_EDITOR
[CustomEditor(typeof(ChildClass), true)]
public class ChildClassEditor : Button_AEditor
{
public override void OnInspectorGUI()
{
var t_childTarget = typeof(ChildClass);
base.OnInspectorGUI();
this.DrawDefaultInspector(t_childTarget);
/*
CUSTOM EDITOR STUFF HERE FOR CHILDCLASS
*/
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment