UIPopup Manager

Code examples to perform various interactions with the UIPopup Manager

Add To Queue

If you need to show multiple UIPopups and you would like not to show them all at once, you can add them to a Popup Queue that is managed by the UIPopupManager. This system shows UIPopups one after the other, in the order they have been added.

Add the passed UIPopup to the PopupQueue

Simple implementation (one line of code)

using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public string MyPopupName; //popup name as defined in the Popups Database
    
    private void Start()
    {
        
        UIPopupManager.AddToQueue(UIPopup.GetPopup(MyPopupName));
    }
}

Simple implementation with a reference to the UIPopup

using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public string MyPopupName; //popup name as defined in the Popups Database

    private void Start()
    {
        //Get an UIPopup
        //This instantiates a clone of the UIPopup prefab referenced, in the Popups Database, for the passed popup name
        UIPopup popup = UIPopup.GetPopup(MyPopupName);

        //Add the UIPopup (instantiated clone) to the Popup Queue
        //And let the UIPopupManager decide when to show it
        UIPopupManager.AddToQueue(popup);
    }
}

Complex implementation with a reference to the UIPopup.
In this example we assume we have an UIPopup with 1 Image reference (used as an icon) and we set its Sprite.
We also assume we have 2 Text or TextMeshPro references (used as labels) and we set the text values.
We also assume we have 2 UIButtons with labels and we set their label texts, their UIButton button name and their Callbacks.

using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public string MyPopupName; //popup name as defined in the Popups Database

    //reference to a Sprite used as a custom icon for the UIPopup
    //for this example we assume we have 1 Image reference and we set a custom Sprite)
    public Sprite MyIcon;

    //custom labels (text values)
    //for this example we assume we have 2 Text or TextMeshPro references and we set 2 custom labels
    public string MyFirstLabel;
    public string MySecondLabel;

    //custom button labels (text value visible on the buttons)
    //for this example we assume we have 2 UIButtons (that also have labels)
    public string MyButtonOneLabel = "Yes";
    public string MyButtonTwoLabel = "No";

    //custom button names (UIButton button name for the buttons)
    //for this example we assume we have 2 UIButtons (and we give them the 'Ok' and 'Cancel' button names)
    public string ButtonNameOk = "Ok";
    public string ButtonNameCancel = "Cancel";


    private void Start()
    {
        //Get an UIPopup
        //This instantiates a clone of the UIPopup prefab referenced, in the Popups Database, for the passed popup name
        UIPopup popup = UIPopup.GetPopup(MyPopupName);

        //SETUP YOUR POPUP
        {
            //Set a custom icon (if your UIPopup has an Image referenced)
            popup.Data.SetImagesSprites(MyIcon);

            //Set labels (if you have 2 Text or TextMeshProUGUI referenced)
            popup.Data.SetLabelsTexts(MyFirstLabel, MySecondLabel);

            //Set button labels (text visible on the buttons)
            popup.Data.SetButtonsLabels(MyButtonOneLabel, MyButtonTwoLabel);

            //Set button names (actual UIButton button name)
            popup.Data.SetButtonsNames(ButtonNameOk, ButtonNameCancel);

            //Set Callbacks for each button
            popup.Data.SetButtonsCallbacks
                (
                 () =>
                 {
                     //Callback for the 'Ok' button (button 1)
                     //When Button 1 is clicked do stuff...                     
                 },
                 () =>
                 {
                     //Callback for the 'Cancel' button (button 2)
                     //When Button 2 is clicked do stuff...            
                 }
                );
        }


        //Add the UIPopup (instantiated clone) to the Popup Queue
        //And let the UIPopupManager decide when to show it
        UIPopupManager.AddToQueue(popup);
    }
}

Clear Queue

Hide the CurrentVisibleQueuePopup (if visible) and clear the PopupQueue

using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    private void Start()
    {
        UIPopupManager.ClearQueue();
    }
}

