Пример #1
0
    ///
    /// Notification UI Methods
    /// void Display(UINotifications.Notification)
    /// void UpdateUI(UINotifications.Notification)
    ///

    // Display Notification if UI Exists
    public static void Display(UINotifications.Notification notification)
    {
        if (instance != null)
        {
            instance.UpdateUI(notification);
        }
    }
Пример #2
0
 public void DisplayError(string title, string description, string button = "", System.Action action = null)
 {
     UnityEngine.Debug.Log("Display error " + title);
     UINotifications.Notification error_message = new UINotifications.Notification(title, description);
     if (button != "" && action != null)
     {
         error_message.AddButton(button, new UINotifications.ButtonMethod(() => { action(); }));
     }
     error_message.AddButton("Close", new UINotifications.ButtonMethod(() => { UINotifications.Close(); }));
     error_message.AddButton("Exit", new UINotifications.ButtonMethod(() => { Application.Quit(); }));
     UINotifications.Notify(error_message);
 }
Пример #3
0
 void DisplayError(string title, string description, string buttonA = "", Action actionA = null, string buttonB = "", Action actionB = null)
 {
     UnityEngine.Debug.Log("Display error " + title);
     UINotifications.Notification error_message = new UINotifications.Notification(title, description);
     if (buttonA != "" && actionA != null)
     {
         error_message.AddButton(buttonA, new UINotifications.ButtonMethod(() => { actionA(); }));
     }
     if (buttonB != "" && actionB != null)
     {
         error_message.AddButton(buttonB, new UINotifications.ButtonMethod(() => { actionB(); }));
     }
     error_message.AddButton("Exit", new UINotifications.ButtonMethod(() => { Application.Quit(); }));
     UINotifications.Notify(error_message);
 }
Пример #4
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);
    }