Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: Excal on May 04, 2014, 05:57:55 PM
-
I've gone through most of the video tutorials and they are great for creating things within the editor, but I'm wondering how to create pop-up dialog boxes via script. I did a few google searches and couldn't find any script examples. If anyone has one, please share :)
-
You could just create a popup dialog prefab and instantiate it whenever you need it.
Or you could have a reference to a popup window and use that one for all of your popups and modify is when you want to call it.
It mostly depends on what you want to do with the popup and how you want to use it.
-
I'm still new to NGUI, but that seems like a great idea. I think the issue is that my dialog boxes will be different sizes. I'm currently creating them using Unity's default GUI system that uses OnGUI and specifies actual pixel sizes and positions. I heard NGUI is resolution independent and that's why I want to switch to it. I've been having trouble figuring out how to dynamically create dialogs.
Would the solution be to create a dialog box prefab for each dialog I want, and then just instantiate it at the right time, or is there a better way?
-
You could easily create a dynamic dialog box by having a script attached that will set the text for it and then use UIStretch on the background to match the text/sprite size for the popup.
So you will set the text, the text width/dimensions will be defined by you in the UILabel of the prefab and then UIStretch will be called on the background so it matches nicely.
-
Alright, bear with me here, I'm still wrapping my head around this. I have an image in photoshop of what I want my button to look like: (http://i.imgur.com/2dfAsJy.png)
Wooden Atlas has a set number of sprites and I'm not quite sure how to get mine to be an option. Do you know how I might be able to set this as my button background? Should I ignore the button prefab and just drag this into the scene and attach a button script to it?
-
You should put the textures for your UI inside an Atlas. (Watch the NGUI video on this if you need more info)
Your Prefab should look something like this:
-DialogWindow <--- Prefab GameObject with a script on it that has a reference to the sprite and label
- Sprite <--Button Background
- Label <--Text for the button
You would instantiate the DialogWindow and call the script attached to set the popup. Also you should use anchoring to set the default positioning of your text on the sprite.
-
Which NGUI video? The 3.0.7 video doesn't cover creating an atlas.
-
Go to NGUI in the toolbar.
NGUI -> Open -> Atlas Maker
Pretty much follow the instructions that it gives you to create a new Atlas.
-
Is using a texture background is just as fine as using a sprite background?
Also, is there any particular script I should attach to the gameObject that contains my NGUI dialog box?
(http://i.imgur.com/ibfGxux.png)
-
Using a texture background would result in an extra drawcall, meanwhile using a sprite from your Atlas will save drawcalls.
You will need to make a custom script that has a reference to the Label and Sprite and then configure those two how you would want it.
I would just recommend having everything that you would want to set inside of a constructor, very similarly to Message Boxes in VB/C#.
-
Thanks, LightSky. But as a note, don't use UIStretch. The new layout system handles it better.
Also, one of NGUI's tutorials shows how you can easily auto-resize a widget based on the label's content. So you could easily have resizeable dialog boxes using the layout system.
-
Which one? Every time someone mentions NGUI tutorial there's like 20 of them.
-
The ones that come with NGUI. There are 7 of them I think? I re-did all tutorial scenes a couple of weeks ago.