Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - bkinsey

Pages: [1] 2 3
I'm also wondering what a good solution is here. I just wrote my first game using Unity, and while the UI looks good on desktop monitors, on the phone it looks really small and the font is hard to read. A little odd since I set my UIRoot to use the Flexible method and not the Constrained or Constrained on Mobile options. I would think the same pixel dimensions used to draw everything would not look blurry regardless of resolution or dpi. Maybe the UI shaders somehow work really badly for windows phone, but the 3d part of the scene looks otherwise very nice.

Unless you want super large UI on your iPad (or otherwise low DPI devices) it seems like you'd need to have a low DPI UI and a high DPI UI.  My 60x60 pixel buttons are decently sized on my desktop and surface pro tablet, but on the phone its sometimes hard to press because its so small. I also think you'd want to use different fonts depending on the DPI. Wish I knew what more people were doing, I see a lot of great games on the phone with crisp UI, and mine looks tiny and slightly blurry. (Of course I have a medium size phone with a larger resolution, and I developed the game with a 480x800 resolution in mind, although on the desktop)

One thing to try is developing 1 UI for a mid resolution phone, say WXGA (1280 x 720). Then lower resolution phones would have a slightly larger UI and higher resolution phones would have a slightly smaller UI. And lower DPI desktop monitors would have a more larger UI. But only 1 UI to try and work across various DPIs and resolutions...

NGUI 3 Support / Re: How to use Tweens?
« on: December 26, 2014, 12:31:04 AM »
Figured out a solution that works for me. I create a dummy sprite parent object and give it a Tween Alpha component which I use to fade the button in and out. I think having a Button's Tween Color and a Tween Alpha on the same UISprite causes some conflicts and is better avoided.  Still don't know how to use the Play Tween component as intended, but I got the effect I was going for. :D

NGUI 3 Support / How to use Tweens?
« on: December 25, 2014, 03:04:20 AM »
I have 4 separate buttons that I want to fade in and out depending on where my character is standing. As he moves around the world, these buttons might fade in or fade out depending on whether he can enter a building or not.  My implementation without any tweens works as expected, I just set the button's gameobject's active state to true or false, and it appears and disappears as expected. However a fade in/out effect would look more professional here.

