How do I get the default inspector for a CustomEditor for RectTransform?
Below is how my RectTransform inspector looks before including the editor script:
After I add the following script:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(RectTransform))]
public class MyRectTransformEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
if (GUI.changed)
Debug.Log("test");
}
}
I get this:
The console does output "test" when the values are changed after the script is added to the project.
What I'm trying to accomplish is changing the behaviour of RectTransforms (specific gameobjects) to go by tile index instead so that I can lock the width/height to an interval of whatever the tile width/height is. However, I don't want to sacrifice the way RectTransform works currently. How can I accomplish this?
I have the same problem. Does somebody know the answer?
Notice that the first editor is actually already a custom editor. So it makes sense that the default inspector looks different. I don't know a fix for sure but you could try to find the editor script for the rect and modify it. Or use the EditorGUI.propertyfield to draw the whole rect class in one go. I'm not sure about these so that's why the comment :) good luck
You are right, I got the same conclusion. $$anonymous$$aybe if I could extend this custom editor it could be done, but I don't know what class does it. I searched in the list of classes in unity.engine and unity,editor.
For now, the solution is: create a new component base and create the new custom editor. Thanks for replying.
3 years later, same problem. Did you finally found the RectTransformEditor class ? Edit: found the solution here : https://forum.unity.com/threads/recttransform-custom-editor-ontop-of-unity-recttransform-custom-editor.455925/
Answer by UDN_52bf9f4d-2d40-4386-bad9-b8048056a414 · Dec 24, 2016 at 11:48 PM
For any one looking for the aswer, you can use "Editor.CreatEditor(object)". Where object is the object(s) you want to display.
https://docs.unity3d.com/ScriptReference/Editor.CreateEditor.html
Answer by RudyTheDev · Aug 25, 2018 at 01:18 PM
CreateEditor(targets, typeof(Editor).Assembly.GetType("UnityEditor.RectTransformEditor")).OnInspectorGUI();
will draw the Unity's editor for RectTransform
s.
Disclaimer: this is an internal
class and if Unity changes stuff, your code will break.
Your answer
![](https://koobas.hobune.stream/wayback/20220612040047im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Convert global or local position to anchorPosition for a RectTransform? 0 Answers
MoveTowards and Lerp not working on RectTransform? 1 Answer
EditorGUILayout.BeginVertical("Box") not filling the inspector 0 Answers
How to make a health bar with multiple fields along the same bar? , 0 Answers
Help with Time Crisis crosshair 0 Answers