Пример #1
0
    // Update Notification UI based on Notification object
    private void UpdateUI(UINotifications.Notification notification)
    {
        // Update Notification Text
        title.text       = notification.title;
        description.text = notification.description;

        // Select right button layout UI based on number of buttons
        int        button_count  = notification.GetButtonCount();
        GameObject button_layout = obj_button_layouts[button_count - 1];

        // Turn off all button layouts
        for (int i = 0; i < obj_button_layouts.Length; i++)
        {
            obj_button_layouts[i].SetActive(false);
        }

        // Turn on right button layout
        obj_button_layouts[button_count - 1].SetActive(true);

        // Set up each button
        for (int i = 0; i < button_count; i++)
        {
            // Get this button
            GameObject obj_button = button_layout.transform.GetChild(i).gameObject;
            Button     button     = obj_button.GetComponent <Button>();

            // Attach this button method for onclick functionality
            int index = i;
            button.onClick.AddListener(delegate { notification.GetButtonMethod(index)(); });
            button.onClick.AddListener(() => { Close(); });

            // Update this button label
            GameObject obj_text = obj_button.transform.GetChild(0).gameObject;
            Text       text     = obj_text.GetComponent <Text>();
            text.text = notification.GetButtonName(i);
        }

        // Display UI Canvas
        canvas.SetActive(true);
    }