Hi, I saw your approach to Unity 6.3 new toolbar
And I just wanted to share my reflection-based alternative
Reflection-based factory
public static class MainToolbarElementFactory
{
private static readonly ConstructorInfo CTOR;
static MainToolbarElementFactory()
{
var type = Type.GetType("UnityEditor.Toolbars.MainToolbarCustom, UnityEditor");
CTOR = type?.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, new[] { typeof(Func<VisualElement>) }, null);
}
public static MainToolbarElement Create(Func<VisualElement> createElement)
{
return CTOR == null ? null : CTOR.Invoke(new object[] { createElement }) as MainToolbarElement;
}
}
Example of use
[MainToolbarElement("SampleButton", defaultDockPosition = MainToolbarDockPosition.Right)]
public static MainToolbarElement CreateSampleButton()
{
return MainToolbarElementFactory.Create(() =>
{
var button = new Button(() => Debug.Log("Test"));
return button;
});
}
I don't really like the approach of creating an empty slate and then populating it, but that's just me.
Hi, I saw your approach to Unity 6.3 new toolbar
And I just wanted to share my reflection-based alternative
Reflection-based factory
Example of use
I don't really like the approach of creating an empty slate and then populating it, but that's just me.