public void Show(Rect rect) { if (windowInstance != null) { windowInstance.Close(); windowInstance = null; } if (dataSource == null) { dataSource = new CallbackDataSource(BuildRoot); } if (gui == null) { gui = new AdvancedDropdownGUI(); } windowInstance = ScriptableObject.CreateInstance <AdvancedDropdownWindow> (); if (minimumSize != Vector2.zero) { windowInstance.minSize = minimumSize; } if (maximumSize != Vector2.zero) { windowInstance.maxSize = maximumSize; } windowInstance.State = state; windowInstance.DataSource = dataSource; windowInstance.Gui = gui; windowInstance.WindowClosed += (w) => ItemSelected(w.GetSelectedItem()); windowInstance.Init(rect); }
public void Init(Rect buttonRect) { Vector2 screenPoint = GUIUtility.GUIToScreenPoint(new Vector2(buttonRect.x, buttonRect.y)); buttonRectScreenPos.x = screenPoint.x; buttonRectScreenPos.y = screenPoint.y; if (state == null) { state = new AdvancedDropdownState(); } if (dataSource == null) { dataSource = new MultiLevelDataSource(); } if (gui == null) { gui = new AdvancedDropdownGUI(); } gui.State = state; 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(); currentlyRenderedTree = HasSearch ? dataSource.SearchTree : dataSource.MainTree; ShowAsDropDown(buttonRect, CalculateWindowSize(buttonRectScreenPos, out requiredDropdownSize)); // If the dropdown is as height as the screen height, give it some margin if (position.height < requiredDropdownSize.y) { Rect pos = position; pos.y += 5; pos.height -= 10; position = pos; } if (SetInitialSelectionPosition) { initialSelectionPosition = gui.GetSelectionHeight(dataSource, buttonRect); } wantsMouseMove = true; SetSelectionFromState(); }