- Home /
 
How to add a decorator to a custom editor OnInspectorGUI()?
I have a class that has a custom editor with overridden OnInspectorGUI(). I add specific fields in there and draw them as usual in Unity. Though when I'd like to add decorators I scratch my head, how can I do that?
A simple example:
 public class MyCustomAttribute : PropertyAttribute {}
 
 [CustomPropertyDrawer(typeof(MyCustomAttribute))]
 public class MyCustomAttributeDrawer : DecoratorDrawer
 {
     public override void OnGUI(Rect propRect)
     {
         MyCustomAttribute myAttribute = attribute as MyCustomAttribute;
 
         // Do some complex stuff here...
         EditorGUI.LabelField(propRect, "Some text", EditorStyles.boldLabel);
         // Show some complex stuff here...
     }
 }
 
 ...
 public override void OnInspectorGUI()
 {
     EditorGUILayout.LabelField("This is a header", EditorStyles.boldLabel);
     if (GUILayout.Button("Click me!"))
     {
          Debug.Log("Do some fancy stuff...");
     }
     EditorGUILayout.PropertyField(SomeSerializedPropertyEvenWithDecorators, true);
     // <------  What to put here if I want to show a MyCustomAttribute?
     // ...further custom stuff for my inspector...
 }
 ...
 
               Until I would put a simple header, I can simply add an EditorGUILayout.LabelField(), but when I have several other decorators defined, of course, I don't want to reiterate all the code to draw them. So how can I instantiate a decorator "field" to draw it on the inspector? Thank you.
               Comment
              
 
               
              Your answer