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!
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.
/// <summary>
/// Gets the list of items clicked.
/// </summary>
/// <returns>The list of items clicked.</returns>
private List<RaycastResult> GetItemsClicked()
{
PointerEventData pointerData = new PointerEventData(EventSystem.current);
pointerData.Reset();
pointerData.position = Input.mousePosition;
List<RaycastResult> Result = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointerData, Result);
return Result;
}
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.
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.
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.
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.