How to create an Alert Box in 4.6 UI?

I’m clear on how I can make a panel with text and buttons to make a type of message box.

What I can’t figure out is how to to restrict input when this message box is visible. With a typical alert box all ui input is disabled except for input directed at the alert box.

What’s a good way to approach this?

Thanks!

The way I’ve been handling popups and inputs is to use tags. So for instance I have a check in one of my input scripts

if (GameObject.FindWithTag("Popup") == null) {
  //allow inputs to be handled
}

Something like that is simple and you can extend it out to handle everything. You could even make the tags more specific.

So for UI buttons you might have to override their OnClick() functions.

You could place your items in an array and iterate to switch them on/off:

private Selectable[] obj;
void Start() 
{
   obj = GetComponentsInChildren<Selectable>();
}

void SwitchInteraction(bool value)
{
    foreach(Selectable s in obj){
       s.interactable = value;
    }
}

Now if you put that on the top object it will also consider your alert items. I would probably create an array to get those and ignore them:

public Selectable [] ignoreList;
private Selectable[] obj;
void Start() 
{
   var o = GetComponentsInChildren<Selectable>();
   List<Selectable> selectList = new List<Selectable>();
   foreach(Selectable s in o)
   {
       if(ignoreList.IndexOf(s) < 0){
           selectList.Add(s);
       }
   }
   alertItems = selectList.ToArray();
}

void SwitchInteraction(bool value)
{
    foreach(Selectable s in obj){
       s.interactable = value;
    }
}

So in ignoreList, you place all the selectable items from your alert box. Start will get all selectable from the canvas and that will include the alert box items. Then you iterate through that collections to see if some are in the ignoreList collection. IndexOf returns -1 if the item is not in so if you get a negative value, it means you selectable is not from the alert list you add it to the temporary list. At the end you turn the temp list to array.

The easiest way to do this is just put a panel behind the alert box that covers the whole screen, this blocking all other input. You can make it white with an intermediate alpha value for a fade type effect. Note this does cost in terms of draw calls.