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

    yuewah

    Joined:
    Sep 21, 2009
    Posts:
    98
    @ArenMook, will you consider to add this fix ?
     
  2. yuewah

    yuewah

    Joined:
    Sep 21, 2009
    Posts:
    98
    @ArenMook, will you consider to add this fix ?
     
  3. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Ideally the border scale parameter would need to be specified on the atlas rather than on the sprite. It's also not the best solution... I'm thinking of having some sort of a parameter on the UIRoot that would address this instead, but I haven't quite figured out the best way just yet. I'm letting it sit at the back of my mind while I'm working on other things.
     
  4. profanicus

    profanicus

    Joined:
    Nov 23, 2009
    Posts:
    295
    Can anyone advise me on how to stop sprites from automatically scaling when I press play?

    I am trying to use NGUI for simple in-game sprites(as well as UI) rather than integrate a second additional 2d solution. I want the sprites to approximate real-world sizes rather than pixel sizes, so I'd like the size of the sprite in the game view to be consistent with how I set it up in the scene view.

    I tried adding my sprite underneath a Panel (no UI Root or Camera) and setting all transform scales manually, but I when I press play it jumps up to "pixel perfect" size. I want it to stay the size I make it in the scene view.

    Additionally, I read that moving the sprite widget itself causes an expensive mesh rebuild; is this also the case if I give the widget a parent gameobject and move that instead?

    cheers.
     
  5. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Moving the parent is not as expensive, but still much more expensive than moving a panel. Sprites shouldn't resize to pixel-perfect coordinates on Play, and as far as I can tell they don't. I use a stretched UISprite for a background in more than one example (for example, UISprite - Backdrop in Example 2). Hitting Play doesn't resize it. I don't think they ever did... what version of NGUI do you have?
     
  6. profanicus

    profanicus

    Joined:
    Nov 23, 2009
    Posts:
    295
    It is version 1.83.

    I guess I must be doing it wrong - the Sprite was set to 128 scale in XY when NGUI created it, and if I change that it gets set back to 128 when I press play. Changing the parent gameobject works though, so I think I am not supposed to be scaling the sprite Widget directly?

    I am looking to have hundreds of sprites (bullets, simple animated units) moving individually so I think a panel for each one is not ideal. At the moment my prototype is just using mesh quads and lots of drawcalls.
     
  7. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    The only reason it would snap back to its original size would be if you had a UISpriteAnimation script attached. Is that the case?
     
  8. profanicus

    profanicus

    Joined:
    Nov 23, 2009
    Posts:
    295
    Ah yes I do :)
     
  9. profanicus

    profanicus

    Joined:
    Nov 23, 2009
    Posts:
    295
    Is there anything I can do to that animation script to stop that behaviour?

    Or do you think it is not worth me trying to use NGUI for this kind of thing performance-wise, since I am moving quite a lot of sprites around? All I am really trying to do is leverage the existing atlas and sprite tools so I don't have to do it all manually myself by mapping quads.

    ex2D is only $15 at the moment, I could just get that for the in-game stuff; I just wanted to avoid another atlas/sprite system if possible and thought I'd try NGUI first since I already use it for UI.
     
  10. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Do you need the sprite to be animated like that? If you want something simple like changing a color or growing in size, tweens are a better way to go here. If you need something more complex, then you can use an image button. UISpriteAnimation is mainly for playing out animations of many sprites (for example sparkle effects over a button). You can still scale it by scaling the parent. Anything more complicated, such as skeletal animation for a character, and I suggest creating it in a modelling package.
     
  11. Rook3D

    Rook3D

    Joined:
    Sep 27, 2011
    Posts:
    19
    Hello, I have just purchased this UI Tool and it is very impressive.

    I have been going through some of the basic documentation, but I have not found anything dealing with including building NGUI's entities into an existing project, using existing camera's, etc..

    Is there any specific documentation on this?

    Thanks

    ------------------------------

    Edit: For anyone else, this is explained in some previous posts ( a little outdated, given the Widget Tools though ) :

    http://forum.unity3d.com/threads/11...edback-request?p=767654&viewfull=1#post767654
     
    Last edited: Mar 21, 2012
  12. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    How would I go about detecting when UIDragObject (or Camera) is released from dragging?
     
  13. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    It's pretty much exactly the same. You will use the Create UI tool to create your UI, making sure that the game's camera doesn't see the UI layer, and that the UI camera only sees the UI layer. You then have an option to create a UI right there, or create it in another scene and just save it as a prefab that will be bright into the main game.

    I personally just use the former approach. My UI is generally created off to the side somewhere (or above the rest of the game, with the Y of 1000 or so). So when working there I just switch the camera to ortho, navigate to the UI, and modify what I need.
     
  14. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Whatever is being dragged will receive OnPress(false).
     
  15. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    I see. Thanks.
     
  16. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Last few revisions, since I haven't updated the thread in a while...

    1.85:
    - NEW: Added Example 12: Better Scroll View.
    - NEW: Added a script that can be used to efficiently drag the contents of the panel: UIDragPanelContents.
    - NEW: Added a function replacement for SetActiveRecursively (NGUITools.SetActive), since the former has rare odd issues.

    1.84:
    - FIX: Changed the way the font data is stored, resulting in potentially better loading performance on mobile devices.
    - FIX: UIPanel.Start() should now find cameras faster.
    - FIX: UIPanel will no longer use the clipping softness value unless soft clipping is actually used.
    - FIX: The way click / drag was handled has been changed a bit. It should now be easier to click buttons on retina screens.
    - FIX: Rebuilding an atlas was not updating fonts correctly.
    - FIX: Couple of tweaks to UIAtlas and UIFont's replacement feature.

    1.83:
    - NEW: Added a simple script that can save the state of the checkbox (or a group of checkboxes) to player prefs.
    - FIX: A variety of minor tweaks.

     
  17. mohydineName

    mohydineName

    Joined:
    Aug 30, 2009
    Posts:
    301
    Hi,

    What is special about UIDragPanelContents?
     
  18. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Instead of moving the widgets, it moves the panel (which is very efficient) and adjusts the clipping rect in the opposite direction, thus creating the effect of moving the contents, when in fact they lie still. Since the contents lie still, the buffers don't get rebuilt, which results in much better performance when scrolling through a long list on mobile devices.
     
  19. helioxfilm

    helioxfilm

    Joined:
    Apr 23, 2008
    Posts:
    259
    Can this be used with UIGrid?
     
  20. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    UIGrid can be a child of the panel, sure. That's how example 12 is set up. I just took example 7 and changed it to use the new script instead.
     
  21. mohydineName

    mohydineName

    Joined:
    Aug 30, 2009
    Posts:
    301
    Maybe it is just me but I am getting this when updating the package:
    Assets/Editor/Editor/NGUIJson.cs(60,57): error CS1061: Type `UIAtlas' does not contain a definition for `spriteList' and no extension method `spriteList' of type `UIAtlas' could be found (are you missing a using directive or an assembly reference?)
     
  22. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Sounds like something didn't get updated correctly for you. File -> New Scene, delete NGUI, then import from the updated package.
     
  23. helioxfilm

    helioxfilm

    Joined:
    Apr 23, 2008
    Posts:
    259
    Since I cannot check it now, I must ask: the momentum and spring properites are still working with this new feature, I assume.
     
  24. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Btw, performance-wise on a mobile device, sorted in fastest to slowest order:

    1. UIDragCamera (2D only, can't be moved off-screen)
    2. UIDragPanelContents
    3. UIDragObject

    So if you're using the camera approach, keep it. :)

    Yes, the momentum and spring all work as expected.
     
  25. helioxfilm

    helioxfilm

    Joined:
    Apr 23, 2008
    Posts:
    259
    Yes, this is very useful info. I am concerned because of the mobile performance. As of now I use the DragObject, but then I will switch to the Panel solution. Re-do it for camera use is too much work, but who knows, if I can get 10 fps more, I might consider...
     
    Last edited: Mar 20, 2012
  26. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Ah then yes, you will get a noticeable performance boost by switching to UIDragPanelContents.
     
  27. mohydineName

    mohydineName

    Joined:
    Aug 30, 2009
    Posts:
    301
    Since you are there, what is the proper way to scale a UI based on device screen properties(size and dpi)?
     
  28. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Depends on what you want to do with it. If you want pixel-perfect results, keep UIRoot set to 'automatic'. If you want predictable results, turn off the automatic option and set the target resolution. The UI will scale as the resolution changes, staying the same size relative to the height of the screen. In the next version I'm also going to add something similar to a "dpi" setting to the UIRoot, as some guys (yuewah) need it for what they're trying to achieve.
     
  29. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Btw, if anyone knows what "bugs" the last two asset store reviewers were talking about, I'd love to know so i can fix them. It's so disappointing when people don't even try to seek assistance... :|

    Well, I'm going to get some sleep.
     
  30. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,203
    I'm seeing the following problem with the uipopuplists that I create. The list items and the hilite for the items are working correctly, but the underlying slicedsprite for the background of the dropdown list seems to be off:



    Not sure what could be causing it... The same slicedsprite is being used for everything. It's like the box starts halfway down the first item.
     
  31. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    Having some issues setting alpha values of UISlicedSprite through script.

    Code (csharp):
    1.  
    2. foreach( GameObject go in obs )
    3. {
    4.     go.GetComponentInChildren<UISlicedSprite>().color = new Color( 255, 255, 255, 100);
    5.     go.GetComponentInChildren<UILabel>().text = "";
    6. }
    7.  
    Basically I have a co-routine which goes through an array of game objects and resets the label text and colour in the child objects. It works perfectly with the exception of the alpha value. It seems it can only ever be 255 or 0 and nothing in between. It also works perfectly if I do something like color = Color.red; or even new Color(255, 40, 205, 255); or something similar.
     
    Last edited: Mar 20, 2012
  32. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @Jaimi: Does that sprite have padding?

    @CJO: Color is specified in 0-1 range, not 0-255.
     
  33. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    I see. Ty. The values in the editor are misleading.
     
    Last edited: Mar 20, 2012
  34. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,203
    It does have a 1 and 2 pixel border padding - strangely enough. Not sure why that cuases it to be off so far. But I have added new sprites with no padding, and it does indeed work right now. Thanks!
     
  35. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    This one's for @yuewah:

    1.86
    - NEW: UIAtlas now has a "pixel size" property that affects MakePixelPerfect logic as well as sliced sprite's border size.
    - FIX: UISprite will now always ensure it has a sprite to work with, if at all possible.
    - FIX: UIDragPanelContents should now work correctly on mobile devices.

    http://www.youtube.com/watch?v=ARfmGCMbJr8
     
  36. yuewah

    yuewah

    Joined:
    Sep 21, 2009
    Posts:
    98
    Great man, ArenMook. Just tested with 1.86, Sliced sprite border size fixed, but Tiled sprite is not fixed.
     
  37. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Can't "fix" a new feature, yuewah. I simply didn't change the tiled sprite. You can fix it locally by opening UITiledSprite, navigating to line 53, and taking pixelSize into account like so:

    Code (csharp):
    1. float pixelSize = atlas.pixelSize;
    2. float width  = Mathf.Abs(rect.width / scale.x) * pixelSize;
    3. float height = Mathf.Abs(rect.height / scale.y) * pixelSize;
     
  38. yuewah

    yuewah

    Joined:
    Sep 21, 2009
    Posts:
    98
    Thank a lot.
     
  39. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    No worries. I've also uploaded 1.86b with this tweak.
     
  40. yuewah

    yuewah

    Joined:
    Sep 21, 2009
    Posts:
    98
    Btw, the prefab is instantiated in runtime, the sprite cannot change to HD, can you add a option that allow to Find the prefab instead of the active scene objects only

    Code (csharp):
    1. static public T[] FindActive<T> () where T : Component
    2. {
    3.     //return GameObject.FindSceneObjectsOfType(typeof(T)) as T[];
    4.     return GameObject.FindObjectsOfTypeIncludingAssets(typeof(T)) as T[];
    5. }
     
  41. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    The sprites are referenced by names, so there is no need to change prefabs. Assuming you have them use the reference atlas, when this sprite is brought into the scene it will automatically pull from whatever atlas it's pointing to.
     
  42. KvanteTore

    KvanteTore

    Joined:
    Feb 16, 2010
    Posts:
    87
    @ArenMook, that's brilliant. +1 on the pixel size solution :)
     
  43. yuewah

    yuewah

    Joined:
    Sep 21, 2009
    Posts:
    98
    The prefab is in the Asset Folder, not in the Scene View.
     
  44. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    I understand that, yuewah... but nothing should be referencing your final HD / SD atlases. All widgets should be referencing the "main" atlas. This way when the main atlas's "reference" value gets changed, all widgets using it will update automatically, regardless of where they are. Only active scene objects need to know about this change because they need to be notified so they can re-draw themselves. Widgets that are not in the scene or are inactive don't need to be notified.

    If you are having some issue with this, can you post some more info with what's going wrong and where?
     
  45. yuewah

    yuewah

    Joined:
    Sep 21, 2009
    Posts:
    98
    Before that, I find another bug about the prefab. Based on the tutorial 2, I make the one of the UISprite to be prefab in Asset Folder, then call NGUITools.AddChild( panel, prefab ); In 1.86c, it raise the following exception, but 1.86 works without problem.

     
    Last edited: Mar 22, 2012
  46. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    I can confirm that there is a regression change there. I'll fix it, thanks for reporting it!
     
  47. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    1.86d fixes that. Thanks, yuewah.
     
  48. yuewah

    yuewah

    Joined:
    Sep 21, 2009
    Posts:
    98
    Thx a lot. Another problem, When using NGUITools.AddChild( panel, prefab ), the new UISprite (Clone) local positon, scale and rotation is not the same as UISprite prefab. I think it is better to have a option to allow keep them the same or reset. What do you think ?
     
  49. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    That's intentional. NGUITools.AddChild does that. You can instantiate the prefab yourself using GameObject.Instantiate if you don't want this behavior.
     
  50. trelobyte

    trelobyte

    Joined:
    Nov 17, 2010
    Posts:
    54
    Hi ArenMook just downloaded ngui 1.86d2 !
    I have a small problem when i add a button the collider seems to be translated on x to 59.5 and on y -15 and are slightliy oversized so i manually have to set it to x=0 and y=0 and the size correctly.
    i tried changing the handle mode to pivot or center and add another button to test but that did not see to affect it... i also tried the global and local coordinates but i still see the same thing
    When i manually add a collider then everything is ok
    Could you please let me know of a quick fix so i dont have to manually add colliders to each button ?
     
Thread Status:
Not open for further replies.