Clear Queue – instantly (without animation)

Hide the CurrentVisibleQueuePopup (if visible) and clear the PopupQueue

using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    private void Start()
    {
        UIPopupManager.ClearQueue(true);
    }
}

Get Popup

Look in the UIPopupManager PopupsDatabase for an UIPopup prefab linked to the given popup name.
If found, it instantiates a clone of it and returns a reference to it. Otherwise it returns null.

using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public string MyPopupName;
    
    private void Start()
    {
        UIPopup popup = UIPopupManager.GetPopup(MyPopupName);
    }
}

Is In Queue

Determine if at least one UIPopup with the given popup name is found in the PopupQueue

using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public string MyPopupName;
    
    private void Start()
    {
        bool isPopupInQueue = UIPopupManager.IsInQueue(MyPopupName);
    }
}
using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public UIPopup MyPopup;
    
    private void Start()
    {
        bool isPopupInQueue = UIPopupManager.IsInQueue(MyPopup);
    }
}

Remove From Queue

Removes the first UIPopup registered with the given popupName from the PopupQueue (if it exists)
By default, after removing the corresponding UIPopup from the PopupQueue, the next popup in queue will be shown.

using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public UIPopup MyPopup;
    
    private void Start()
    {
        UIPopupManager.RemoveFromQueue(MyPopup);
    }
}

Show Next In Queue

Show the next UIPopup in the PopupQueue (if any)

using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    private void Start()
    {
        UIPopupManager.ShowNextInQueue();
    }
}

Show Popup

Show the given UIPopup with the given settings

using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    //Target popup that needs to be shown
    public UIPopup MyPopup;

    // If the popup is added to the PopupQueue, it will be shown when its turn comes up. Until then it will remain hidden.
    public bool AddToPopupQueue;

    //When shown, should the popup animate instantly? (in zero seconds)
    public bool InstantAction;

    // Sets a new UICanvas target by looking for an UICanvas with the given name (also re-parents the popup to it)
    public string TargetCanvasName;

    private void Start()
    {
        UIPopupManager.ShowPopup(MyPopup, AddToPopupQueue, InstantAction, TargetCanvasName);
    }
}
using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    //Target popup that needs to be shown
    public UIPopup MyPopup;

    // If the popup is added to the PopupQueue, it will be shown when its turn comes up. Until then it will remain hidden.
    public bool AddToPopupQueue;

    //When shown, should the popup animate instantly? (in zero seconds)
    public bool InstantAction;

    private void Start()
    {
        UIPopupManager.ShowPopup(MyPopup, AddToPopupQueue, InstantAction);
    }
}
using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    //The popup name to search for in the PopupDatabase linked to a UIPopup prefab.
    //If the prefab is found, a clone of it will get instantiated and then shown
    public string MyPopupName;

    // If the popup is added to the PopupQueue, it will be shown when its turn comes up. Until then it will remain hidden.
    public bool AddToPopupQueue;

    //When shown, should the popup animate instantly? (in zero seconds)
    public bool InstantAction;

    // Sets a new UICanvas target by looking for an UICanvas with the given name (also re-parents the popup to it)
    public string TargetCanvasName;

    private void Start()
    {
        UIPopupManager.ShowPopup(MyPopupName, AddToPopupQueue, InstantAction, TargetCanvasName);
    }
}
using Doozy.Engine.UI;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    //The popup name to search for in the PopupDatabase linked to a UIPopup prefab.
    //If the prefab is found, a clone of it will get instantiated and then shown
    public string MyPopupName;

    // If the popup is added to the PopupQueue, it will be shown when its turn comes up. Until then it will remain hidden.
    public bool AddToPopupQueue;

    //When shown, should the popup animate instantly? (in zero seconds)
    public bool InstantAction;

    private void Start()
    {
        UIPopupManager.ShowPopup(MyPopupName, AddToPopupQueue, InstantAction);
    }
}