public static void Draw(string buttonText, Rect windowPos, Func <int, object, bool> popupDrawCallback, GUIStyle buttonStyle, object parameter, params GUILayoutOption[] options) { PopupWindow pw = PopupWindow.GetInstance(); GUIContent content; if (buttonText.Length == 1) { content = new GUIContent(buttonText, "Menu"); } else { content = new GUIContent(buttonText); } var rect = GUILayoutUtility.GetRect(content, buttonStyle, options); if (GUI.Button(rect, content, buttonStyle)) { pw.showPopup = true; var mouse = Input.mousePosition; pw.popupPos = new Rect(mouse.x - 10, Screen.height - mouse.y - 10, 10, 10); pw.callback = popupDrawCallback; pw.parameter = parameter; } }
public static void Draw(string buttonText, Rect windowPos, Func <int, object, bool> popupDrawCallback, GUIStyle buttonStyle, object parameter, params GUILayoutOption[] options) { PopupWindow pw = PopupWindow.GetInstance(); var content = new GUIContent(buttonText); var rect = GUILayoutUtility.GetRect(content, buttonStyle, options); if (GUI.Button(rect, content, buttonStyle)) { pw.showPopup = true; // pw.popupPos = new Rect(windowPos.x + rect.xMin, windowPos.y + rect.yMax + 1, 10, 10); var mouse = Input.mousePosition; pw.popupPos = new Rect(mouse.x - 10, Screen.height - mouse.y - 10, 10, 10); pw.callback = popupDrawCallback; pw.parameter = parameter; } if (Event.current.rawType == EventType.MouseUp) { pw.showPopup = false; } }