Search Unity

Extending Mesh Renderer Component with a custom Editor

Discussion in 'Scripting' started by fwalker, Aug 10, 2020.

  1. fwalker

    fwalker

    Joined:
    Feb 5, 2013
    Posts:
    255
    I would like to add some fields to what I see in the custom editor of a Mesh Renderer component. So I started by simply doing this:
    Code (CSharp):
    1. [CustomEditor(typeof(MeshRenderer), true)]
    2. public class MeshRendererEditor : Editor
    3.     {
    4.     public override void OnInspectorGUI()
    5.         {
    6.         // Show default inspector property editor
    7.         DrawDefaultInspector();
    8.         }

    I was hoping that would essentially show me the exact view that I had prior to adding the custom editor. This is not the case, what I see is:
    Capture.PNG

    But what I had as default was this:
    Capture2.PNG


    There are obvious formatting changes. With things grouped into collapsable sections. But there are also missing parameters like lightmap Parameters which is empty in the default view.

    I don't really care to recreate the wheel to try to have the same view as the default before a custom editor is provided, is there a way to

    1. Draw the default as it is shown without a custom editor plugged in?
    2. Code that is used by Unity to draw the editor for Mesh Renderer exactly as the default looks?
     
  2. BruceLeo

    BruceLeo

    Joined:
    Mar 9, 2015
    Posts:
    1
  3. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
  4. fwalker

    fwalker

    Joined:
    Feb 5, 2013
    Posts:
    255
  5. CrisW

    CrisW

    Joined:
    Apr 1, 2020
    Posts:
    1
    hi the solution is mix the last two links.


    replacing the function OnEnable with :
    Code (CSharp):
    1.     void OnEnable()
    2.     {
    3.         defaultEditor = CreateEditor(targets, Type.GetType("UnityEditor.MeshRendererEditor, UnityEditor"));
    4.         _TargetMeshRenderer = target as MeshRenderer;
    5.     }