how to create dynamic UI that adjust itself to current screen dimensions after loading? - unity3d

I have created a level editor using new UI system in Unity3D.
Using Level Editor:
I can drag the ui elements,
I am able to save them in scriptable objects
But how could i save and load them at runtime?
I mean, if i create a level with some {width x hight} resolution and if i load it on different resolution, then the whole UI positioning get distorted.
How could i anchor them correctly programmatically?
Any help would be appreciated.

There are good video tutorials about the 4.6.x UI here:
http://unity3d.com/learn/tutorials/modules/beginner/ui.
Especially for positioning the elements I recommend watching: http://unity3d.com/learn/tutorials/modules/beginner/ui/rect-transform.
I suggest you learn how to use the anchor correctly first. If you want to change the position and size of UI element in a script you can do that through the RectTransform component. It offers functions like offsetMax,offsetMin and sizeDelta for position your UI element. The functions you need to use depend on your anchor setting.

as LokiSinclair said. You just need to Adjust the Scale that the new UI provided. It is the four Arrow on the Canvas of each Object and every UI object is inheriting their scale behavior from their Parent.

Related

Scale UI buttons and images with screen size

I ma developing a game for unity and i want to be able to scale my buttons and UI elements to fit different screen sizes. Please how can i go about this? I have tried scale with screen size and it doesn't seem to help me. Is there a script i can use for this?
You will want to use a canvas scaler for this.
You simply attach this object to your canvas parenting your UI elements and it will scale them acordingly.
You will also want to make sure your UI elements are anchored correctly so that they stretch with their correct anchor point.

UI Panels are not positioning themselves according to screen size

My UI elements inside my panels are scaling fine with screen size, but the distance between my different panels is not. I have 3 panels in my scene at different relative position which i set at 1920x1080 reference resolution, and switching between them using animation. But when i change the game view resolution, these panels do not align themselves right. Here are the screenshots:
These are the panels at 1920x1080 which i set.
These are the panels when i set game view resolution to 2340x1080. As you can see, the "settings" panel is still fine but the "more settings" panel does not repositioned correctly.
The same thing happens when i set game resolution to 800x480.
Please help me..
The easiest way you can achieve what you are attempting to do is to use a component called GridLayoutGroup. Add this component to a parent object, child all three of your UI elements to it, and set the column count to 2. I can add an example in a bit, currently building a project.
Edit: Here is a gif example of the above solution.

Unity UI screen size issue

I'm quite new to Unity, so I'm sorry if this is a basic question. I've been trying to set up the UI for a mobile game, but I'm not quite sure how to make the UI lock it's position, no matter the screen size. I've tried using anchors (though I don't fully understand how to use them properly), I've tried using a canvas scaler, I've looked at the Unity document and I just can't seem to find an answer. The buttons are off screen/half off the screen when I build the game to my device/switch screen sizes in the game view. Does anyone know how to fix this?
You can set your anchor point by selecting the UI object (such as a button) and then clicking here and selecting the right anchor point. You can also press down shift to set the pivot and/or alt to move the object to that point at the same time. The object should now be anchored to that point and keep its position even if the resolution is changed. You can set a precise position from the inspector, too. Simply adjust the Pos X and Pos Y variables. It will still adhere to the anchor point.
Note that you might have to play around with the Canvas object's UI Scale mode and its settings to get the right setup.

NGUI can't bring sprite to front in Unity

I have a sprite widget in NGUI, and It can't be brought to front what ever the depth I change in the editor:
Note that the orange panel is a scroll view of NGUI.
Here is the inspector setting of the sprite that I want to set to the very front:
And here is the inspector setting that has overlapped the above sprite that I want to make front of it.
And here is the BottomPanel setting
I finally solve this problem by
Add another panel
Setting the added panel in front the origin one
Make the sprite child of the newly added panel
And the final hierarchy is like this:
And this link of NGUI forum helps
quoted here:
"Depth" property is used to determine the drawing order of the widgets within the same panel that use the same atlas. If you are using different atlases or labels using a dynamic font, bring the widgets forward on the transform's Z, moving them closer to the camera (-Z). If you are using different panels, adjust the transform of the panel you want to bring in front to a lower negative Z value (-Z). I highly recommend sticking to one atlas if you can manage it, it will make your life significantly easier.
And I make a youtube video to explain what I have achieved so far.
Everything looks fine to me but it doesn't seem to work for you. There is another workaround.
On the UIPanel, change the Render Q to Explicit then use z-axis to sort your UISprite. I mean the z position (P) not (R) or (S)
For example, change the z-axis of the "Sprite (1)" object to be 2 then change the z-axis of the "background" object to 1. If this does not work, change the values around.
Please make sure that the Sprite is under the panel.

How to line-break buttons using Unity 3D New UI

I'm not familiar with Unity's new UI system of 4.6 and later. I would like to display a series of buttons on screen and have them center-aligned and breaks into the next line when screen width is reached. The old OnGUI function no longer seem working so I wonder how can I achieve this?
You need to use UI's layout system. Usually, you just create a Layout Group and populate it with objects that have Layout Element component.