• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jaiyo · Nov 21, 2014 at 08:32 PM · uiinput

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Slev · Nov 21, 2014 at 09:49 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by fafase · Nov 21, 2014 at 09:59 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jaiyo · Nov 22, 2014 at 04:30 AM 0
Share

Good call but I'm going to try the simpler method first by Bored$$anonymous$$ormon first.

avatar image
0

Answer by Kiwasi · Nov 21, 2014 at 10:06 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jaiyo · Nov 22, 2014 at 04:29 AM 0
Share

Sounds very simple yet effective. I'll give it a try!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

GUI for Keyboard controls 0 Answers

How to allow clicking of 2 buttons at once in Android 0 Answers

Capture microphone input 1 Answer

Making GuiButton trigger on ps3 controller input 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges