Using the code below I lose all the functionality of the current Unity Custom Editor on their RectTransform. How do I keep their exact RectTransform while also adding my own stuff underneath it? I tried Editor.CreateEditor stuff and I kept getting infinite loop crashing when I tried to create Editor based on the RectTransform.
using UnityEditor;
using UnityEngine;
using System.Collections;
[CustomEditor(typeof(RectTransform))]
public class RectTransformEditor : Editor {
public override void OnInspectorGUI () {
DrawDefaultInspector ();
}
}
You need to inherit RectTransformEditor and call base OnInspectorGUI function. Since RectTransformEditor is internal class you need System.Reflection to get editor type, then instantiate it.
using UnityEngine;
using UnityEditor;
using System.Reflection;
using System;
[CustomEditor(typeof(RectTransform), true)]
public class RectTransformEditor : Editor
{
private Editor _editorInstance;
private void OnEnable()
{
Assembly ass = Assembly.GetAssembly(typeof(UnityEditor.Editor));
Type rtEditor = ass.GetType("UnityEditor.RectTransformEditor");
_editorInstance = CreateEditor(target, rtEditor);
}
public override void OnInspectorGUI()
{
_editorInstance.OnInspectorGUI();
// ...
}
}
Hey. You need to destroy created editor. It’s mentioned in documentation.
In my case I had to call it from OnDisable and OnDestroy from my custom editor script.