- changed title to Multiple method calls for OnInspectorGUIAttribute
Multiple method calls for OnInspectorGUIAttribute
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"); }
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)
-
reporter -
reporter - edited description
-
- changed status to resolved
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.
- Log in to comment