0
\$\begingroup\$

So far, this is the only resource I've found that does what I'm looking to do (which is to center-align my inspector headers): CreatureSurvive's example script on GitHub Gist

If I'm understanding properly, the center alignment is achieved either through the depth field,

/// <param name="depth">the depth of this header element in the inspector foldout</param>

or through what appear to be style fields, like padding, margin, etc.,

// draw header background and label
var headerRect = new Rect(pos.x + margin, pos.y + spacing, 
                         (pos.width - margin) + (padding * 2), 
                          pos.height - (spacing + barHeight + spacing));
EditorGUI.DrawRect(headerRect, Constants.BackgroundColor);

This appears to be an example result using the linked script:

a fancy example of center-aligned headers in a custom inspector

More to the point, ignoring some of the fancier adjustments to the editor in the image above:

  1. Is it necessary to write a custom script in this manner to be able to adjust the alignments of HeaderAttributes?
  2. Are there any functions of something like EditorGUILayout that could handle the alignment of attributes (instead of having to write a script that does the same thing)?
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$
  1. The [Header] attribute is intended to be a simple, utilitarian solution for headers. It does not support any advanced formatting such as adjusting the alignment of the header. If you want a more customizable header, you would need an Attribute class and PropertyDrawer, as in the example you linked to.

  2. Layout functions can be used inside a custom PropertyDrawer or Editor. They can't be used to adjust the layout of existing attributes like [Header]

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .