public void GUIDropDownDisplay(params GUILayoutOption[] guiOptions) { FARGUIDropDownDisplay display = FARGUIDropDownDisplay.Instance; toggleBtnState = GUILayout.Toggle(toggleBtnState, "▼ " + stringOptions[selectedOption] + " ▼", GUIDropDownStyles.ToggleButton, guiOptions); // Calculate absolute regions for the button and dropdown list, this only works when // Event.current.type == EventType.Repaint Vector2 relativePos = GUIUtility.GUIToScreenPoint(new Vector2(0, 0)); Rect btnRect = GUILayoutUtility.GetLastRect(); btnRect.x += relativePos.x; btnRect.y += relativePos.y; var dropdownRect = new Rect(btnRect.x, btnRect.y + btnRect.height, btnRect.width, 150); switch (isActive) { // User activated the dropdown case false when toggleBtnState && Event.current.type == EventType.Repaint: ShowList(btnRect, dropdownRect); break; // User deactivated the dropdown or moved the mouse cursor away case true when(!toggleBtnState || !display.ContainsMouse()): HideList(); break; } }
public void GUIDropDownDisplay(params GUILayoutOption[] guiOptions) { InitStyles(); FARGUIDropDownDisplay display = FARGUIDropDownDisplay.Instance; toggleBtnState = GUILayout.Toggle(toggleBtnState, stringOptions[selectedOption], toggleBtnStyle, guiOptions); // Calcuate absolute regions for the button and dropdown list, this only works when // Event.current.type == EventType.Repaint Vector2 relativePos = GUIUtility.GUIToScreenPoint(new Vector2(0, 0)); Rect btnRect = GUILayoutUtility.GetLastRect(); btnRect.x += relativePos.x; btnRect.y += relativePos.y; Rect dropdownRect = new Rect(btnRect.x, btnRect.y + btnRect.height, btnRect.width, 150); if (!isActive && toggleBtnState && Event.current.type == EventType.Repaint) { // User activated the dropdown ShowList(btnRect, dropdownRect); } else if (isActive && (!toggleBtnState || !display.ContainsMouse())) { // User deactivated the downdown or moved the mouse cursor away HideList(); } }