Search Unity

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
    There is a very good reason for this btw. Try creating a window background with a UISlicedSprite that's rectangular in shape, such as 400x200. Now add a child UISprite to it that's a square. Now rotate this square 90 degrees -- the square now looks like a rectangle -- it's all skewed. Following the hierarchy I suggested above you don't get this problem.
     
  2. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    Okay, I think I'm getting it now. I'll restructure as you indicate!

    BTW, there was a warning... just in the console (I wasn't watching). I thought you might have mean't more like a dialog box popup sorta warning.
     
  3. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Is there a method (or can one be added) for a constant touch?
    At the moment everything is debounced or 'press' 'release' ; an OnContinuous event would be great! ;-)))

    Cheers
     
  4. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Code (csharp):
    1. public class ContinuousPress : MonoBehaviour
    2. {
    3.     bool mPressed = false;
    4.    
    5.     void OnPress (bool isPressed)
    6.     {
    7.         mPressed = isPressed;
    8.     }
    9.  
    10.     void Update ()
    11.     {
    12.         if (mPressed)
    13.         {
    14.             // Do your stuff here
    15.         }
    16.     }
    17. }
     
  5. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Hey ArenMook,

    :) lol; I know!, I was just wondering if it could be added to the lib.
    But thanks anyway :))

    Cheers
     
  6. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    SendMessage events are generally slow, so for performance reasons it would be best to do something like I wrote above rather than have the system send notifications while some touch is held. The approach above is clean and simple anyhow. :)
     
  7. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    I did think that; so will implement as you suggest :)

    Cheers
     
  8. mydingefnysen

    mydingefnysen

    Joined:
    Dec 15, 2011
    Posts:
    51
    Interesting! Im just doing some simple windows with label, textfield and a button, so I dont need anything fancy right now, but I can see how some kind of hierarchy could come in handy when doing more complex things. Feel free to share what you come up with if you try it out :)

    Ah, thanks! Didnt know that Unity does a GetComponent<Transform>()! Ill use the widgetToFollow.finalScale instead then.
    But if I use a transform instead of UIWidget for the widgetToFollow, how do I get the widgets pivot easily?
     
  9. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Ah true, pivot... then I suggest using UIWidget.pivotOffset and UIWidget.visibleSize, just scale them by UIWidget.finalScale.
     
  10. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Version 1.25 is now up for download.
    • NEW: Added a UIGrid script that can be used to easily arrange icons into a grid (used in Example 2).
    • NEW: UIFont can now specify a UIAtlas/sprite combo instead of explicitly defining the material and pixel rect.

    I'm still kinda iffy about the atlas/font integration. In order to keep older projects from breaking UIFont supports both paths right now -- with an atlas/sprite combo, and with a material/rect, so the code is not as perfect as I would like. But it does seem to work fairly well. I'll wait for some feedback.
     
    Last edited: Jan 5, 2012
  11. Kalagaraz

    Kalagaraz

    Joined:
    Aug 26, 2009
    Posts:
    46
    I have some tiles for a user interface that came with a pack of graphics I bought a while back. It's basically the border sprites for a window and then a center sprite you would tile to the window size. So I got top left corner, top, top right corner, right, bottom right corner, etc... all fixed size 45x45 (don't know why they chose 45x45)

    Does anyone have any idea the best way to go about converting these to like a 9-sliced sprite to work well with NGUI? Do I still all the borders togeather 9-slice that and then use center sprite as a tileable sprite to go over it? The center sprite isn't stretchable since it's made to have a wood-like pattern.
     
  12. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Merge the borders together, then tile the center, yup. That would work. This reminds me, I was planning on adding an option to UITiledSprite to not draw the center piece...

    Btw, you don't have to do that, technically. You can just piece your window together using several UISprites instead of one UISlicedSprite.
     
  13. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    hey aren im not sure whats going on but it was working fine until i redid the loading screen and now just the npc health bars arent showing up any ideas? my debugging version of flash is bugged and doesnt log...
     
  14. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    again its related to loadlevel... idk why its doing it this time, i just built the game without the main menu and the health bars show up
     
  15. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Well, it's a bug that Unity QA is aware of. It's some issue with serializable fields after LoadLevel.
     
  16. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    I've narrowed down the problem. It's an issue with Flash+Prefabs. If you reference in-scene objects (bring your font and atlas into the scene), it should go away.
     
  17. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    329
    The UIDrag script needs to be renamed UIDragCamera in this new version or you'll get an error.

    And yeah, I'd like a convenience function that adds an object to the list view. But I also think it would be good if the list view recycled list objects so you don't need a giant array of objects for a long list. Perhaps there can be a callback when a list object is about to become visible you can use to set it up with the proper label text, icon image, etc.

    But for now, I'll take a convenience function that adds an object vertically or horizontally to the list with an offset.
     
  18. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    UIDrag is gone. It has been renamed to UIDragCamera. If you still have it, I'm guessing you just overwrote the contents of the old NGUI folder instead of replacing the folder entirely?

    Also, I've already added a class that arranges children into a grid, take a look at UIGrid in 1.25.
     
  19. Hans

    Hans

    Joined:
    Feb 20, 2007
    Posts:
    422
    Hello ArenMook

    when is the tut on example 3 coming?

    thanks

    Hans
     
  20. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    It won't be much of a tutorial, but more of a write-up with explanations. That said, #1 on the list right now is support for trimmed sprites out of texture packer. That will be my focus tomorrow. After that I still have the built-in texture atlas creator tool I'd like to add for those who'd rather not use external packing tools, but we'll see. I'll prioritize based on what people want the most.
     
  21. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    I'd vote against a built-in TexturePacking tool. It'd be cool... no doubt.... but since, you know, that's what the TexturePacker guy spends all his time thinking about and improving on his own. Almost seems redundant. In the same why I'd recommend against trying to reproduce the Glyph Designer in there too.

    I'd argue that you should spend all your brain power and talent on the GUI-related stuff and let the other tools do their thing, since they are... after all... quite good at this point.

    My two cents anyway.

    David
     
  22. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    329
    Yeah, i agree. Focus on GUI functionality--we can deal with the external tools.

    Anyway I just clicked the import/update button in the Asset Store to get the new version. Is this not the proper way to update? I re-imported but don't see UIGrid. What's the best way to update to the new version?
     
  23. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    I agree with the others, unless you want total control over those atlases to eliminate problems/inconsistencies.
     
  24. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    329
    Hmm, now when I try to re-download it, the Asset Store download manager page says "error"
     
  25. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,085
    Not sure how long ago it went up, but I just checked out the draggable window demo. Man that looks awesome :)

    Thanks for taking the time to create such excellent examples. Love it.
     
  26. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    329
    Ok false alarm, Unity had logged me out of Asset Store silently. Hence the errors.

    So I got the new version, but I don't get how UI Grid works. When I apply it to my custom scroll view all the list objects disappear.
     
  27. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    329
    Ok the problem with this UIGrid thing is it ends up moving the objects away from the Viewport camera. So I had to apply UIGrid, then disable the script and move the Viewport around until it matched up with the newly arranged items. (After I had moved the new items away from the 2DGUI camera)
     
  28. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    329
    Also--one thing I've noticed is when the list view starts, there's a little gap between the top item and the top of the viewport window. When I first scroll the view down and then I scroll all the way to the top, the first item ends up being right up against the window instead of stopping where it was when the control starts untouched. Is this starting border a setting somewhere?
     
  29. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    329
    Also, my next request would be to have momentum on UIDrag.
     
  30. nsxdavid

    nsxdavid

    Joined:
    Apr 6, 2009
    Posts:
    476
    If Aren doesn't get around to it before I do, I'll add momentum (perhaps bounce too) to UIDrag or a new UIDragLikeObject in the next day or so and make that available.

    David
     
  31. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    329
    Oh yeah, bounce would be my next request. :)
     
  32. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @quitebuttery: Take a closer to look at how UIDrag is used in the second example. The gap is either because of your initial camera position (just move it) or the size of your items' colliders (expand them). UIDrag is uber simple. All child game objects under it are considered to be a part of the list. When it runs (or when you click the checkmark in the inspector) it positions all the children to be the specified distance apart. I suggest you play with the example and tweak UIDrag's properties there to see what happens.

    @nsxdavid: By all means :)
     
  33. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Hey all,

    Perhaps it me but depth doesn't seem to affect priority of touch. Therefore I looked at increasing the depth of the collider and making sure it's in front of any other collider. I'm trying to layer icon ontop icon and only want the one nearest the camera (i.e. visibly in front) to receive the press.

    Cheers
     
  34. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Depth is used for determining what's drawn on top. You have to adjust the collider's Z by bringing it forward or back if you wish something (icon) to receive events before something else (window background). I suggest just bringing the window background's collider back rather than every button forward.
     
  35. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Hey ArenNook,

    This is what I thought. I'm still getting the collider beneath triggered even though it's z pos is less.

    Cheers
     
  36. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Double-check to make sure the colliders are on the same layer and that dimensions are correct.
     
  37. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Ah yes. Had to scale my colliders to visually match the image exactly - works perfectly now thanks!

    Cheers
     
  38. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    NGUI menu -> Add Collider will also auto-adjust the collider's bounds to envelop everything under it. :)
     
  39. Quickfingers

    Quickfingers

    Joined:
    Aug 29, 2009
    Posts:
    268
    http://www.quickfingers.net/covert .. My flash in a flash compo entry. Filled with NGUI madness!

    FYI found a hideous bug that kept me up last night, with the new pivot system reloading scenes in flash causes all text fields not set to TopLeft, to set their pivots to top left.The first scene works ok but any scene after that or going back to the first scene again causes all text not set to TopLeft pivot to go back to TopLeft and everything goes out of line. Really hope you can fix this one :)
     
  40. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Thanks Aren! :)
     
  41. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    @QuickFingers

    Nice man!
     
  42. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @quickfingers: Damn, that's an awesome game. I love the style of it! Nice nod to Deus Ex: Human Revolution with the pass codes there. :) The pivot thing sounds like another side of the same flash bug. I've created a very simple reproduceable case I've submitted to Unity, so hopefully they can fix it soon.
     
  43. mydingefnysen

    mydingefnysen

    Joined:
    Dec 15, 2011
    Posts:
    51
    About built in atlas generation, thats something I would really like to see. We load a lot of sprites from online sources and removing the need of external tools would help a lot (For example, thumbnails from twitter)!
    Not having to go through texture packer every time you update just one GUI-sprite would save a lot of time as well.
     
  44. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Hey Aren,

    I'm having difficulty moving uisprites around so that they end up in the same screen position irrespective of resolution.
    I have them anchored to a corner but wish to place them relative to potentially a parent object.
    I assume the display is normalised and that screen wise it goes from 0 -> 1 , is that correct?

    Cheers
     
  45. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Same position in pixels, or same position relative to the screen size? If pixels, take a look at Example 0 -- the window there is anchored to a corner and it's always the same size in pixels regardless of the resolution. If relative, consider anchoring a game object instead of a widget, then parenting your widget to that game object.
     
  46. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Sorry, I'm confused :)
    I guess I mean position relative to screen size.
    You say for relative anchor them to a game object. Presumably you don't mean a UIAnchor do you?
    Sorry this is confusing me. I guess I am looking for a means that x=0.5 and y=0.5 is always centre of the screen a la Unity's Viewport system; then at least positioning (pixel wise) is irrelevant and equally I can 'scale' again with out a need for pixels. So an object could be centred at 0.5,0.5 and have a width height of 0.1 0.1 - hence visually it's the same irrespective of resolution.
    This I need for my outline icon boxes.
    I'm still unsure of how to deal with the bitmap contents though. Whilst (as mentioned previous) I can have 2 atlases (hi res and low res) do I just choose the 'nearest' atlas to my resolution and again use normalised space to draw the bitmap (which will of course produce some stretching depending on resolution)???????????

    Cheers
     
  47. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    0, 0 is the center of the screen, assuming the camera itself is at 0, 0, 0.

    You shouldn't be working in relative space like that, pick a target resolution and design your UI with that in mind like tutorials show. When your resolution changes the UI will be scaled accordingly automatically by Unity (it's just how cameras work).

    For choosing the closest atlas to your target resolution... assuming both atlases have sprites with identical names just in different positions and sizes, you can simply find all components of type UISprite and UILabel, and change their atlas to use the closest match when the scene starts.
     
  48. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Hey Aren,

    I've looked at the tutorials but they don't seem to help.
    Assuming I go down your root of being fixed to one resolution.
    Basically what I am trying to do is move an icon from the bottom left corner to say the centre of the screen (ok, I'll use screen.height/2 and screen.width/2) to get there (say with lerp) - I can't just adjust this uisprite's transform can I ?

    Cheers
     
  49. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Sure you can. Just don't anchor the sprite. Anchor a game object, and parent the sprite to it. You can then move the sprite freely.
     
  50. markhula

    markhula

    Joined:
    Sep 3, 2011
    Posts:
    630
    Reboot mac - seems to work now!!!!
    Hmmmmmm, a "Unity Moment" I guess!!!!

    Cheers
     
Thread Status:
Not open for further replies.