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.


Topics - bkinsey

Pages: [1]
1
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?

2
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?

3
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.

4
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.

5
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.         }
  9.  

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.

6
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.

Steps:

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: https://onedrive.live.com/redir?resid=931785C27FCC921F%2184531)

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.

7
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?

8
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.

Steps:
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?

9
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>();
  4.  
  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(tex.name);
  10.                         texNames.Sort();
  11. ---->                   foreach (string tex in texNames) spriteList.Add(tex, 2);
  12.                 }
  13.  

Quote
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.

10
NGUI 3 Support / What is the correct way to re-position a widget?
« on: September 16, 2014, 11:59:59 PM »
I have a prefab widget called a "FloatingScreenNotification".  It's a pretty simple structure:

  1. UIWidget
  2.     Label
  3.     Sprite
  4.  

The widget, when created, uses Tweens to float upward, displaying a message, for example: "+1 [gold icon]"

The widget works as expected. However, when I create an instance of this prefab, and try to set its position, it is always drawn in the same exact position..
  1.                 GameObject go = Instantiate (FloatingScreenNotificationPrefab, new Vector3(-290, -272, 0), Quaternion.identity) as GameObject;
  2.  
  3.                 FloatingScreenNotification n = go.GetComponent<FloatingScreenNotification> ();
  4.  
  5.                 n.Label.text = "+" + amount.ToString ();
  6.                 n.Sprite.enabled = false;
  7.  
  8.                 //UIWidget widget = n.Widget;
  9.                 //widget.SetRect (-290, -272, widget.width, widget.height);
  10.  

-290, -272 is supposed to be at the bottom left of the screen. The widget was created in the middle of the screen, made into a prefab, and removed from the scene.

I've tried setting the GameObject's transform properties, supplying a position in the Instantiate function, and using the SetRect method, and nothing changes visually, the notification is always appearing at the middle of my screen and floating upwards. Is it supposed to be this hard to re-position a UI element during runtime? :(

11
I don't know what happened, but now the pink Plane defining my UI Root and my white special cube representing the Camera's view are not aligned, and I can no longer see my widgets in my game.

Background information, if it helps:
- I'm using a constrained scaling style, 800 x 480 with the Fit option for both content width and content height.
- I made my "UI Root" as a prefab, and create it at runtime
- I have a scene, UIDevelopment, where I want to develop my UI screens and interface. So I work on "UI Root"s children in this scene, and then save the prefab, and test it out in my game scene.
- I didn't notice any misalignment issues until after doing NGUI -> Create -> 3D UI, and it created a "UI Root (3D)" object. I've since deleted it though, since I couldn't figure out how to make 3d UI.

Questions for my understanding:
1. What's the relationship between UI Root->Camera and the scene's MainCamera? Are they the same? Are they supposed to have identical position/orientation at all times, or just that the UI Root->Camera output is displayed on top of the MainCamera output?
2. How can I align the UI Root's panel or the 2D pink rectangle with the UI Root's Camera? The pink rectangle is nowhere inside the white orthographic projection of the camera, and I don't know how to get it inside there, or how it ever got out of there..
3. Why does my UI Root have an odd scaling?  The x/y/z scaling is 0.004166667.  Is this small number something out of the ordinary?
4. Finally, if I have a child GameObject underneath UI root, and modify its x/y/z position, it does absolutely nothing? Shouldn't I be able to modify x and y to move child containers, sprites, labels, etc around?

Example of my setup:

  1. Main Camera
  2. UI Root (UIRoot, UIPanel, Rigidbody, UIEvent Trigger)
  3.     Camera (Camera, UICamera)
  4.     DefaultUI (DefaultUI)
  5.         Button_Gold
  6.             Container (UIWidget, Box Collider, UIButton)
  7.                 Sprite (UISprite)
  8.                 Label (UILabel)
  9.  

With this setup, modifying the position of Button_Gold does absolutely nothing to any children below it. Is this by design?  I am using GameObjects as a grouping mechanism, to organize UI screens in my game and hide/show them as appropriate.

12
NGUI 3 Support / How to make 3D widgets?
« on: September 16, 2014, 03:02:49 PM »
Is there a tutorial on creating 3d UI widgets?  What I would like to do is have images and text that are displayed in 3d space, in difference parts of the world. For example, imagine a 3d Mario hitting a block and having a coin image float up into the sky. I want to have similar kinds of notifications floating up, in the world.  Is this possible?

(From the NGUI menu option I created a "3D UI" object, which gives me two UI Root objects in my Hierarchy. I copied a Container, Label, and Sprite from my "UI Root" object to the "UI Root (3D)" object, but not seeing it.. I only see my 2D widget.)

13
NGUI 3 Support / namespace?
« on: September 15, 2014, 02:05:29 AM »
As it turns out, I'm also using an enum of type Direction, and it's preventing NGUI scripts from building.  Looks like we both aren't using namespaces. :(

Have you thought about putting NGUI code into a namespace?  Normally I wouldn't expect to see conflicts.. except I just found one. Not sure what I'm going to do here.. looks like I will have to put mine into a namespace... but then, shouldn't I put all my code into a namespace?  A lot of work, just to start playing with ngui. Doh..

14
NGUI 3 Support / scene picking and ui input handling
« on: September 14, 2014, 02:36:49 AM »
Hello,

I just recently purchased ngui, and watched all the tutorial videos. Maybe this is really simple, or I missed it, but what is the suggested implementation for determining if a mouse button down or finger down happens, and whether or not it happened on a ngui control?

Previously I have an update method, and each time I check the mouse position, if its not over my UI, I check if any mouse buttons are down, and do scene picking via raycast.

Would I just hook into the uiroot's click events and perform a raycast for scene picking? Do I need to do anything specific to support touch vs mouse? What happens if my mouse goes down on a 3d object, is dragged over a button, and released..

My game has UI input handling and non-UI input handling, for scene picking and camera manipulation. Its not clear to me how to handle input. Suggestions?

Thanks for any help.

Pages: [1]