Search Unity

Draw default inspector with all scene gui & handles

Discussion in 'Scripting' started by silentslack, Mar 22, 2021.

  1. silentslack

    silentslack

    Joined:
    Apr 5, 2013
    Posts:
    395
    Hi,

    I would like to "embed" the native inspector for components inside my own Inspector. I currently have this code which gets me some of the way there:

    Code (CSharp):
    1. [CustomEditor(typeof(PE_ComponentWrapper), true)]
    2. public class PE_ComponentWrapperInspector : Editor
    3. {
    4.     private PE_ComponentWrapper _ComponentWrapper;
    5.     private Editor _CompEditor;
    6.  
    7.     protected virtual void OnEnable()
    8.     {
    9.         _ComponentWrapper = (PE_ComponentWrapper)target;
    10.         _CompEditor = Editor.CreateEditor(_ComponentWrapper.Component);
    11.     }
    12.  
    13.     private void OnSceneGUI()
    14.     {
    15.         if (_CompEditor != null)
    16.         {
    17.             Editor editor = Editor.CreateEditor(_ComponentWrapper.Component);
    18.             MethodInfo onSceneGUIMethod = editor.GetType().GetMethod("OnSceneGUI", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { }, null);
    19.             if (onSceneGUIMethod != null)
    20.             {
    21.                 onSceneGUIMethod.Invoke(editor, null);
    22.             }
    23.         }
    24.     }
    25.  
    26.     public override void OnInspectorGUI()
    27.     {
    28.         if (_CompEditor != null)
    29.             _CompEditor.OnInspectorGUI();
    30.     }
    31. }
    This issue is this seems to only draw around half the scene gui handles/shapes. For the Box Colliders for instance we don't see the standard green shape outline. It may be due to not calling OnSceneGUI() for every base type but I can't seem to find a way to do that - and unsure if that is the issue.

    Any help on this one really appreciated!

    Thanks, Jake