Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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.

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

Changing Scene When Button Tapped 7 Answers

Unit button and axis mapping issue 0 Answers

GUI for Keyboard controls 0 Answers

How can I get user-defined inputs? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges