Making a panel stretch to the size of the canvas and then back to its previous size like a "maximize" button in Unity - unity3d

I've figured out how to make the maximize portion of this work using the aspect ratio built in function on a button to scale a panel up to the full size of the screen. Haven't been able to find anywhere how to get it to back down to its previous size.

Related

Unity - UI Positions

I currently have a problem on a UI.
The button on the phone moves when changing resolution and changes size as well. On the screenshots, it is in the General Panel. I also tried to put a second panel of the size of the phone, but it is all this panel that moves and changes size. How can I do, to keep the buttons at the right size and in place, as the background does when changing resolution?
Thanks in advance !
You need to change the UI Scale Mode to "Scale With Screen Size".
THe Reference Resolution can help you place items in the editor. You can choose wether you want the width or the height (or a mixture) to be preferred when fitting the canvas to the resolution.
If you, for example, choose "Width" in the "Match" slider, the elements will never overshoot horizontally. This would be perfect for wrapping textfields.

How to keep the same resolution of canvas on different screen resolution?

First of all, sry for my English mistakes, I'm not a native English speaker.
I'm trying to make an UI which is composed of a canvas within different gameObject, and I would like that my canvas scales to the dimension of the screen but keeps its original resolution (16x9 portrait). If it is displayed on a tablet resolution (4x3) then an image is displayed in the space that is not covered by the canvas.
But actually all I've got is a canvas which scales to every resolution, and it changes the aspect of its child (for example a square becomes a rectangle).
Thank you for showing interest in my query!
UI's are heavy beasts. Canvas in Unity have a component attached to themm called Canvas Scaler which is set by default on Constant Pixel Size. You may try to set this property on Scale With Screen Size and then specify the base resolution you want to work with (usually 1920x1080 is a console standart). This is your first step
Then, to avoid strange Image scaling, you may check the property Preserve Aspect, this way the ration of the Sprite into your Image will remain the same indepently of the ratio of the Image
Last, you may play a bit with anchors but this is another story, you should let those at plain center at the beginning and come back to it when you will feel ready
Hope that helped ;)
Your canvas should have a component called Canvas Scaler. Here it should say Constant Pixel Size, change this to Scale With Screen Size and it should lock the Canvas to be the same width / height as the screen. If you want to lock an image to a specific width/height ratio, go to the Image component on the image and check the Preserve Aspect checkbox. This way if you have a 100x100 image, the images width will always be the same as the height. If you have a 200x100 image, the images width will always be twice the height, etc etc etc.

How to change canvas' size in unity3d

I can not change canvas' size when it's in Screen Space - Overlay Mode; After some research I found that the size of a canvas is determined by your game's screen size. The canvas just covers your screen. So I think I could change my camera's size to change canvas' size. But it does not work. Does anyone know how to set a specific size to a canvas?
So may be my question should be how to change the screen size showed
in editor?
To change the screen size, go to the Game window (accessed by the menu "Window->General->Game"). At the top of the window will be a screen size menu (outlined in green, below) to change the screen size. When pressed, it will display the list of screen sizes that will be emulated. I say "emulated" instead of "displayed" because it is possible to have a screen size larger than the screen on which you are working. It is also possible to zoom into a screen. The "Scale" slider (to the right of the screen size menu) will allow you to scale up/down.
As a note, the list of screens and resolutions shown are related to the current build target (accessed by "File->Build Settings..."). For example, common iOS screen sizes are displayed in the list when the build target is iOS.
Use the Canvas Scaler Component
Unity3D Documentation: Canvas Scaler

Unity - Keeping UI centered no matter the screen resolution

I want to keep my UI looking the same no matter which resolution the screen is at I am running of 16:10 in my game view and I want the UI to stay the exactly the same and centered even if the screen resolution changes.
Screenshot of UI
For the UI in the screenshot, I assume you want it always at the bottom of the screen and always the width of the screen.
For always taking up the width of the screen, select your canvas and go to its canvas scalar component. 'Change UI Scale Mode' to 'Scale with Screen Size' and adjust Reference Resolution to a resolution that looks good for you. Then the canvas elements will be the same width on all resolutions.
For always staying centered at the bottom of the screen, select the UI elements themselves, or their parent if they have one. Change their anchor to bottom center.
For more information about how to design for all screen resolutions, check the documentation as Hellium suggested!

Canvas too big for the camera in Unity

I have created a 2D game with an orthogonal camera and using 16:9 display size.
I dragged my background image onto the hierarchy (it's about 2048x1152) and then set the camera size to be 22.5, which made it fit the background perfectly and displays just right.
However, when I add a Canvas for a UI it is absolutely giant, about 100 times bigger. It only becomes 'normal' size with respect everything else added when I set the camera to its default size of 5. So when I add a small graphic, it too becomes giant.
I'm simply following a book I read and I'm not doing anything to deviate.
Am I doing something wrong? Below is what I mean. The background image is the little image in the bottom right and the outlined rectangle is the canvas with a small graphic added.
Thanks.
To force your Hierarchy Canvas UI to the same resolution as the Camera View in your Unity Editor Scene window resolution (i.e. not ridiculously massive), or in other words get the Canvas to fit into the Camera size in the Scene, do the following:
Set the Canvas component's Render Mode to Screen Space - Camera.
Make sure you select or drag the relevant Camera from the Hierarchy to the Render Camera field in the Inspector.
You should use the Unity canvas for this along with the canvas scaler component. If I'm not mistaken it will scale all elements relative to the screen they are viewed on.
The canvas scaler allows you to match the scaling based on a preferred viewport size which is a life saver.
However this may not fit you needs perfectly as it would mean that the background element would become fixed. So if you wanted to pan the element you would need to move it's x and y elements within the canvas.
Hope that helps?