Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Usefulness of Unity 4.6 UI system

Discussion in 'UGUI & TextMesh Pro' started by luniac, Dec 19, 2014.

  1. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    596
    Okay if i'm just misunderstanding something due to lack of development experience please let me know but I got some issues with this new system so far...

    I don't understand why the canvas got all scaling and aspect ratio components to help make it look good at any resolution but the same functionality is not extended to anything else? How is that helpful? I got a complete game here with all kinds of sprites, effects, etc but only the UI has the ability to properly scale to various resolutions...

    I personally use the 2D toolkit camera and it's been pretty dam great so far, i just stick it in there and use the fit visible override and it affects EVERYTHING in my game, not just UI...



    Another issue i have is with this new event system... sure it has all the callbacks and whatnot that are needed for input functionality but it doesn't have inbuilt SIMPLE support for more complex zoom,twist type gestures.

    I use TouchScript for all my touch input needs, and i don't need 3 different goddamn raycast components, one for UI, one 2D one 3D..... touchscript works for everything and has one gesture for nonspecific touches where i can use raycasts if i want to...



    The only useful purpose that i see of the UI when i already have access to 2dtk and touchscript is the fact that i can make a canvas in WORLD view, i can remove any default canvas scaling components and then the canvas becomes just another object albeit with powerful internal functionality regarding scrolling and precise object placement and all that...

    AND EVEN THEN do i still have to use the Graphic Input component to interact with the UI? is there any other way to interact with the UI, like the scroll bar and the sliders?

    Although maybe that's not THAT BAD if i just need to have one event gameobject with graphic input component and have touchscript as input for everything else.

    Although im not sure how i can say "IF TOUCHING UI, IGNORE TOUCHSCRIPT TOUCHES"....

    any thoughts?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Not quite sure what you mean; anything scales to various resolutions, unless you specifically make it not do so. That's how 3D graphics work by default...note that Unity normally works with units, not pixels (although you can make the GUI use pixels), and units are arbitrary.

    4.6 was just released recently, so I wouldn't expect it to have all possible features when it's new. I'm sure they'll be adding more features later. The priority was to get the basics done first.

    Well, a lot of people don't. If you have assets that work for you, great; feel free to ignore the 4.6 UI.

    --Eric
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Did you ever try use OnGUI? The improvements to the built in UI system should be obvious.

    Did you ever use SendMessage? The improvements in the event system should be obvious
     
  4. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    596
    I mean the kind of scaling that looks good on different resolutions, aspect ratios, such as scaling but with "fit visible" so no stretching occurs and no objects go off the screen type of stuff.
    But maybe i just gota learn more.

    I have been avoiding OnGUI because i did repeatedly hear about its issues.

    I do use sendmessage though as part of the touchscript plugin since i write in JS(don't kill me please)
    but i haven't had any problems with it(i hear it's slower but it's negligible for me so far at least)
     
  5. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    596
    well touchscript is free though :)
    I got lucky and got 2dtk on sale for 20.

    The thing is i like the way Unity does stuff and i prefer to use the native unity solutions for general game stuff and this UI system appears to be pretty integral to the experience, i guess i'm just frustrated a little with it lol
     
  6. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    596
    I think the combination of 2d toolkit camera with WORLD canvas may the amazing though. All i need to do is line up the canvas properly at the 2dtk reference resolution.

    I can use the 2d tookit camera features to make the ENTIRE game scale properly to different aspect ratios and resolutions and i can still use all the cool visual features of the canvas.

    The IMAGE UI one is actually great because i can size it to whatever i want and any sprite i stick in there will resize itself to be the size of the image. This way i can use any sprite to take up the top half of a screen for example simply by sizing the IMAGE UI to be that size, and when i choose different aspect ratios and resolutions in game view the 2d tookit camera resizes everything properly.

    This actually solves an issue i had so technically at least from a visual perspective only(no event system usage) the new UI provides some excellent stuff.


    Question though:
    To make the event system work with touchscript i can technically use
    EventSystem.current.IsPointerOverGameObject()

    if the pointer is over a game object i can ignore any TouchScript callbacks from inside my scripts. All i gotta do is add that if statement. Is EventSystem a static property?
    Is there a better way to do it?

    Like for example... Lets say i have half of the screen be a canvas, and the other half an advertisement banner.

    I use the graphic raycaster for the canvas and touchscript for the banner, or am i not understanding something about the graphic raycaster.

    Does the graphic raycaster detect touch on the UI or the Touch Input Module USES the graphic raycaster to detect a touch on a UI? so without the graphic raycaster the canvas is untouchable by the touch input module?
     
    Last edited: Dec 19, 2014
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Best way would be to eliminate all of your on touch, use a physics raycaster, and the interfaces provided with the event system.

    This may not be practical for existing projects, but is definitely the approach for new projects.
     
  8. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    596
    When u say physics raycaster do you mean the Physics 2D Raycaster that's part of the event system or just manually make a raycast script?

    for example, What is the most simple way possible to detect a for example a touch press on a BUTTON UI.

    I 100% need a graphical raycaster component on the canvas right?
    What exactly does the graphical raycaster component on a cavas do?
    does it DETECT a raycast hit from physics 2D raycaster?
    or does it shoot a special UI ray into the screen that only UI objects can detect?

    this is what's confusing me...
     
  9. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I mean the Physics2D Raycaster. Or the Physics Raycaster is your project uses 3D physics.

    The raycaster components are responsible for figuring out what the user input should be applied too. The graphics raycaster picks up UI elements, and belongs on the Canvas. The physics raycasters pick up colliders and belong on the camera.

    The Event System will examine the results of all of the raycasts, and choose the one closest to apply the input event to.
     
  10. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    596
    Ok so let me see if i understand this 100% now:

    Let's say I'm making a 100% 2D IPHONE game,
    The top half of the screen contains a canvas,
    the bottom half of the screen contains a banner image (basically not part of the UI system because itll be using some outside AD plugin from the asset store)

    So first off i need:
    1) EventSystem gameObject containing
    a)Event System component which is required because it globally handles interactions with event triggers on ANY object, not just the special built in events on Unity UI objects
    b)Touch Input Module component which is required because it supplies touch information into Unity that the event raycasters use, as in graphical,2D,3D raycasters.(forget multitouch for now, this game will be 100% single touch)
    c)Standalone Input Module which is required so i can test the game in the editor with my mouse but is essentialy the same thing as the Touch Input Module(for one touch at least)


    2)Graphic raycaster component on the Canvas gameObject because
    a)Without it the canvas UI children objects won't detect Touch Input Module or Standalone Input Module touches
    b)It's not a camera component because the Canvas component already contains an Event Camera variable to supply which camera to work with(not 100% understand this)


    3)Physics 2D raycast component on Camera gameobject because
    a)This way i can interact with 2D sprites which are not part of the UI system and therefore Graphic Raycaster does not pertain to them

    4)The banner Image contains an Event Trigger component because
    a) This allows it to detect a ray from the Physics 2D raycaster attached to camera(collider2D is required on banner Image)


    QUESTION:
    Assuming i understood correctly:
    If i attach an Event Trigger component to a BUTTON UI and create Pointer Down event for example, AND add a 2d collider component to it, this means that if i press on the button, the camera 2D raycaster component will hit the BUTTON UI and trigger the Pointer Down event?

    And at the same time through the Graphic Raycaster the Button Itself will become "Pressed Color" color?


    I'm doing my best to learn this system and find the best way to do my projects :)
     
  11. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    I know what the OP means but UI does autoscale and position when it's set up right. I have a Game Title now in text that isn't set up right but oh well.

    As far as the rest - the Unity engine is set up to choose a Quality level of Fastest for all platforms by default which since most people can't afford a liquid cooled dual video card rig every year is reasonable.

    The one problem with Unity that can't be solved with Unity auto-choosing LOD and UI is camera positioning. A scene that looks great at 16:9 will look clipped and uninteresting at 5:4 for example. However that's also true of your DVDs which is why most movies by default are letterbox at 16:9 rather than pan & scan at 3:2 when they get mastered to DVD/BR.

    So your solution is to design your game with a 3:2 or 5:4 viewport to look good in that mode and when a player goes to 16:9 or 16:10 the extra scenery will still look good but as background and not essential. So, in summary, design to look good in Portrait and it will look good in Landscape. It may looked clipped or amateur if you design to look good in Landscape and then switch to Portrait. You can also design to Landscape or Portrait and lock game play down in one of those modes eliminating the need to worry how it looks in the other.
     
  12. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    596
    I solve my aspect ratio issues using 2d tookit.



    Ok so ive done some testing and i have a general understanding of how things work now:
    Without graphic raycaster canvas inputs don't work,
    Event Camera variable seems to have no effect on anything
    the priority variable on graphic raycaster im unsure about.

    I have a new question though:
    If i have a sprite with 2d collider rendered over a canvas Button, the button still gets pressed instead of the sprite, how do i set priorities of what gets clicked over what?