Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NGUI (Next-Gen UI) -- demo final feedback request

Discussion in 'Assets and Asset Store' started by ArenMook, Dec 8, 2011.

Thread Status:
Not open for further replies.
  1. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Ok, start with something easier -- example 1.

    Select the "Show" button. It has a UIButtonTween script attached. This script is pointing to Cubes as the target, which is a disabled game object. "If Disabled On Play" option is set to "Enable Then Play", meaning it will enable the game object before playing the tweens.

    Now select the "Hide" button. It has the same script attached, pointing to Cubes as well, but the direction is now "Reverse" instead of "Forward", and "Disable When Finished" option is set to "Disable After Reverse", meaning it will disable the game object and all of its children after the animation finished playing in reverse (which is what this button triggers).

    To manually enable or disable the panel, it's the same as any other game object -- NGUITools.SetActive(gameObjectToUse, trueOrFalse).
     
  2. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Also note that "Cubes" game object doesn't have anything on it, but it does have two children that happen to have TweenPosition script attached with "from" and "to" values set. The script is also disabled, meaning it will not automatically start playing when the game object becomes active. UIButtonTween script enables it for you.
     
  3. Zemnoph7

    Zemnoph7

    Joined:
    Apr 4, 2012
    Posts:
    8
    Hey Aren,

    So I am using NGUI 1.91 on a windows7 machine. I am using several UIPopupLists in a scene and have all the OnSelectionChanged events forwarded to a single game object. I am getting the following error when the scene is not being played

    !IsPlayingOrAllowExecuteInEditMode ()
    UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
    UIPopupList:set_selection(String) (at Assets/Resources/NGUI/Scripts/Interaction/UIPopupList.cs:163)
    UIPopupList:Start() (at Assets/Resources/NGUI/Scripts/Interaction/UIPopupList.cs:202)
    UnityEditor.DockArea:OnGUI()

    however, when I play the scene, it runs as it should. Any Ideas on this?
     
  4. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    That happens when you are forwarding events to a script while in edit mode, with the script not marked as "ExecuteInEditMode".

    Simple solution would be to change:

    Code (csharp):
    1. [AddComponentMenu("NGUI/Interaction/Forward Events")]
    2. public class UIForwardEvents : MonoBehaviour
    to:
    Code (csharp):
    1. [ExecuteInEditMode]
    2. [AddComponentMenu("NGUI/Interaction/Forward Events")]
    3. public class UIForwardEvents : MonoBehaviour
    ...but my suggestion is -- don't use this script. It was written for those coming from an EZGUI background, and it's more of a work-around to make it easier for them. I suggest using UIEventListener.Add instead. Have your single game object's script reference the popup lists via a public variable, and in its Start() function, add the listeners to those popups via that method. It's faster and more elegant.
     
  5. Zemnoph7

    Zemnoph7

    Joined:
    Apr 4, 2012
    Posts:
    8
    Awesome, thank you very much
     
  6. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    I'm having a difficult time trying to get the "Tool Tip" to work.
    I've studied and stared at the character example. I've even tore the exact pieces out of the example and put them into my bare bones UI. I can't get the ToolTip to pop up no matter what I do.

    The references I've found where you discuss it is very short and makes it seem like it's so incredibly easy to do however I feel like I'm missing something.

    Looking further into the example I have no idea how you are even getting the tool tip to be recognized per asset.
    Thanks in advance.
    B

    IMO It'd be great to just have a simple Tooltip option be added during
    the widget creation.
     
  7. Zemnoph7

    Zemnoph7

    Joined:
    Apr 4, 2012
    Posts:
    8
    Sorry for the simple question, but what even listener to I choose for popup list OnInput()? OnSelect()?
     
  8. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @modeling_man: Try something easier. Add a label to the scene that you can find, whether by name or by a script reference, then add the OnTooltip function to one of your scripts attached to the widget you want to have a tooltip. Inside that function, find your label and set its text.

    @Zemnoph7: UIEventListener.Add(targetGameObject).onSelect += YourFunction;
     
  9. Matkins

    Matkins

    Joined:
    Aug 24, 2009
    Posts:
    152
    When changing a sprite image in run time by doing mySprite.spriteName = "new_sprite_name" the sprite changes but the scale does not change to the size of the new sprite. What would you suggest i do to get the sprite to go to the correct size?
     
  10. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    That's intentional, Matkins. Just call sprite.MakePixelPerfect() if you want it to update its size.
     
  11. vrgz

    vrgz

    Joined:
    Apr 20, 2011
    Posts:
    34
    hi ArenMook

    i have a question
    i make a ios game with ngui
    and i use Instantiate add a ngui prefab in the scene.
    the prefab include some sprite and label.and use itween position and scale.
    and i make it rise from the bottom to the top,and more and more bigger
    like some Achievement message box.

    and the question is :
    Most of the time it works perfect.but some time the background sprite (in this prefab )looks error and full of the screen.
    i can't find what make this happen.it happen in Approximately 10% chance.
    can you help me ?
    i think is it a itween bug?
     
  12. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    When you instantiate an object, generally its position and scale matches the prefab, unless you explicitly change it to something else. Using NGUITools.AddChild instead of GameObject.Instantiate ensures that it's always brought in with the scale of (1, 1, 1). I suggest looking into that first, and then checking to see what scripts you have on the background sprite, to see if any of them are causing issues.

    I also suggest using Unity's built-in animation system to create such transitions instead of iTween. They are far more powerful and fully WYSIWYG.
     
  13. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    I have one panel with soft clipping that contains a lot of items (think inventory). Now when the user starts dragging an item I want to move it to a different panel without clipping so that he can drag anywhere on the screen. I've tried parenting it to a different panel with transform.parent = panel.parent, but it's still clipped. How can I assign a UIWidget to a different panel?
     
  14. kevinseligmann

    kevinseligmann

    Joined:
    Mar 23, 2011
    Posts:
    68
    Hi Aren! I have a doubt, is it possible to add opacity to a NGUI generated sprite? I have my atlas with lots of textures, and I want to set manually the opacity of one Sprite depending which button the user clicks.

    Can this be achieved?
    Thanks!
     
  15. kevinseligmann

    kevinseligmann

    Joined:
    Mar 23, 2011
    Posts:
    68
    I looked into the documentation and there is no color property, I thought I may achieve something by doing mySprite.GetComponent(UISprite).color or something similar and changing the Alpha property from 255 to 0, but I don't really know how.

    Any idea?
     
  16. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    @kevinseligmann: let me answer that for you: UISprite inherits from UIWidget and as such it has a color as well as a convenient alpha property.

    mySprite.alpha = 0f;
     
  17. kevinseligmann

    kevinseligmann

    Joined:
    Mar 23, 2011
    Posts:
    68
    Thanks very much col, is it ok to declare mySprite as a GameObject? Because I'm getting that ALPHA is not a member of GameObject.
     
  18. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    There is an example for this that was added in 1.92 :)
     
  19. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    take your game object and GetComponent<UIWidget>() on it. You can modify 'color' and 'alpha' on the returned UIWidget as you want.
     
  20. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Btw, if you're using Javascript, make sure to follow the instructions in the readme file first or you won't be able to access any of NGUI's classes.
     
  21. kevinseligmann

    kevinseligmann

    Joined:
    Mar 23, 2011
    Posts:
    68
    Thanks very much Aren! I did it by changing mySprite.GetComponent(UIWidget).color.a = 0.25f;
     
  22. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    @ArenMook: Thanks, I was pretty close. :) Even doing it the same way as your script I was still running into the same ordering issue I was having - the background sprite would suddenly be in front of half the widgets on the item, but moving the background-widgets a bit back on the z axis fixed it...

    Do you have any kind of writeup on how the ordering process works? Because what happened here was something like this:
    Each item consists of several sprites and some labels, all from one atlas except the icon which is from a second atlas. 2 panels, one for the background, one (clipped) for the list of items. When I move one item from the list to the background, the background jumps in front of all the other items, but only in front of those widgets that belong to the first atlas, the second atlas was still in front... confusing stuff... If I had an understanding of how this order comes to be I'm sure it would help me in the future... :)
     
  23. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Everything inside the panel using the same atlas gets bundled into the same draw call. The order in which widgets appear inside that draw call is determined by depth. The order in which the draw calls appear is determined by the distance from the camera to the center of the draw call's geometry (this is why adjusting Z works).
     
  24. col000r

    col000r

    Joined:
    Mar 27, 2008
    Posts:
    698
    makes sense - thanks a lot!
     
  25. goodhustle

    goodhustle

    Joined:
    Jun 4, 2009
    Posts:
    310
    @ArenMook: I ran into a small issue when testing out the controller input example scene. Clearing the selection with KeyCode.Escape (line 544 of UICamera.cs) makes it so that Keyboard/Controller control schemes get locked out of selection, because the UICamera no longer has a selectedObject to send messages to. Additionally, it seems like a side effect is that it removes the target of the OnKey SendMessage call for KeyCode.Escape in line 735 of UICamera.cs.
     
  26. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    That's intentional -- the selected object is cleared on escape. Check the chat window example to see how it activates itself when the Enter key is pressed.
     
  27. goodhustle

    goodhustle

    Joined:
    Jun 4, 2009
    Posts:
    310
    I see what you mean, and I was able to easily write a script similar to ChatInput.cs that selects the attached gameObject by default if return is pressed while UICamera.selectedObject is null. I then attached it to a button on each panel that I wanted to make a default button. Thank you for the tip!
     
  28. BalloonSeller

    BalloonSeller

    Joined:
    Apr 16, 2012
    Posts:
    2
    Hi ArenMook

    I have a question.
    I use UITable with UIDragCamera in developing my project . This table moves across the scene.
    The problem is that when the table elements get closer to screen bounds they start to move away. How can I solve this issue?
     
  29. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Camera-based approach has quite a few limitations, one of which is the inability to move it off-screen. It's mentioned in the example.
     
  30. kevinseligmann

    kevinseligmann

    Joined:
    Mar 23, 2011
    Posts:
    68
    Hi Aren, I was told today that we needed to add to the application's GUI an animated sprite of a product rotating.
    I'm still not sure yet, but I think there are 360 png files, making a loopable complete turn of the object in the images.

    Does NGUI support this? Is there a way to play one image per FPS inside a Sprite Widget?

    Thanks!
     
  31. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    If the object is flat, and you have a top-down view, it's as simple as spinning a single sprite. If you have a 3D object, then I suggest actually having that object in your world and just rendering it into a RenderTexture that's then drawn as a part of your UI using UITexture. The third option is to have however many frames pre-rendered into individual sprite textures, and then pack them into an atlas. Name them consecutively, ie: object01, object02, object03, etc, and then use UISpriteAnimation to play them back by specifying the prefix up to the number (in this case 'object').
     
  32. gamefools

    gamefools

    Joined:
    Apr 9, 2011
    Posts:
    35
    Hi,

    I'm having a an issue. I decided to reorganize my atlases and decided to put all my fonts in the same atlas. So I removed the font it from its original atlas, and then recreated my font in a new atlas called Fonts. I went through all the labels and dragged the new font into the Font field of UILabel. Everything looks good when I run the project within Unity, but when I build it and run it, none of the labels show up at all. I know for sure that all of the labels were showing in builds before I made this switch. Any thoughts on what could cause this issue?
     
  33. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Dragging the atlases over isn't enough. You also need to update the sprite. Use the drop-down list to select the correct sprite for your fonts.
     
  34. gamefools

    gamefools

    Joined:
    Apr 9, 2011
    Posts:
    35
    When I look at the sprites within the atlas and the font, they seem correct. They both show the box around the font. Would that have explained why it's working in Unity and not a build? It's probably also worth noting, that when I create a new label widget with the font, it shows up fine in the build.
     
  35. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    If it works in edit mode, and works in the editor, but doesn't work when you build, then the issue isn't in the atlas. Are you using the latest version, 2.0.1b?
     
  36. gamefools

    gamefools

    Joined:
    Apr 9, 2011
    Posts:
    35
    I'm not sure what the issue was, but when I re-create the font back in the atlas it was originally in, it works fine again when I drag the fonts to the labels. I guess I'll just leave it there for now. Is there an issue with creating an empty atlas and then creating a font in it without there being anything else? Yes, I am updated to the newest version. Very happy with it.
     
  37. kevinseligmann

    kevinseligmann

    Joined:
    Mar 23, 2011
    Posts:
    68
    Sorry Aren to come back once more, but I have a doubt.

    I'm using a plugin which let's you playback full hd videos (AVPro), and the plugin renders the video with GUI.DrawTexture.
    I already managed to play the video in fullscreen, etc. But my problem is when I try to make a "Skip video" button.

    The problem is that the button is behind the video, and I can't find a way to bring it on front. I tried modifing the GUI.depth of the video but everything stays on the same place. Is there something I could modify on my NGUI Button to be rendered in front of a GUI.DrawTexture?

    Thanks very much.
     
  38. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @gamefools: Well, it's good that it works, whatever the issue was. And nope, there are no known issues with that.

    @kevin: Unity's GUI will always be on top of your scene objects, including NGUI. There isn't much you can do about it. I'd suggest requesting an NGUI compatibility feature from the makers of AVPro.
     
  39. petrucio

    petrucio

    Joined:
    Aug 30, 2011
    Posts:
    126
    Is there a good reason why I can't use SphereColliders after the last update? BoxColliders work fine, SphereColliders do nothing. They used to work fine on previous version on NGUI.
     
  40. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    All colliders work exactly the same. NGUI simply piggy-backs on the Unity's physics system, it doesn't do anything itself. Whatever's wrong, it's not on NGUI's side.
     
  41. petrucio

    petrucio

    Joined:
    Aug 30, 2011
    Posts:
    126
    Yeah, the camera is inside the sphere if I use the hierarchy created by the 'Create a New UI' menu, which I did today after updating. My camera needs to stay a bigger distance away from the UI to use spheres - my bad.
     
  42. petrucio

    petrucio

    Joined:
    Aug 30, 2011
    Posts:
    126
    Actually, my problem is that the UIAnchor script is tugging the entire UI with the camera when I move it away, so I can't move it outside the colliders. So if the user wants to work with SphereColliders for the widgets, he is forced to set the Ui Camera member of the Anchor to None (thus losing some nice auto-resolution stuff).

    Maybe something that could be addressed in a future update?
     
  43. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Set the depth offset on UIAnchor (if its a 3D UI), or set up the near/far clipping planes correctly (if its a 2D UI -- the create UI tool makes them -10 near +10 far, for example).
     
  44. petrucio

    petrucio

    Joined:
    Aug 30, 2011
    Posts:
    126
    That works with widgets I create inside the editor, but I'm Instantiating cloned widgets programatically, and their Z position gets automatically shifted to the camera plane, which is exactly what I don't want - and I can't seem to be able to budge them.
     
  45. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Parent them to an object that has been offset along the Z.
     
  46. petrucio

    petrucio

    Joined:
    Aug 30, 2011
    Posts:
    126
    That worked, thanks!

    On an unrelated note, I have a mobile suggestion: trigger a OnHover event when the user sweeps a finger over a widget. Currently I have to check for this by doing Raycasts inside an Update function instead of relying on NGUI events - or is there an easier way to do this?
     
  47. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Why raycast? UICamera.hoveredObject will tell you what's under the touch inside your OnDrag callbacks.
     
  48. petrucio

    petrucio

    Joined:
    Aug 30, 2011
    Posts:
    126
    Because I'm still learning and wasn't aware of that... :)

    OnHover would still be nice tho.
     
  49. petrucio

    petrucio

    Joined:
    Aug 30, 2011
    Posts:
    126
    Actually, your suggestion does not work as is, because the only widget that receives OnDrag is the initial widget that started the drag, not the widget now currently under the touch. So while UICamera.hoveredObject helps me out a lot, I still need to track when it changes on an Update function instead of relying on OnDrag.
     
  50. petrucio

    petrucio

    Joined:
    Aug 30, 2011
    Posts:
    126
    In case anyone is interested, this does the trick for touching OnHover:

    Code (csharp):
    1.     void Update() {
    2.         if (!fingerOnUs  UICamera.hoveredObject == this.gameObject) {
    3.             fingerOnUs = true;
    4.             this.OnHover(true);
    5.         }
    6.         else if (fingerOnUs  UICamera.hoveredObject != this.gameObject) {
    7.             fingerOnUs = false;
    8.             this.OnHover(false);
    9.         }
    10.     }
    11.  
     
Thread Status:
Not open for further replies.