public void Show(Rect rect) { if (m_WindowInstance != null) { m_WindowInstance.Close(); m_WindowInstance = null; } if (m_DataSource == null) { m_DataSource = new CallbackDataSource(BuildRoot, BuildCustomSearch); } if (m_Gui == null) { m_Gui = new AdvancedDropdownGUI(); } m_WindowInstance = ScriptableObject.CreateInstance <AdvancedDropdownWindow>(); if (minimumSize != Vector2.zero) { m_WindowInstance.minSize = minimumSize; } if (maximumSize != Vector2.zero) { m_WindowInstance.maxSize = maximumSize; } m_WindowInstance.state = m_State; m_WindowInstance.dataSource = m_DataSource; m_WindowInstance.gui = m_Gui; m_WindowInstance.windowClosed += w => { ItemSelected(w.GetSelectedItem()); }; m_WindowInstance.windowDestroyed += OnDestroy; m_WindowInstance.Init(rect); }
public void Init(Rect buttonRect) { var screenPoint = GUIUtility.GUIToScreenPoint(new Vector2(buttonRect.x, buttonRect.y)); m_ButtonRectScreenPos.x = screenPoint.x; m_ButtonRectScreenPos.y = screenPoint.y; if (m_State == null) { m_State = new AdvancedDropdownState(); } if (m_DataSource == null) { m_DataSource = new MultiLevelDataSource(); } if (m_Gui == null) { m_Gui = new AdvancedDropdownGUI(); } m_Gui.state = m_State; m_Gui.Init(); // Has to be done before calling Show / ShowWithMode screenPoint = GUIUtility.GUIToScreenPoint(new Vector2(buttonRect.x, buttonRect.y)); buttonRect.x = screenPoint.x; buttonRect.y = screenPoint.y; Vector2 requiredDropdownSize; OnDirtyList(); m_CurrentlyRenderedTree = hasSearch ? m_DataSource.searchTree : m_DataSource.mainTree; ShowAsDropDown(buttonRect, CalculateWindowSize(m_ButtonRectScreenPos, out requiredDropdownSize)); // If the dropdown is as height as the screen height, give it some margin if (position.height < requiredDropdownSize.y) { var pos = position; pos.y += 5; pos.height -= 10; position = pos; } if (setInitialSelectionPosition) { m_InitialSelectionPosition = m_Gui.GetSelectionHeight(m_DataSource, buttonRect); } wantsMouseMove = true; SetSelectionFromState(); }