Hey folks. Experimenting with custom editors at the moment, and it would be handy to have a few GUIStyle s exposed at the start of the editor, which I can reference throughout. That way I can customise the visuals of my editor visually and interactively as I lay it out.
My MonoBehavior script has,
[SerializeField]
public GUIStyle butStyle01 = new GUIStyle();
and in my Editor script, I’m trying to reference it as,
SerializedProperty butStyle01;
private void OnEnable()
{
butStyle01 = serializedObject.FindProperty("butStyle01");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
base.OnInspectorGUI();
GUIStyle gah = butStyle01.objectReferenceValue as GUIStyle;
GUILayout.Button("Woop!", gah);
I have no trouble getting the GUIStyle showing up in the Editor either as base.OnInspectorGUI or as a serialised property. However, I’m running into issues with the last lines - I can’t get access to the actual GUIStyle from the SerialisedProperty and/or I can’t seem to cast it as GUIStyle for use by the button on the last line.
Any clues, folks?