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
    Fullsize setting?
     
  2. Lord_Pall

    Lord_Pall

    Joined:
    Sep 25, 2009
    Posts:
    52
    UI Viewport has a Fullsize number in the editor
     
  3. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Oh -- that's just the orthographic size of the camera. It's the original value saved here, since UIViewport modifies the camera's value and it has to keep the original somewhere.
     
  4. Lord_Pall

    Lord_Pall

    Joined:
    Sep 25, 2009
    Posts:
    52
    Is there a straightforward correspondance between the viewport and main ui camera and that value?

    I've been sizing the label (that exists in the viewport camera) using that number. I also had to make it way bigger to even see the label themselves.
     
  5. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Basically it should match your 2D UI camera's orthographic size. This way you will get pixel-perfect results and the scale of main camera's widgets and the viewport camera's widgets can stay consistent (the scale of their root node).
     
  6. Lord_Pall

    Lord_Pall

    Joined:
    Sep 25, 2009
    Posts:
    52
    Got it. That fixed the scale weirdness.

    Is there a simple way to calculate the actual physical size of a UILabel? I create it from prefab, call makepixelperfect, but I need to know how big the actual box (with the wrapped text) is so I can offset.

    Do I need to roll that manually? Is there a quick rule of thumb between line width and number of characters if I know the font size, so I can calculate how many visible lines i've got?
     
  7. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    You do that via the label's font. You can ask the font what the printed size will be, given the specified text. Don't forget to multiply by the transform's scale though. :)
     
  8. Lord_Pall

    Lord_Pall

    Joined:
    Sep 25, 2009
    Posts:
    52
    Okay so here's what I'm using to calculate (For anyone who runs into this)

    UILabel has a line width of 450.

    I run the text through getPrintedSize. I get (16.7,1). I get the .size property on the font, which is 28. I scale the vector2 by this value and get (459,28)

    Since the line length is 450, I know I have 2 lines. Since I know the height of the font is 28, and I'm running 2 lines, I offset by 56.

    It seems to work.
     
    Last edited: Dec 26, 2011
  9. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    You could also just pass the 450 to the font as the maximum width, and it will create 2 lines for you.
     
  10. SoulWind

    SoulWind

    Joined:
    Aug 25, 2011
    Posts:
    23
    hi ArenMook
    you said that 1.09 is support preserving inner rects on import.
    but when I overwrite the altas picture and txt file, all inner rects back to default?
    or how can I re-import atlas ?
     
  11. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    This was fixed in 1.09f I think. The current latest version (1.10) should certainly have it functional.
     
    Last edited: Dec 26, 2011
  12. SoulWind

    SoulWind

    Joined:
    Aug 25, 2011
    Posts:
    23
    How can right-aligned a sprite or text?
     
  13. Lord_Pall

    Lord_Pall

    Joined:
    Sep 25, 2009
    Posts:
    52
    I'm not seeing a real clear codepath for using enter to activate inputs instead of clicking on the collider. Basically, a modal chat system. Press enter to type, press enter again to send.

    Sending the message "OnSelect" activates the input object, but because the controls are forwarded by the camera, no text shows up. I don't see a public or accessible way to manually set msel in the UICamera.

    Not a difficult thing to add, but I'm curious if there's a cleaner way to do that. I'm still trying to make the shift into events vs. function calls/object references, so there might be an obvious way to do this that I'm missing.
     
  14. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @SoulWind: There is no right alignment for text yet. For sprites you can just align a game object to the right side of the screen using UIAnchor, and parent the sprite to it, offset manually however you like (say by sprite's width).

    @Lord_Pall: You're right. I'll add a way of setting it. Edit: Adding this function to UICamera should do the trick:

    Code (csharp):
    1. public GameObject selectedObject
    2.     {
    3.         get
    4.         {
    5.             return mSel;
    6.         }
    7.         set
    8.         {
    9.             if (mSel != value)
    10.             {
    11.                 if (mSel != null) mSel.SendMessage("OnSelect", false, SendMessageOptions.DontRequireReceiver);
    12.                 mSel = value;
    13.                 if (mSel != null) mSel.SendMessage("OnSelect", true, SendMessageOptions.DontRequireReceiver);
    14.             }
    15.         }
    16.     }
     
    Last edited: Dec 26, 2011
  15. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Aren, having access to the RaycastHit is very helpful. Thanks for that. Another thing that would be cool, which I am making workarounds for is: to be able to cancel a drag event:
    For instance, if an object is affected, moves, as a result of the OnPress event, then I want the collider underneath it, now exposed to receive the OnDrag event. Instead the original object continues to get the OnDrag event.
     
  16. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Sure, I'll expose that the same way as the selected object.
     
  17. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Thanks! better yet- if the Drag is cancelled then the next collider would just get OnPress or whatever is appropriate instead of a continuation of the OnDrag.
     
  18. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    I can just expose all of them so you can do what you like. I think that'll be the most straightforward solution. :)
     
  19. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    I'm not sure what members you are exposing? I was thinking of like a CancelDrag() method or similar.
     
  20. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Actually a question for you... Why don't you just write a script that implements OnDrag and resides on the game object that simply forwards the events to some other object? Why cancel the drag on one object only to have it get picked up on another? That just seems confusing.

    Reason I'm asking is I implemented the functionality, but it complicates the code a fair bit and only works with the mouse, since touch-based inputs can have many dragged objects at once.
     
  21. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Aren, well I certainly vote for not complicating the code... And yes, that's exactly what I ended up doing. Just to clarify: there should be a choice where an object is draggable or not.

    In this case it's not a drag-n-drop situation. I processed the original collider with OnPress, and moved it out of the way (a domino that gets picked from a set on a table, actually). Now I want to get OnPress() or OnDrag() or whatever collider is underneath or next hit by the raycast. Instead NGUI is forcing me to forward OnDrag events around. Because they continue to be sent to the original collider, until the mouse/finger is lifted. Basically I just want to tell NGUI OK we are done dragging that object or better yet: not interested in drag events on that object.
     
  22. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    I see. Drag is just a notification sent to a pressed object. There is no "dragged" object, per say, just an object that the mouse or touch was pressed on and started moving. What you seem to be asking for is an object that can receive a press event, but not drag events, which isn't possible.
     
  23. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    OK just opining that it would be more convenient if the OnDrag was sent to whatever collider is currently under the raycast *unless* the original object was somehow marked as draggable, then the OnDrag events would continue to to be sent to the original collider. But this isn't hard for me to work around - so no worries.
     
  24. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    I understand, I am just saying that the drag even is always sent to the pressed object. I'm not sure how sending the drag events to an arbitrary number of objects that may be under the mouse if only the button happens to be held down is making things better. :) This feature might cause more confusion than anything, and the work-around where you manually forward the event to whatever you want to be receiving them is the more straightforward implementation. I'll give it some more thought though.
     
  25. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Furthermore btw, where would you put this flag you mentioned? Any simple collider is capable of receiving all of NGUI event system's events. It's not limited to widgets. :)
     
  26. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Dont mind me! I'm refactoring old code and (dis)abusing the new cached RaycastHit feature;)
     
  27. mohydineName

    mohydineName

    Joined:
    Aug 30, 2009
    Posts:
    301
    Hello!

    Thanks for releasing this product!
    How can I make a scroll list like in easyGUI plase? Any tutorial would be greatly appreciated
     
  28. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    Hey aren, not sure but when i downloaded and imported the new ngui package from the dl link i get these errors when im trying to work with a UILabel and i havnt tried any other widget yet.
     

    Attached Files:

  29. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @mohydine: Example 2 has a window that has can be dragged. What are you trying to make?

    @Efraser: o_O -- I've never seen this issue on either pro or free versions of Unity, and just tried it on my end and it's all fine. Have you tried importing it into a brand new project just to check? Has anything been modified on your end?
     
  30. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    P.S. Is the widgets' material null?

    If you navigate to where the issue happens you can replace these 2 lines:

    Code (csharp):
    1.  
    2. panel.AddWidget(this);
    3. mPanel.LateUpdate();
    4.  
    ...with these:

    Code (csharp):
    1. CreatePanel();
    2.  
    3. if (mPanel != null)
    4. {
    5.     mPanel.AddWidget(this);
    6.     mPanel.LateUpdate();
    7. }
     
  31. mohydineName

    mohydineName

    Joined:
    Aug 30, 2009
    Posts:
    301
    Right now all I am trying to do is a scroll list, but from which I can drag objects
     
  32. mohydineName

    mohydineName

    Joined:
    Aug 30, 2009
    Posts:
    301
    drag and drop somewhere else indeed
     
  33. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Hmm... that's more complicated. In order to have draggable objects work with a 2-camera approach scroll view you will need a 3rd camera which will draw the dragged object. If you don't need smooth scrolling, I would suggest just creating a bunch of labels in a column whos text you will be changing depending on the scroll value. Then you can get all of it done using just one camera.
     
  34. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    I believe it actually has to do with the fact that i removed the widget from the parent which had the panel script attached to it that might be why, i will take a look at it later. Thanks :)
     
  35. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Does UICamera obey the culling mask of the Camera it's attached to? Including mixed culling masks? cant get my 3D UI to work unless I set culling mask to "Everything" on my camera.
     
  36. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Yes it does. That's the mask it uses for both drawing and events.
     
  37. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    OK I think there must a a bug involving multiple cameras then. Will see if I can put together a simple repo case for you.
     
  38. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Example 3 (inventory) has both 2D and 3D UI, using different cameras, each camera drawing only one layer specified via the camera's mask.
     
  39. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Yes thanks, I know. But I've come up with a situation where UISprite doesn't render even though it's on a layer that is specified in the camera's culling mask. Could be related to my use of UISprite as a prefab... Are there any NGUI widgets that are unsafe to use as prefab?
     
  40. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Possibly. Double-check to see where the UIPanel resides that manages this widget. You may have more than one. Also I assume you've double checked to make sure that the widget game object is on the proper layer?
     
  41. mindlube

    mindlube

    Joined:
    Oct 3, 2008
    Posts:
    993
    Aha! I think I found it. The root gameobject (where the UIPanel got automatically added to) was on the Default layer. After I switched the UIPanel's gameobject to the "3DUI" layer, then my UISprites are now being rendered. I didn't realize that it was a requirement to put the root gameobject unto that same layer. But it is working now. That the UISprites are being instantiated from prefabs doesn't seem to matter/ works fine.
     
  42. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Glad to hear it. :)
     
  43. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    Hey aren, that doesnt seem to be the problem, when i add anything under the object with the panel script it doesnt even add a widget to the ui panel. Im not sure what is wrong but this is the setup:
     

    Attached Files:

  44. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Can you grab the latest version (1.11) and check to see if you still get this there?

    Btw... 1.11 has been released, adding a new example: Chat Window.
     
  45. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    nice update.. hey aren im getting this error on flash develop, any idea?

    Can't remove EquipItems (Script) because Mono's disabled (MonoBehaviour),
    LogCallStackError
    at com.unity::UnityNative$/Ext_Flash_LogCallstack()
    at com.unity::UnityNative$/_Z17DebugStringToFilePKciS0_iiii()
    at com.unity::UnityNative$/_Z22DestroyObjectHighLevelP6Objectb()
    at com.unity::UnityNative$/_Z22DelayedDestroyCallbackP6ObjectPv()
    at com.unity::UnityNative$/_ZN18DelayedCallManager6UpdateEi()
    at com.unity::UnityNative$/_Z10PlayerLoopbb()
    at com.unity::UnityNative$/NativeExt_PlayerLoop()
    at com.unity::UnityContentInternal/playerLoop()
    at com.unity::UnityContent/onEnterFrame()
     
  46. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Nope, can't say I've seen that before. When and where are you seeing it?
     
  47. DanTreble

    DanTreble

    Joined:
    Aug 31, 2010
    Posts:
    590
    Just had a chance to look at it. Very, very, impressed.

    If I had to pick a flaws, it would be in the small amount of tweening/animation in there.

    For instance UIGrowOnHover.Update. Seems a shame for each instance to have to be ticked every frame just incase it is animating. That's where the competition is a little better. Having a centralised animation singleton to handle it and only tick it for the lifetime of the animation isn't as clean, but it is more optimal.

    Also having numbers to represent state seems like a odd design choice.

    However the code is super clean. I picked up some pointers looking at it :)
     
  48. hjupter

    hjupter

    Joined:
    Dec 23, 2011
    Posts:
    628
    On Flash Develop
     
  49. Legacy

    Legacy

    Joined:
    Oct 11, 2011
    Posts:
    651
    I do not get the error but i know that we did have some issues last night with color state, it seems that the alpha for the colors is defaulted to fully transparent lol im not sure if its unity or ngui but it works very well, we published it to flash and it all works perfectly thanks!
     
  50. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @DTreble: You are welcome to use something like iTween or other animation tools. :) UIGrowOnHover is just an example script of how it can be done simply. When developing NGUI I was always faced with a choce -- keep it simple, or make it complex and do everything, and I would always go with the first approach.

    @hjupter: I've never used flashdevelop. Is it supported by Unity? The example runs fine when built by Unity into Flash.

    @Efraser2007: As far as I can tell it's a Unity thing -- default color is fully black and transparent rather than white and opaque.
     
Thread Status:
Not open for further replies.