Scaling UI for all resolutions in Unity? - c#

I want to create a 2D game with unity. I use anchor points and canvas scaler as everybody says in the Internet.
The image below shows how do I set anchors
However, when I create an apk for Android. It works for some mobile devices (I tested with Xiaomi, Samsung with 720p,1080p or higher resolutions) but it doesn't work well for tablets. Such as Samsung Galaxy Tab A 10.1. In the image below: left one is Xiaomi, right one is Galaxy Tab
In the internet everyone says it can be done using anchors and canvas scaler and they resize the Game screen and show the UI scales in Unity. Yes, it happens so in unity. But it doesn't happen so in devices. In the image below I wanted to show when I resize the Game screen in unity there is no problem about scaling. What can I do about that? I appreciate for any help in advance.

The thing is, you can expand your UI 100% correctly only by 1 dimension - width or height. Looks like your UI suppose to preserve vertical size and can handle some free space on left and right, so change in Canvas Scaler component "Match" to Height (=1), so it will change your UI only if height is changing.

Change the match value to 0.5 -> 1 what in canvas scaler component and reset or modify UI.

Related

Unity 2D Canvas Scaler

I'm working in Unity, and something stuck in my mind. What is the difference between the UI Scale Mode options in the section of the canvas scaler component, can anyone explain it?
There are 3 UI Scale Mode options. Which of these 3 options should I use and what do they do?
Thanks in advance
You can check here for a more detailed explanation of each field: https://docs.unity3d.com/Packages/com.unity.ugui#1.0/manual/script-CanvasScaler.html
But basically:
Constant Pixel Size: means the UI elements will have the same pixel size always, no matter what size of screen do you have. So if you have a 100px X 100px button on your screen at 1920x1080 it will fill just a small portion of your screen, but if your screen resolution changes to 200x200 for example, than the button will be giant and fill a much bigger part of the screen now.
Scale With Screen Size: means exactly what it says, the UI will scale according to the screen size, so if you work and create your UI on a 960x540 screen and then change to 1920x1080 for example, your UI will scale, and in this case make the UI 2 times bigger because the screen is now 2 times bigger, so the aspect of the button will appear the same in all resolutions.
Constant Physical Size: uses DPI instead of pixels. DPI means "dots (pixels) per inch", meaning you it doesn't matter what the size of your screen is, the amount of pixels you define the UI will cover will remain the same, so for example if you have a 1920x1080 screen, and a 200x100 button, the button will be small on the screen, but if you play the game in a cellphone with lower resolution, 1280x720 for example, the button will remain with the same pixel density, 200x100, but since the screen has less pixels now the button will appear bigger, but in reality the resolution of the button in both cases remains the same.
But all of them also change the way anchors will work on your UI. The best way to know what you should use and what each one does is by testing yourself.
You can read more here as well for more information: https://docs.unity3d.com/Packages/com.unity.ugui#1.0/manual/HOWTO-UIMultiResolution.html

Animate initial vector drawing in WPF

I see several content, where an icon has an animated drawing, so it looks like the icon is drawing actually. For example the site http://www.baeldung.com/ use it for all his drawing (in menu bar at top). Another example is the fingerprint icon on the android lock screen. If the screen is activated, the fingerprint is "actually drawing".
How could I implement something like this in C# and WPF? It will be a pain to write the whole animation for every icon (there are up to 200 in our library).
Edit: the icons are vector images with a path value, for example from https://materialdesignicons.com/ or different sites.

Why Does My Unity Game Not Display At Full Size On Some Devices?

Could someone check why my game screen does not maximize on some devices?
Look at the screenshot :
You see the black background and some UI buttons which should be hidden are appearing? The game background is not maximized on some devices.
I am using 1280 x 720 Resolution. I have set a Pivot and Anchor Point In the Rect Transform. But it seems some devices don't display it well.
What should I do to have it maximized on all device? Any ideas?
Thanks
Dennis
I guess you are using UGUI (Unity's built-in GUI system).
Looks like the resulting screen does not match the aspect ratio you used for the UI, so it just rescales evenly until it fits the screen horizontally.
As you can see from the image below, You can have your UI elements scale to fit the screen following different criteria.
Rect Transform Anchors Presets:
If you want your UI to perfectly fit the screen and you don't mind some vertical stretch you might just use the bottom-right option.
However, it's always better to keep in mind the "safe areas" when you design your UI.
It's a concept related to TV screens, but I find it extremely useful for mobile products as well, you can get more info here
You should check if your canvas scaling is maybe set to 0.5 width and 0.5 heigth.
you should change it to 0.0 width and 1.0 heigth.
Also make sure your anchors is right. For the ui part i would write a manager which disables and shows ui based on game states.
hope it helps xD

Scaling issue in Unity

I am trying to make a game scene for Unity. However, I can't seem to get rid of this border. Or I can't seem to stretch my background to fit the whole screen. I need this scaling to work for all screen sizes. Here is an image of what is happening.
You can clearly see the blue edging, when I don't want that to be happening. This happens when I test on my Tablet as well. The camera is of size 5, however, when I do some debugging, I notice it gives me positions such as 7.15 when I touch on the screen. How can I scale everything down, I have searched through tons of forums and no one seems to be having this issue.
Are you using UI panel for the background? if so try these step.
1st strech the background Panel to fit the whole canvas size
then change the background panel to stretch in all directions
Then select the canvas object and render mode for screen space camera, assign your camera to it and change the UI scale mode to 'scale with Screen size'

Custom mouse cursor size in WPF

We are developing an application that must be used by people that may have some visual problem involving the use of kinect to move the cursor, so we need to make it bigger than usual. However, this application does not interfaces directly with kinect, so we can't use its APIs.
We are programming in C# (.NET 4.5) using WPF. The problem is that the default cursor size cannot be bigger than 32x32 pixel or 64x64 pixel in high res devices.
We first tried to make the actual mouse cursor invisible and then use a Graphics object, taken using Graphics.FromHwnd(applicationWindowHandler). It succeeds to draw the image but it leaves the trail of the past cursor positions.
Is there a way to do using the regular windows mouse cursor, or at least a way to remove the trail (like an "invalidate" method that force the current window to refresh)?
We already tried these solutions but with no luck:
www.hsys.com/CustomCursorArticlePart1.htm
www.hsys.com/CustomCursorArticlePart2.htm
csharparticles.blogspot.it/2005/03/custom-drawing-cursors.html
Couldn't you just use a Canvas control that covers the entire window, set the cursor to none and then put an Image control with a suitably large cursor image in the Canvas, with its Left and Top properties bound to the cursor's X and Y coordinates relative to the Canvas??

Categories

Resources