I tried making use of the Play Tween component, and Tween Alpha component, but it didn't seem to play the Tween.  Does it make sense for each UISprite to have a Play Tween and Alpha Tween component?  I also tried programmatically adding a Tween Alpha and calling the PlayForward/PlayReverse/ResetToBeginning, but my buttons seem to fade in and out in a manner I can't understand, and also when I mouse over my button, and then mouse away from the button, the button goes invisible. (Maybe the Alpha Tween is setting the UI Button's Color Tween settings, causing it to think the normal state has 0 alpha...)

What's the best way to have buttons with their default/highlight/pressed/disabled tween and also have a tween that can fade in and out the buttons?  Maybe I need a parent widget to do the fading, so it doesn't mess with the UI Button's colors?

Also, does setting a Tween's enabled=true property cause it to play? Or what is the right way to play the tween multiple times, but not looping? (Fade in.. sometime later.. Fade out.. sometime later.. Fade in..) Basically, is the enabled field relevant and when do I want to set it true/false?  Ideally, my buttons will start totally transparent.. is this a tween setting or other setting?

NGUI 3 Support / Resizing Scrollbars for different resolutions
« on: December 18, 2014, 08:27:23 PM »
My game supports multiple resolutions, and for larger resolutions, I generally don't scale the UI, instead I increase Scroll View's, so that they show more content. However I recently added scrollbars, since mouse users are not used to click/dragging scroll views.

I am not able to set the Thumb's Anchor, so even though the slider background will scale correctly, the thumb will not.  The 2 attached screenshots illustrate the problem. In 800x480 resolution, the resolution I usually work in, I set the size of the thumb to look correctly. But when I increase the vertical resolution, as is normal on desktop PCs, the thumb's no longer fill the correct amount of space over the background. What's the solution?

Also, is there a preference between the UISlider and UIProgressBar scripts? I think the documentation is slightly outdated. I'm using the UISlider, I've tried both and didn't seem to make any difference. Is one deprecated, or slider for scrollbars and progress bar for progress bars?

NGUI 3 Support / Best way to implement Button Sound effects?
« on: November 16, 2014, 01:08:17 PM »
I'm slowly getting to that part of my project where I want sound effects.  Starting with UI sound effects seems like a great intro to the area.

There are a couple designs I'm thinking of:
1. Playing a sound when button goes down, and button goes up.
2. Playing a sound when the button clicked event happens, in the handler.

I think design (1) seems more professional.  In this case, wouldn't it make most sense to have the UI Button script to have AudioClip references for Pressed/Normal states?  But you need an AudioSource component in order to play an AudioClip. Wouldn't it be a lot of effort to add an AudioSource, Pressesd/Normal AudioClips, and a script to hook them all together, for every button in your UI?  In this case I'd have to repeat this setup for 50 buttons or so.. seems like there should be a more streamlined solution.

NGUI 3 Support / Re: setting Button.normalSprite doesn't take affect
« on: November 12, 2014, 04:33:18 PM »
So simple, I like it!  Thanks, I will add this in.  I hope you add this in too.. so I get it in future releases.

NGUI 3 Support / Re: setting Button.normalSprite doesn't take affect
« on: November 11, 2014, 02:42:07 PM »
On further investigation it looks like the sprite is not initialized, so setting it does nothing.

I had to force the buttons OnInit to be called, by calling the normalSprite 'get' method:

  1. // This is purely to force NGUI to initialize its internal sprite object.
  2. string x = mGuideVisitorButton.Button.normalSprite;

Can you expose the OnInit method so that I can call it myself, or maybe figure out a more elegant solution? (We'd still want a safeguard preventing init from happening more than once)

NGUI 3 Support / setting Button.normalSprite doesn't take affect
« on: November 11, 2014, 02:36:26 PM »
In my game I have several game objects with UIButton scripts, and they usually start off disabled. (i.e. lots of panels are not shown on game start)

When I set the button's normalSprite member and activate the game object, the new sprite is not drawn. I've also tried activating first and setting the sprite second, but it didn't change the result.  If I deactivate and re-activate the widget's, the correct sprite is now displayed.

Question: When setting a button's normalSprite, do I need to call any method to make the change final?  It looks like there is some kind of caching going on, or some reason when I set the sprite name, it doesn't immediately take effect.  I started noticing this in happening recently, maybe in 3.7.5 and 3.7.6.. my buttons are appearing with their default images, despite me setting them in code to different images.

NGUI 3 Support / Drag and Drop with the "Clone" object
« on: October 02, 2014, 07:41:11 PM »
I'm so glad there is a clone option, that is exactly what I wanted!  However it looks like the cloned GameObject is being destroyed after releasing the DragDropItem!

  1.         protected virtual void OnDragDropRelease (GameObject surface)
  2.         {
  3.                 if (!cloneOnDrag)
  4.                 {
  5.                         ...
  6.                 }
  7.                 else NGUITools.Destroy(gameObject);
  8.         }

Why?!  In my game I have an inventory, just imagine you have a stack of potions represented by 1 DragDropItem widget, and I want to drag just one of these potions onto my belt, for example.

Things I don't know and need help with:

1. The duplicated potion widget is getting destroyed and not sticking to my belt DragDropContainer slot. I would like this duplicate to be re-parented just like the origin would be if I'm not using duplicates.
2. How do I get notified that the DragDropItem has been released?  Does my belt slot need to have a function defined and it will get called whenever an item is dropped on it? I don't see the DragDropContainer having any mechanism allowing me to add a delegate to be called.
3. Does it look like I will have to extend the UIDragDropItem class to implement re-parenting of the clone? And extending UIDragDropContainer so that I can get notified when an item is dropped?  I have very specific slots and need to know when items are dropped on them and when items are removed from them.

Attached a screenshot so it will give you an idea what I'm trying to do.

NGUI 3 Support / Re: Optimizing Draw Calls and Draw Order - Need Info
« on: September 24, 2014, 02:45:55 PM »
What's a dynamic font, and what are my options?

I just use a .ttf or .otf, use your font maker tool, create a prefab and get it added to my atlas, and specify the font in the UILabel font field in the inspector.  Maybe I've been doing it wrong? It does seem like I shouldn't be incurring more draw calls if I'm using a single atlas to draw the entire UI. But I thought maybe a special material was used for rendering the glyphs from the atlas.

I'm trying to follow NGUI 3.6.0 Tutorial 4 to create a drag and drop implementation in my game. However the Grid contents are being re-positioned outside my scroll view bounds.


1. Add a Scroll View as a child of a Sprite
2. Add a Grid as a child of the Scroll View in step 1.
3. Add a Sprite as a child of the Scroll View in step 2.

The Grid has cell width of 60 and cell height of 60. Arrangement is Horizontal, and so is Sorting.  Pivot is left to default TopLeft value. I checked "Smooth Tween" option. (I've tried changing options here, didn't change my outcome at all)

For some reason, the Grid is positioning items far below where I expect them to be. Please see the attached image.

(In case attached image doesn't work, please look at this uploaded screen capture:

Note that I've clicked on one of the sprite widgets in the grid, and its transform is 0/0/0, no rotation or odd scaling, and yet its almost entirely outside the scroll view it's meant to be displayed in. Why is the positioning incorrect? The grid is messing up the position of its children.

NGUI 3 Support / Optimizing Draw Calls and Draw Order - Need Info
« on: September 23, 2014, 10:13:58 PM »
Today I defined my most complex UI, and when I clicked on Stats I saw 14 draw calls.  I've opened up the Draw Call Tool window, and I can see the draw calls are just alternating between the NGUI Atlas material and the NGUI Font material.  Is this because I have Sprites and Label's intertwined in my UI?

Just for more understanding:
- I remember in a video tutorial something being said about draw order. Is it really bad to have 2 widgets using the same draw order?  My "Panel" is full screen, and  have a bunch of sprites that represent sub-panels, I call them windows. For each window I just define their draw order from back to front, starting at 0. So each window will have sprites and label's that share draw orders with other windows.  Will this add draw calls?
- If instead I just uniquely set each draw order from 0 to 57, for example, would this be a better for ngui to draw?

NGUI 3 Support / Re: How to add and use images in fonts? (emoticons)
« on: September 23, 2014, 10:08:10 PM »
Oops, that was a typo. I tried both ":brains" and ":brains:" but it did not work.  I'm guessing the issue might be that the image needs to be a specific size, and I don't know what size it needs to be? I can define a font as size 20, for example, but then the Label properties let me scale that to any value I want, so I'm not sure what size I would need, the UILabel font size, or the font prefab declared size.

I'll take a look at the example and see what I can find.

NGUI 3 Support / How to add and use images in fonts? (emoticons)
« on: September 22, 2014, 12:07:13 PM »
Is it possible to get emoticons to appear just by setting the symbol in a Label's text, using a font with an emoticon set?  Does the emoticon have to be the same size of a font glyph?  I have a ModalDialog widget I created with displays a message, and I'd like the message to contain images.

1. Add a .ttf file to assets location
2. Open Font Maker tab, select .ttf as source.
3. "Create the Font". Save the prefab somewhere.
4. Add an emoticon from the "Symbols and Emoticons" panel in the inspector. (I've tried symbols ":brains:" and ":)". I want to show an icon of brains, its an undead kind of game)
5. myUILabelInstance.text = ":brains";  Or myUILabelInstance.text = ":)";
6. The font the label is using is the same as the font I added the emoticon to.

When I run the game, the dialog does not have any image displayed. What am I doing wrong?

NGUI 3 Support / Atlas Maker crashes
« on: September 19, 2014, 03:30:20 AM »
Just wanted to let you know that the UIAtlasMaker.cs script has crashed on me a couple times.

  1.         Dictionary<string, int> GetSpriteList (List<Texture> textures)
  2.         {
  3.                 Dictionary<string, int> spriteList = new Dictionary<string, int>();
  5.                 // If we have textures to work with, include them as well
  6.                 if (textures.Count > 0)
  7.                 {
  8.                         List<string> texNames = new List<string>();
  9.                         foreach (Texture tex in textures) texNames.Add(;
  10.                         texNames.Sort();
  11. ---->                   foreach (string tex in texNames) spriteList.Add(tex, 2);
  12.                 }

ArgumentException: An element with the same key already exists in the dictionary.
System.Collections.Generic.Dictionary`2[System.String,System.Int32].Add (System.String key, Int32 value) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)
UIAtlasMaker.GetSpriteList (System.Collections.Generic.List`1 textures) (at Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:228)
UIAtlasMaker.OnGUI () (at Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:963)

When the crash occurs I am unable to click on any new tabs in my editor, for example I cannot open my Hierarchy tab.

Opening and closing the Unity Editor fixes the issue, but maybe the code should more gracefully handle this. Not sure what the problem is, I just added a bunch of png files into my asset folder from file explorer, and then clicked on Unity, which attempted to catalog/load the images, and that's when the Atlas Maker crashed.

Pages: [1] 2 3