Search Unity

[Official]New UI System.... coming in Unity 4.6

Discussion in 'General Discussion' started by Tim-C, May 28, 2014.

  1. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    Yes, but with the way NGUI does it, there's no need to drag things around. You can put the gameobjects wherever you want in an organised fashion then just change the draw order. Unity's way seems like it could make a mess of things by forcing you to put gameobjects in certain positions.

    Also, if we instantiate some buttons that have to overlap in a certain way, we might have to instantiate them backwards or something, so the last button is at the top of the hierarchy? Rune mentioned you can change the order through code, so maybe not.
     
    Last edited: May 28, 2014
    Tomer-Barkan likes this.
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I don't see how having yet another layering system makes less of a mess of things...
     
  3. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    Something tells me that they are more likely to be web developers than programmers then. From the looks of it, with the new gui system I could be finished with the flow and layout of the entire UI in an hour tops, and it would then be ready for content to be dropped on top of it.

    From what I'm seeing, it would be so easy to prototype in unity and functionally have it done, even if I had to make some scripts.
     
  4. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,119
    That's an amazing job you've done there, guys. Looks really nice, and the anchor workflow looks great!
    I have a few questions.
    1. The button has a "On Click" event. Is there a way to add "On Pressed" and "On Released" events as well?
    2. Does alpha work as expected for child objects (parent alpha affects child alpha)? Is there a way to circumvent this for a single child object (example: a background image has a text label as it's child. I want the background to always have 0.75 opacity. By default this will affect the text label's alpha. Is there a way to make this specific text label have 100% opacity, ignoring the parent's alpha?)
     
  5. Lime_x

    Lime_x

    Joined:
    May 1, 2009
    Posts:
    210
    This looks really interesting so far.:)
    What I'm wondering however is if old scripts using the current GUI API will still work after the update?
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    It'd be nice if these were added, but if they aren't, you could use animation events to accomplish the same thing.
    It looks like the canvas alpha can be used to affect all the children, instead.
     
  7. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Easily possible to implement a reverse order :)
     
  8. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Including drag-and-drop reordering?
     
  9. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    The other question is if it is possible to reorder the UI elements at runtime? So if I wanted to have a canvas appear behind another slide out and then slide on top of the one that it appeared behind of? There aren't a lot of help method on the current Transform class. Are there going to be things like Transform.InsertAt(transform, index) and GetIndexOf(transform)?
     
  10. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    So the default button we provide is only really interested in 'Clicks' and while it handles Press and Release events internally it doesn't forward them on... You can add this yourself pretty easily though:

    Code (csharp):
    1.  
    2. public class SpecialButton : Button
    3. {
    4.     public UnityEvent myPressCallback;
    5.     public UnityEvent myReleaseCallback;
    6.  
    7.     public override void OnPointerPress(PointerEventData eventData)
    8.     {
    9.         base.OnPointerPress (eventData);
    10.         myPressCallback.Invoke ();
    11.     }
    12.  
    13.     public override void OnPointerRelease(PointerEventData eventData)
    14.     {
    15.         base.OnPointerRelease (eventData);
    16.         myReleaseCallback.Invoke ();
    17.     }
    18. }
    19.  
    We'll be talking about API stuff later, but one think I'm really really happy about with the new UI is that it's all following 'normal' c# patterns. We use interfaces for knowing what gets call backs, and a whole bunch of other good things. No magic methods being called. :)

    It depends on what you mean by 'as expected' We don't change alpha of children if a parent changes in the UI system, but you can search for children and do this yourself if you like.
     
  11. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,051
    +1

    With NGUI for example you can change the UIPanel (= Canvas) depth by script and also there is NGUITools.BringForward(GameObject go);, NGUITools.PushBack(GameObject go); and stuff like that.
     
  12. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Yes they will still work, we are not removing the old GUI as the whole editor is built on it :)
     
  13. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    We have added helper functions to the transform to make it easier to reorder children from API.
     
  14. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Looks awesome. Anyone have info on handling different textures for different resolutions?

    usually it's been the case that you need 1x, 2x and even 4x textures.
     
  15. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    ... and also no possibility, right? Last time I used NGUI its layering system was the main reason why "last time" is a while back.

    The hierarchy sorting order for the new Unity GUI is absolutely awesome and a lot of fun to work with. It also keeps things tidy and clean in the scene.
     
  16. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Right now we are leveraging the Sprite system for the asset handling and are coupled to their SD/HD handling which currently is quite poor. Whilst I won't commit to anything I will say that they are very very aware that this is currently a sore point in 2D / GUI.
     
  17. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Talked to the developer on this feature. Currently it is not possible. I have raised you concerns with him.
     
  18. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109

    would be great to be able to take SVG formats created in illustrator, or even XAML (UI prototyping) and have import capabilities.... for true resolution independence.
     
  19. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    I would love that also. :) We did some experimentation with vector graphics for an internal Hack Week project, the results were really nice, but we haven't had the time to turn it into a 'feature' yet...
     
  20. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    One question about this. If I don't use any of the OnGUI system, will the default GUI skin (including the fonts and such) be included in my build? Or is it only included if it's actually getting used?
     
  21. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    I would have to check where the resources live. In the default resources there are two types, builtin and builtin-extra. If something is in builtin it is always included, if something is in extra it's only used if your project references it. Looking at the layout the default fonts and skins are included in the base builtin package.
     
  22. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,119
    Oh, that's fine then. I was afraid that some mumbo-jumbo was required for it to work.

    That's a real bummer. So you can't create a "panel" (parent game object) with content (children), fade that panel out and have all the content fade out automatically? Doing it by hand is a REAL pain in the ass: we'll have to create additional scripts for each widget in the hierarchy. This script will have to somehow update the widget's actual alpha to include their parent's alpha (which will also be affected by it's own parent). And that script would have to be executed last in the execution order, to take into account any other scripts which might modify that widget's alpha.
    I think this needs to be a part of the rendering pipeline and work automatically.
    Really guys, I can't believe you or any other beta tester, didn't run into this problem.
     
    Last edited: May 28, 2014
  23. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Whoa, lets hold off the flame train for a moment.

    The GUI system supports nesting of canvas' and a canvas has an alpha. Changing the alpha on a canvas changes the alpha of all the renderers on the canvas. So in your scenario you would make your 'window' a canvas and then if you want to alpha it out you can do it by just turning down the alpha on the canvas.
     
  24. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Nope, like I said it's designed to be super extendible. All the components and API we provide are written against public Unity API, no internal tricks or hidden stuff.
     
  25. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I suspect the solution is to use a "Canvas" for each window that you want to fade in. Since a canvas's alpha DOES affect its children.
     
  26. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    Usually in GUI you want parent-child relationship to work in a way that parent is behind the child. For example window to be parent of all its buttons and the Window would also render behind them.

    What you are describing is that hierarchy view is always sorted bottom-up. This would mean that parent-child would also be reversed. Parent would be below the child and when you expand a parent, it would awkwardly expand children on top of it (?)

    Other option I'm seeing is that you want some kind of zig-zag where siblings are ordered bottom-up, but parental relations top-down.

    Personally I don't see neither of these options as being superior to what we have now, but maybe I completely misunderstood. Can you provide some insight?
     
  27. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    That does sound like something masks should be capable of, or at the very least makes more sense for that kind of parent/child relationship to be the domain of masks. I could see issues with trying to structure the hierarchy for programming purposes, so I would be wary of that relationship in some way that wasn't a hundred percent explicit.
     
  28. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,119
    What if I have a button with a child label/icon I want to fade to 0.25 opacity when it's disabled? Or I have an complex objects, that has multiple labels and a button with a child icon and I want to be able to fade out the button to 0.25 opacity, and then fade out the whole complex object?
    How many canvases can I have in a scene and is there a performance hit for using multiple canvases? Can I nest canvases? Are they really supposed to work for the kind of situations I mentioned?
     
  29. aiab_animech

    aiab_animech

    Joined:
    Jul 4, 2012
    Posts:
    177
    This is great. Absolutely wonderful. More standard c# and less messages and other hidden stuff! :)
    It really seems like Unity is going in the right direction in general on this matter; more correct and standardized programming APIs. Big thumbs up.
     
  30. KyleStaves

    KyleStaves

    Joined:
    Nov 4, 2009
    Posts:
    821
    It seems like it should be very simple to create a "RecursiveAlpha" component to easily fade in/out groups of components.
     
  31. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Currently with buttons and other things that need 'nesting' like this we have been using the animation system to control the current element as well as the child element when required. We'll be having a talk internally about the points you have brought up, but I'm not sure if we want to have the behaviour you describe built in as it raises many questions. Things like, why is alpha multiplicative to children but not color? Why when I change the color of one element do I need to rebuild all children elements. Personally I feel this is better left to a case by case bases and only done when needed in a user script, but we will talk about it.
     
  32. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,119
    It might seems so but it's not.
    There is a multitude of problems of different complexities related to this problem.
    You have a button which is basically a background sprite + child text label. You set your text to 85% opacity. You want to fade out your button and then fade it in again. So the buttons alpha goes to 0 and than back to 1. If you have a script on that button that recursively changes alpha of the child label, than when the button reaches alpha=1, the text child will also be alpha 1. But I need it to have 85% opacity. Okay, then we need to store the initial text alpha before applying the button alpha. That might solve the problem, until we have a really complex object with multiple widgets and we have to store the initial alphas for every widget. Or there's another script that changes the label's alpha at the same time as the button. Or the button has another parent that is also changing alpha.
    This might look like a made-up example, but I've had to deal with this before, and it is a pain in the ass if it's not integrated into the system.

    Multiplicative color is not something you might need for UI design so often. Alpha on the other hand is used extensively to create fade-ins/fade out, disabled states, etc. It is a really useful feature.
    If you want, I can come up with a few real examples, with screen shots or even a real project using NGUI, to demonstrate a few cases and why I think this is important.
    Thanks!
     
    Last edited: May 28, 2014
  33. Mistale

    Mistale

    Joined:
    Apr 18, 2012
    Posts:
    173
    This is looking a lot better than I had anticipated! A big thumbs up!
    I realize that it won't be 'complete' in 4.6, but it looks like a solid foundation.
    One concern is the text-handling. I'm still on 4.3, so I don't know if this has already been fixed in 4.5, but the dynamic fonts are buggy at times. Upon re-building their textures to fit more characters, they sometimes fail to signal this to dependant controls which leads to jibberish characters (wrong uv).
    Please stress-test the dynamic font system before release, especially on mobile platforms.
    As it stands, we've had to resort to using bitmap-fonts or distance-field fonts since we can't trust the dynamic fonts.
    Note that this of course happens more often when you use a lot of different character sizes for the same font.
     
  34. The-Spaniard

    The-Spaniard

    Joined:
    Jan 7, 2012
    Posts:
    149
    Looks fantastic! I have a very GUI heavy app I was building a while back that I stopped work on due to difficulties with the instant-mode GUI (and I lost interest...) and this looks to be a fantastic improvement. Glad to see that it'll be a very open API as well. I look forward to seeing how text input boxes work, and I wonder how easy it will be to create complex interfaces with resizable, dragable windows and tabs (something nearing the complexity of an editor like Unity's). I hope that some higher-level standard GUI elements (like drop-downs, etc) are included as well, but I'm pleased to hear that they'll be easy to make ourselves.

    Great work (you've been working on it long enough... :p) and thanks for keeping the community updated with progress. Can't wait for "summer"....
     
  35. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    Good god, it's real... it exists...


    :D
     
  36. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    I have 3910 lines of old Unity GUI I stopped work on waiting for this and I was dreading porting it. Now it looks like via drag drop building in the hierarchy what I spent a month building (with problems still) can be done in 30 minutes.

    My question is, and I've watch all 3 videos and read all the posts but can't remember this being asked directly and directly answered:

    When I set up a old Unity GUI I noticed that even when I made icons at the correct scaled size for various game view port resolutions the icons were not scaled in the Unity 'Game' window, they were full size, although the 'Game Window' was scaled (I manually created Game view ports at various common device screen sizes). So now when I do this in new uGUI will the icons (sprites / menus) be scaled down as the game view port was?
     
    Last edited: May 28, 2014
  37. Cripplette

    Cripplette

    Joined:
    Sep 18, 2012
    Posts:
    66
    This is a must have for a GUI system. When you want to fade out a panel which contains children, you don't want to dig into all the children to make them fade out.
    It is like when GameObject disabled state was not herited into children, it was a pain and a miss conception.

    Btw can you create some invisible widget used for placement ? like an invisible rectangle.
     
  38. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    196
    @goat,

    The anchoring system should handle re-sizing elements based on the resolution of the target screen. "Stretch" ,discussed in the overview video, is one option for doing dynamic re-sizing. Based on the positioning of the anchors on your element you should be able to make sure something like a button always takes up the same relative screen space. Hope that makes sense.
     
  39. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    Thanks.

    That makes sense if they are scaled correctly to begin with. The 'Game' viewport I created at 1920x1020 that Unity scaled down should also scale the sprite at the same ratio as soon as the sprite/icon hits the Canvas.

    So it does quacks like a duck and looks like a duck and walks like a duck so I hope it's a duck. Or that saying goes something like that.
     
  40. Per

    Per

    Joined:
    Jun 25, 2009
    Posts:
    460
    Looks good, got a couple of questions.

    1 ) Will there be a table/cell/div/grid GUI element for things like inventories, crafting or dynamic lists? (maybe even optimized with culling)

    2 ) How much of this is scriptable? I mean can you create layouts on the fly? Do you have to use the GUI event system or can you attach events using scripting?

    3 ) Does the canvas also support non 2D elements, e.g. could you use the GUI's mouse events system to turn some real 3d buttons into functioning buttons? Or have the GUI texture on a more complex shape than a rectangle.

    4 ) Does the system support spline drawing? If not, is it planned?

    5 ) How fast is the text rendering? e.g. full large block of EULA text rendering on an IOS device, is that feasible? Or what about lots and lots of smaller text elements rather than a single large element?

    and

    6 ) Can you set formatting styles within a block of text, e.g. emboldening just one word?

    Which leads to...

    7 ) Are there plans for an HTML rendering element?

    and

    8 ) Input Fields... I didn't spot it, but is there a checkbox to enable text editing/input field within game? Ideally inline edit rather than specific input field as input fields always force their own formatting which is often ugly and it would be nicer to just drop a text field, have an enable editing checkbox (scriptable), and give it your own border/background, or even overlayed button (rather than giving the user a caret on hover always).
     
  41. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    I want to add my "vote" for having some kind of simple alpha control for children. Even if you don't feel like it should be present in every component derived from "base" UI component, you should provide some light-weight "Panel/Container" component with that functionality as I doubt that having multiple Canvases just to fade buttons (with text and/or icons) here and there is a good idea.
     
    Last edited: May 29, 2014
  42. Kylotan

    Kylotan

    Joined:
    Feb 17, 2011
    Posts:
    212
    Per managed to post just minutes before me with some of the points I wanted to make, but I'll make them again so it's clear how much demand there is.

    1) What sort of support is there going to be for grids, lists, and other dynamic layouts? The anchor system looks very flexible but without some higher level logic it looks like it will be a nightmare trying to create a scrollable list box in code containing an arbitrary number of contents, never mind a grid or table view. The video was 90% about static GUI layouts where all that changes is relative size whereas probably 90% of the GUI problems I've ever faced have involved dynamic GUI elements, where the content changes significantly. Ideally there would be some sort of object similar to the GUILayout Horizontal/Vertical system which takes ownership of the anchoring of its children. I'm also hoping that there would be some intelligent comparison of content size to parent size and automatic creation of scrollbars. Any comment on this?

    2) How practical is it going to be to use this from script? In particular, let's say my artist/designer creates a list box for me. Is it possible for him or her to set it up so that I can basically write one or two lines of code to add a new line of text or a new image to it? I can have this in HTML, and in pretty much any non-game retained mode GUI made in the last 20 years, but for some reason game UIs tend to make this harder than it needs to be, and the video here is not too encouraging in this regard.

    3) Input - How is it detecting mouse clicks? Does it prevent clicks passing through to items in the scene view? And text - is there any support for text input at all? And if so, does it consume keypresses?
     
  43. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,657
    One of my ongoing projects during the beta has been to build a copy of my current project's UI in uGUI - both my frontend (using the old Unity GUI wrapped in a bunch of components) and my in-game elements (using EZGUI). 30 minutes is about right; it took me a bit of time to get my head around the anchor system but once you get it things are stupid fast to build. It's finally back to the point where I spend more time in Visual Studio actually implementing the behaviour for the buttons than I do messing about in Unity trying to lay the widgets out.

    This has included doing fade-in/fade-out of menu pages by having a separate canvas for each page and animating its alpha value. Took about five minutes to set up, and now applies to all menu pages I build automatically (reusing the AnimatorController + a shared MenuController base class I wrote).
     
  44. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    I like this a lot so far. I went into the video thinking "How is this better than NGUI?" and the video then spent a lot of time talking about the anchoring system which is by far my biggest complaint with NGUI, and also one of the things Aren is most stubborn about being willing to change. This anchoring system looks far better, so I'm excited about that. I also like the simple screen-sized canvas and the event binding as well. The rect transform looks very useful. I like being able to move the pivot point in the editor (can we please get that on regular 3D objects as well?). The one thing I kind of prefer in NGUI is being able to use Tweens for animation instead of using the actual animation window. For simple things like button expand or OnHover color, I prefer just typing in a tween value and duration rather than needing to use the Animation window. But I can probably integrate that on my own.
     
  45. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,197
    Hey guys, I was just thinking, generally I draw my UIs on photoshop using a fixed resolution as base (generally 800x480 for android) and I always make small borders for my windows/boxes/buttons/etc because if I make thick borders for my windows/boxes/etc when the OnGUI draw them on 320x240 devices almost half of the window could be taken by these borders, I was thiking if the new system has anything to handle this, I thought about it because I saw a component called "Reference Resolution" with width and height inputs... I don't know if you will understand what I mean but, here goes my question...

    edit: also, because the padding/border and other GUIStyle attributes doesn't scale down with the resolution..
     
  46. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182

    Yes! That means the code I stopped work on last November will be about 500 lines not 5000 lines. This will do more to help programming good games as just about any other new feature.
     
  47. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    I made the background invisible on my menus to avoid such hassles...my GUI is like floating 'pictograms' (also because I don't want to translate languages)..,but in your case with the new uGUI it should scale the borders and such proportionately I think.
     
  48. im

    im

    Joined:
    Jan 17, 2013
    Posts:
    1,408
    wow from what ive seen in the video where u demonstrate new gui is soo amazing it looks like its done right, exactly what we all need / needed. great thread, very nice, keep up the communications it really great to see you all creating all these official threads and being here in the trenches with the soldiers...

    oh is there anyway to get access to unity 4.6 beta ( mean honestly anyone developing using unity needs it) cause who in their right mind wants to use the current ui when u could be developing it using the new most amazing / easiest / looks the greatest way...

    honestly after seeing the video. im sold ship the thing. i dont want to write another line of code for existing ui.. why make me throw it all away after 4.6 comes out. make beta 4.6 accessible to those who want it. at least they could be using it (and giving u feedback)...
     
    Last edited: May 29, 2014
  49. Schnelle

    Schnelle

    Joined:
    Jan 17, 2011
    Posts:
    89
    This looks outstanding. I have been wanting to create some business applications with Unity and the layout engine you demonstrated will take me a long way. Bravo.

    I may have missed this, but what is the length of beta and expected release for 4.6? Thank you.
     
  50. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    How's the event system looking? I'm really hoping that Unity helps clear up the various event systems around the place. It seems that everyone and their dog has their own, it'd be nice if there's a single standard one we could all work to.