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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

World Space ScreenSize

Discussion in 'UGUI & TextMesh Pro' started by NobodyReallyDotDot, Apr 24, 2015.

?

Should such a feature be implemented in a future build?

  1. It's not necessary

    0 vote(s)
    0.0%
  2. For sure!

    16 vote(s)
    100.0%
  1. NobodyReallyDotDot

    NobodyReallyDotDot

    Joined:
    Apr 24, 2015
    Posts:
    2
    Hi guys! We're not making a game in unity. We're working on an app! (It's not crap, its a government project).

    We have build the entire app using NGUI and because unity now has a UI that works this time we're rebuilding the project. Within the first hour we hit a road block and its something we would want to do the correct way.

    We're looking for a way to have the world space UI fit the actual size of the screen at run-time. NGUI was easy because we could just set it to the screen width. We haven't had much luck with unity's UI using that method.. We need this because each page(Canvas) is set at different locations around the scene that we have a dynamic camera array preform a set of animations to blend each page.

    Even though UUI is young, It's really damn awesome!
     
  2. Ramcat

    Ramcat

    Joined:
    Aug 16, 2014
    Posts:
    95
    The dynamic camera array poses an interesting problem. Aside from that, have you looked at a canvas in screen space - overlay, the canvas scaler scales the canvas to any screen size. Depending on your animations and screen blending, you might be able to do that with multiple canvases in screen space - overlay.

    Another approach might be to use screen space - camera because animations can be done between the camera and the canvas. Multiple canvases can be on the same camera (I believe), with different distances, or multiple cameras, each with a canvas. Of course, in this mode the canvas always fits the screen.

    Now to do it the way you asked, their are some ways you could change the size of the canvas and with raycasting detect if it fills the screen.

    Code (CSharp):
    1. /// <summary>
    2.     /// Gets the list of items clicked.
    3.     /// </summary>
    4.     /// <returns>The list of items clicked.</returns>
    5.     private List<RaycastResult> GetItemsClicked()
    6.     {
    7.         PointerEventData pointerData = new PointerEventData(EventSystem.current);
    8.         pointerData.Reset();
    9.         pointerData.position = Input.mousePosition;
    10.         List<RaycastResult> Result = new List<RaycastResult>();
    11.         EventSystem.current.RaycastAll(pointerData, Result);
    12.      
    13.         return Result;
    14.     }
    I used a method like this to detect uGUI elements. Instead of the mouse position you could use the corners of the screen. During your splash screen you could do these detects to find the size of your Android or iOS devices.
     
  3. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    Daft question, but if you want the canvas to fill the size of the screen, why aren't you using a Screen Space variant of the Canvas.
    • Screen Space - Overlay resembles the old style Legacy GUI and draws on top of everything
    • Screen Space - Camera adds perspective, rotation and rendering layers
    Both of which use the full screen by default.

    Is there some reason you are trying to use a world space canvas full screen?
     
  4. NobodyReallyDotDot

    NobodyReallyDotDot

    Joined:
    Apr 24, 2015
    Posts:
    2

    Yes! I need to be able to move entire canvas's using its transform independently from the camera. An example of this is a popup window we made to display errors or notices. this works by a popup camera in place that overlays the main camera and then moves a canvas in to the view of the camera. These moving canvas's need to be first set to the screen dimensions to assure everything fits on screen regardless of screen dimensions.

    This is why I need to be able to set the world space canvas's to the dimensions of the screen.
     
  5. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    Then you may be better having a full screen panel and adjusting that rather than a world space canvas.
    If you want to move all objects in the UI canvas, then simply group them under an empty GO on the Canvas and move the empty GO.

    No need to use a worldspace canvas for that scenario.

    If you also need to rotate or add perspective to the panel, then use a Screen Space - Camera canvas.

    Hope that helps.
     
  6. jhkimblue

    jhkimblue

    Joined:
    Mar 27, 2015
    Posts:
    14
    I think that this is a must have feature. In current status of new UI, to do camera effect on ui, there is way that switching canvas to world space, witch cause lots of side effects. Also a problem for SimonDarksideJ's solution is if a scene has multiple canvases you should know every UI root objects when you try to shake your UI. Of course I could do that though, it doesn't looks like a elegant solution. Not sure that which way is good way to implement this kinds of needs; camera effects shaking, sizing, etc.., but i think there should be a feature handling this needs in a beautiful way in a near future build for sure.
     
    Last edited: Jun 18, 2015