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;
        }
示例#2
0
 // Use this for initialization
 void Start()
 {
     menu = GetComponent <FloatingMenu>();
 }
    private bool activated;                                                     // Is the menu active

    void Awake()
    {
        Instance = this;
    }