UnityDynamicPanels
UnityDynamicPanels copied to clipboard
Notification delegates for individual Panels and Tabs
OnPanelClosed and OnTabClosed works globally for all panels/tabs. I would love to be able to define different delegate methods for different tabs. This way I could specify individual behavior on close or even make some tabs closeable and others not. Sadly I'm not experienced with C# delegates so I'm having a hard time thinking of a workaround that works for me.
Thanks for this great Plugin!
Thank you for the feature request! I probably won't be able to add this feature in the near future, though.
Thanks for the response!
Here is my current workaround - I had to make changes to the source of the plugin which could break the existing functionality:
PanelTab - Add a new Method:
public void AddCloseButtonListener( UnityAction call )
{
closeButton.onClick.AddListener( call );
Internal.ChangeCloseButtonVisibility( true );
}
PanelNotificationCenter#TabIDChanged Disable the call to ChangeCloseButtonVisibility so it won't hide the close button again
An example listener that simply destroys the tab if the Button is Clicked:
panelTab.AddCloseButtonListener( () =>
{
panelTab.Destroy();
});
For Panels the changes should be very similar
Obviously, this solution is quite flawed but it is a simple workaround that will do the trick for me :)
Looks neat! What are its known flaws?
I think it is quite "hacky" because it does not use the PanelNotificationCenter which was originally intended for this purpose. An the behavior becomes unpredictable if used together with the PanelNotificationCenter.OnTabClosed. For example if you happen to use both at some point:
PanelNotificationCenter.OnTabClosed += ( PanelTab tab ) => {
tab.Destroy();
};
panelTab = PanelUtils.CreatePanelFor( scriptEditor, canvas ).GetTab( scriptEditor );
panelTab.AddCloseButtonListener( () =>
{
scriptEditor.GetComponentInChildren<TMP_InputField>().SetTextWithoutNotify( "You can't close yet!" );
} );
The tab will always be closed and the text won't ever show. But the same unpredictability can happen if you register multiple Delegates so maybe this is simply the responsibility of the developer.