private void Awake() { if (_canvas == null) { Debug.LogError("Canvas is null"); return; } if (_buttonPrefab == null) { Debug.LogError("Button prefab is null."); return; } // Create and build the menu GameObject menuObject = new GameObject("DropDownMenu", typeof(RectTransform)); menuObject.transform.SetParent(_canvas.transform); _dropDownMenu = menuObject.AddComponent <FloatingMenu>(); _dropDownMenu.SetButtonPrefab(_buttonPrefab); // Add the buttons for (int i = 0; i < System.Enum.GetValues(typeof(Buttons)).Length; i++) { _dropDownMenu.AddButton(((Buttons)i).ToString(), i); } // Subscribe to the callbacks _dropDownMenu.OnMenuButtonClick += HandleButtonClick; // Hide the menu _dropDownMenu.Hide(); _resultText.text = string.Empty; }
protected void Update() { // Shift + Left Click to show at mouse position if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { if (Input.GetMouseButtonDown(0)) { _dropDownMenu.Show(Input.mousePosition); } } // Right click to hide if (Input.GetMouseButtonDown(1)) { _dropDownMenu.Hide(); } }