The following code works exactly as you expect for a Canvas, RectTransform, etc etc but not for an Image.
Is this simply not possible or is there a way to do it? Even if we just want to add fields / labels etc?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEditor;
[CustomEditor(typeof(Image))]
public class ImageEditor : Editor
{
public override void OnInspectorGUI()
{
EditorGUILayout.LabelField("Test", "Check");
}
}
This post hasn’t been replied to yet, so I’d like to second that post.
I am working on an atlas/sprite system so I’m basically overriding the UnityEngine.UI.Image class to had a couple of fields. But the custom editor class refuses to maintain the default Image class inspector layout.
I’m still interested in this, because it doesn’t work when I try to overwrite the default ImageEditor. I don’t want to implement a custom component, I simply want to implement my own editor for the builtin UI.Image, exactly like OP, however it’s not working for Image nor for Button.
The same works fine for RectTransform, CanvasRenderer, MeshRenderer and probably most other components. What is special about Image and Button that I can’t overwrite their editors?
Just starting this hunt as well. Its not that you can’t overwrite them its a case of if the Inspector is exposed for us.
E.G Image has its own custom inspector, it handles things like only showing the fill method if the filled mode is the selected. The problem is, when you make your own it ignores Unity’s one and just exposes raw data.
After looking at rus89’s link I can see its the correct answer and thankfully they are exposed. So instead of extending Editor I now extend UnityEditor.UI.ImageEditor and my inspector is up and running
What Unity and UI package are you using? And do you simply overwrite the builtin Image editor or trying to make an editor for a custom child class of Image? I can’t get it to work to overwrite the builtin Image component editor, it simply ignores my CustomEditor attribute if the type is Image. Most other engine types work.