Hi,
I have made a dropdown using 4.6. It works just fine now. However the dropdown doesn’t close when I click somewhere else other than the dropdown. I have not been able to achieve this. I can close the dropdown if the dropdown itself was clicked or a value is selected. Now all I need is to get a click event from any arbitrary object. So whenever the dropdown is open and I click something other than dropdown, I can close the dropdown.
void Update() {
if (Input.GetMouseButtonUp(0) /* && mouse not over dropdown */) {
// close dropdown
}
}
There’s no global “the mouse clicked somewhere” event, so you’ll have to poll every frame like this on your dropdown element.
The harder part is checking if the mouse is currently over your dropdown or anywhere else since as far as I know there’s currently no way to get the UI element that’s below the mouse pointer.
You should be able to check if your dropdown is being hovered using RectTransformUtility.RectangleContainsScreenPoint (if you’re using a “Screen Space - Overlay” canvas I think you can simply pass null for the camera parameter, although the docu doesn’t mention this). If this doesn’t work you could use IPointerEnterHandler/IPointerExitHandler to find out if the mouse is currently hovering your dropdown.