Detect UI DropDown Open/Close events
Working in Javascript, I'm trying to detect when the dropdown is open or close (i.e. when the option list is presented). I suspect that the OnPointerClick event has something to do with this but am having trouble coming up with a reliable solution.
I realize that working with C# is preferred but this is legacy code I'm modifying so a Javascript solution is preferable.
Thanks, Manny
I'm trying to prevent a touch on a dropdown list/scroll from affecting the stuff behind it -- so I need to disable touch events on other things when the dropdown list is opened and reenable it when the list closes. Any suggestions on how this can be done?
Answer by HgM3rK · Jan 29, 2017 at 08:00 PM
Adding to Gearme's Answer. I used the childCount thinking it would be Better than FindGameObject since I had to use this inside an Update Function to prevent finger sliding from moving the camera.
public Transform DropDownShips;
if (DropDownShips.childCount != 3)
{
return;
}
Count is 4 when its open, and 3 when closed.
There has to be a way to get the click event but I dont know how
Answer by Gearme · Oct 03, 2016 at 07:45 PM
I'm guessing this is way too late for you - but for posterity's sake: Lets call the GameObject holding the Dropdown-Component "DropdownObject". Whenever the dropdown menu is opened, Unity creates a new GameObject called "Dropdown List" as a child of DropdownObject's transform. One could therefore query the state of the dropdown by trying to find it, i.e. by using the FindChild(string name) function of DropdownObject's transform. The function will return the GameObject if the Dropdown is open and null if it is not.
Answer by ZeroSumGames · Apr 15, 2017 at 07:42 PM
Hey old thread but you can add an Event Trigger to the Dropdown component to detect pointer events
Your answer
Follow this Question
Related Questions
Reuseable Dropdown 0 Answers
Content Size Fitters wont work DropDown Menus? 0 Answers
How do you access the text value of the Dropdown UI? 6 Answers
How to change the Font Asset from a Dropdown List item? 1 Answer
UI Dropdown problem. 1 Answer