Multiple method calls for OnInspectorGUIAttribute

Issue #138 resolved
Johannes P. created an issue

Currently, OnInspectorGUIAttribute can be used to run a function before or after an element is drawn, and whether the function is prepended or appended is determined by the value of the append argument.

However, there is no easy way to have functions do both; One Function that runs with append=true as well as another with append=false.

Attempting to use the attribute twice, with append = true and false respectively, yields a Duplicate attribute error:

[OnInspectorGUI("DoBefore", append: false)]
[OnInspectorGUI("DoAfter", append: true)] // not allowed
public int Derp;

private void DoBefore() { Debug.Log("Before"); }
private void DoAfter() { Debug.Log("After"); }

F2yWQ3R.png


I would like to propose an overload for OnInspectorGUI that simply takes two string arguments, the first of which corresponds to append being false, and the second to append being true:

[OnInspectorGUI("DoBefore", "DoAfter")]
public int Derp;

private void DoBefore() { Debug.Log("Before"); }
private void DoAfter() { Debug.Log("After"); }

Alternatively, you could simply enable AllowMultiple with AttributeUsageAttribute for the OnInspectorGUIAttribute, which would enable my initial example, and have the added benefit of allowing an arbitrary number of callbacks with the existing signature.

[OnInspectorGUI("DoBefore1", append: false)]
[OnInspectorGUI("DoBefore2", append: false)]
[OnInspectorGUI("DoAfter1", append: true)]
[OnInspectorGUI("DoAfter2", append: true)]
// etc...
public int Derp;

Comments (3)

  1. Tor Esa Vestergaard

    This proved an easy immediate addition, so we've added an extra constructor to OnInspectorGUI that takes two arguments for prepend and append methods. We'd rather not allow multiple, as .NET has no inherent concept of which order attributes are declared in (we just get them in a basically random order), so ordering of the various OnInspectorGUI attributes would be completely random and impossible to control.

  2. Log in to comment