- Home /
Question by
arhovid · Dec 04, 2020 at 06:52 AM ·
eventsystemselectionevent triggeringdeselect
EventSystem child element selection/deselection and click
I have a custom-created UI illustrated dropdown with hierarchy like this:
Also, I have a event triggers on main dropdown panel itself (one with "Placeholder"), on open button, and on dropdown content elements.
Event trigger on main dropdown element calls a method, that set visibility of a content panel to "True", and also hide it, if dropdown was deselected.
public void SetContentVisibility(bool v)
{
_content.gameObject.SetActive(v);
}
public void OnDeselect(BaseEventData eventData)
{
_content.gameObject.SetActive(false);
}
When I'm try to click on one of elements, click on element's trigger can't be registered, because panel immediately hides after deselect of main dropdown element inside event system.
So, how can I prevent behaviour like this? I have a kind of solution, but I think it's a bad idea to do things this way:
public void OnDeselect(BaseEventData eventData)
{
StartCoroutine(ReactOnDeselect());
}
private IEnumerator ReactOnDeselect()
{
yield return new WaitForSeconds(0.25f);
SetContentVisibility(false);
}
dropdwon.png
(43.4 kB)
Comment