Unity scrollview inherit scale and keep position relative to parent - unity3d

I'm trying to add some buttons to a gameObject which is a scroll view child. The child is a very wide image, about 4 times as wide as normal screens, which is why I let it control the height, so that it is always from top to bottom, and only exeeds horizontally where scroll is allowed.
Here you can see my setting.
1. is the wide image
2. is a banner that used to be part of the image, but now I want it to be a individual gameObject.
I don't know how I can make the banner (2) inherit the behavior of the "full map" (1), right now when I choose free aspect and resized the game view, the "full map" scales nicely, so the it always fits from top to bottem. The more narrow the screen is, then more of the map will exceed to the right, and vice versa.
However the problem is that then banner (2) has a rect transform, which is set with x,y coordinates relative to the parent which scales. So as i resize around the view, the banner gets out of it's intended position, and also does not scale with the. I have tried many different components, but without luck. Here among, scale constraint, canvas scaler, position constraint
As you can see in this gif, the banner does not scale down, as the island gets smaller, also it stays in the same position horizontally.
Any suggestions on how I can make the children os the map behave as they were part of the map?

Deleted previous, misunderstood the question.
Proposed solution:
You remove the map part from UI and create it as an object: You attach the map image as a texture to (ie) a plane (see a video here). You add the "infinity island" as another texture and have it placed over the island image.
After that, you control the camera to zoom in/out of the island and not struggle with any scaling or moving UI.

I think you need to anchor the images to center of the island mini image, you can drag the anchor gizmo from the scene hierarchy.
If you see it as free aspect it gets buggy and difficult to handle, but if you choose a resolution everything is smooth.
Is this what you want?
Change the resolultion

Related

Unity gameobjects and text ui change size and position while changing resolution

sorry I have to put all of this as an image but I couldn't post this with text as when creating the original post something happened to where it was flagged as spam. I figured this would be the only way?
Unity's UI screen is different from the in-game world space.
For the UI part you can easily fix the issue of the size and position by considering the following:
First thing you need to check is the Canvas Scaler component which is automaticaly generated on your Canvas gameobject.
Canvas Scaler Example
First under The UI Scale Mode you should choose the "Scale with Screen Size" which will make UI elements bigger the bigger the screen is.
Second is the Reference Resolution which is the resolution the UI layout is designed for. If the screen resolution is larger, the UI will be scaled up, and if it's smaller, the UI will be scaled down. A good example is to set the dimensions int something like this (1920x1080) which is the most common landscape resolution.
Third is the Screen Match Mode which is a mode used to scale the canvas area if the aspect ratio of the current resolution doesn't fit the reference resolution. With other words if you change your in-game resolution this will handle your UI elements.
Fourth is Match which will determine if the scaling is using the width or height as reference, or a mix in between. So if your game is in landscape mode you should set it to 0, if it's in portrait mode you should set it to 1.
Last thing to keep in mind that will affect your UI elements position is the Anchor presets which is part of the Rect Transform component on each of your UI elements.

How to resize camera to work with multiple resolutions on Unity?

I'm working on a fun project on Unity and I want to support all mobile resolutions in landscape mode. I designed everything to work in 1920:1080 resolution.
Everything works in world space, including UI elements.
What's correct way of supporting all resolutions (including weird ones like square 1:1)?
I don't want the scene to be cropped or filled with blue, all I want is my camera's viewport to be scaled to fit the device screen. I don't care if objects in the scene will get thin or fat.
To support different aspect ratios for your UI Elements, I recommend making use of the anchors that come with every RectTransform. These will ensure that the position of an element is consistent across various aspect ratios. For example, setting the anchor of an element to be left on the x axis will make the origin and pivot on the far left. This means an x position of 10 will position the element 10 units away from the far left of the element's parent. This is made easier with Anchor Presets. Although you can set every value yourself, Anchor Presets provide an easier way to anchor your UI Elements. Provided you have a RectTransform on you UI Elements, every element should have the Anchor Presets available. No need to change the width and height of your Canvas.
Aside from that the Camera should automatically resize depending on the resolution of the game view. You can test how your elements' anchoring works with different aspect resolutions by setting your game view's Aspect to free aspect, which will change the aspect ratio of the game depending on game view's width and height.

How to animate UI position for different aspect ratio screens?

I know how to make a moving animation of an UI object, but how to make it supporting different aspect ratio screens?
For example, I have an UI object_1 in the left-lower corner and object_2 in the right-upper corner, both adjusted its position relative to the screen's corners. I want to make an UI image moving from object_1 to object_2.
The problem is that object_1 and object_2 are at different positions (even different ratio according to screen ratio) in different resolutions. Then how can I make the moving animation supporting different resolutions?
Thanks for any advice!
Screenshots:
1 Moving starting point where the left-lower checkbox is on 18:9 screen.
2 Moving ending point where the left-lower checkbox is on 18:9 screen.
3 Moving starting point, changed to 16:9 screen, and the screenshot shows that the position of the finger image does not match where the checkbox is.
4 Moving ending point on 16:9 screen, same problem with the above one.
OK, problem solved. It turns out the animation supports changing anchors at certain frames. So just turn on recording and adjust whatever you like.
In my project, first frame I set the finger image's anchor to the middle-lower point then record its position; when starts the moving animation, changes its anchor to middle-upper point then set the destination position. If the screen aspect ratio changes, since the animation also uses the right anchor data with the two check boxes, they'll match perfectly.
FYI, here's a screenshot of the animation window to help you understand.
This may help,
docs Unity3d site
This will support animations.

Unity: Positioning an element on canvas

I need to move an image down through canvas so that its central point would be where is now its top edge. It makes some 50 points, but if I decrease y by 50, it moves to different part of the screen on devices with different screen size. I guess, it's because my main canvas is set to scale with the screen size. So I suppose I need to manually divide the number 50 by my screen height and then code to multiply by Screen.height? Isn't there a more convenient way to move UI objects?
Allow me a second question: Do you think it is even wise to make a game purely on canvas? My game is simple 2D, only slightly animated and contains many layout elements, so I decided to go for it, but I have hard time to grasp the UI position rules.
you may have the problem of the anchoring.
Unity UI totally depends on the Anchoring, if you have got right anchoring there is no issue.
For example. if you anchored something at the Center than changing left and right value moves them according to the center anchor.
for clear visualization, you can paste a screenshot of the behavior.

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?