2

I am trying to extend UnityEngine.UI.Image like that

public class MyImage : Image {
   public string Comment;
}

But I do not see extra text field Comment in inspector. Is it possible to add extra field that would be available in inspector?

PS It triggered as duplicated for Extending Unity UI components with custom Inspector but it is not dupe. I do not ask anything about custom Inspector. It is just regular field with default Inspector. The problem is that field is not appearing in inspector at all.

Community
  • 1
  • 1
Tema
  • 1,338
  • 13
  • 27
  • 2
    Possible duplicate of [Extending Unity UI components with custom Inspector](http://stackoverflow.com/questions/29052183/extending-unity-ui-components-with-custom-inspector) – Fredrik Schön Mar 10 '17 at 12:10

1 Answers1

6

Unfortunately, the Inspector GUI cannot inherit from base class automatically. You need to write that yourself, just like what is described in Extending Unity UI components with custom Inspector.

MyImage.cs

using UnityEngine;
using UnityEngine.UI;

[ExecuteInEditMode]
public class MyImage : Image
{
    public string Comment;
}

MyImageEditor.cs

using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(MyImage))]
public class MyImageEditor : UnityEditor.UI.ImageEditor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();//Draw inspector UI of ImageEditor

        MyImage image = (MyImage)target;
        image.Comment = EditorGUILayout.TextField("Comment", image.Comment);
    }
}

Result: MyImage's Inspector GUI

Community
  • 1
  • 1
zwcloud
  • 4,546
  • 3
  • 40
  • 69