如何显示的游戏在使用Unity Android设备各个方面比同一部分? [英] How to show the same part of game on every aspect ratio on Android devices with Unity?

查看:220
本文介绍了如何显示的游戏在使用Unity Android设备各个方面比同一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从Libgdx引擎团结快到了,我是一个初学编程的。我尽量让游戏在Unity Android和iOS设备,但我有纵横比/分辨率缩放的一个问题。在Libgdx如果你开发你给一个默认的决议的东西,一切都将被缩小到设备的屏幕,不管它是否有更大或更小的分辨率,并没有什么会从屏风隔断。在另一边,团结,如果我做一个游戏,将裁剪画面所选择的高宽比,这是不是最好的,如果你想在所有可用的设备相同的体验。我已在网上搜索了很久,但我还没有发现任何会为我工作。

I'm coming from Libgdx engine to Unity and I'm a beginner programmer. I try to make a game in Unity for Android and iOS devices, but I have a problem with the aspect ratio/resolution scaling. In Libgdx if you have develop something you give a "default" resolution, and everything will be scaled to the device's screen, not matter if it has bigger or smaller resolution, and nothing will be cut off from the screen. On the other side, in Unity if I make a game it will crop the screen to the chosen aspect ratio, which is not the best if you want the same experience across all the devices available. I have searched on the internet for a long time, but I haven't find anything that would work for me.

底线:我想知道,如果有一些code团结(C#),这将让我的比赛看起来像跨越不同的纵横比的所有设备都一样吗?我正在开发使用Unity 2D。如果任何人都可以$ C C是$,并想和大家分享的话,我会非常高兴,因为这是非常糟糕的,如果它看起来并不像同在所有设备上。 我没有与onGUI问题还没有,因为我没有做任何菜单什么的吧,只是游戏,但它是不好的背景是不是在设备上的相同,而字符是不是屏幕的相同部分

Bottom line: I would like to know if there's some code for Unity (C#) which will make my game looks like the same across all devices with different aspect ratios? I'm developing with Unity 2D. If anybody could code it and would like to share it, I would be very happy, because it is very bad if it doesn't look like same on all devices. I don't have the problem with onGUI yet, as I haven't did any menu or something for it, just the game, but it is not good that the background is not the same on devices, and that the character is not on the same portion of the screen.

推荐答案

在初始化,使用Camera.pixelRect确定高度和宽度的设备假设摄影机是全屏。

During init, use Camera.pixelRect to determine the Height and Width of the Device assuming the camera is fullscreen.

存储的高度和宽度,然后做一些数学与你的默认设置。 例如。默认设置是为480x854,pixelRect为800x1280。 因此,在宽度差为800F / 480F。做同样的高度。

Store the Height and Width and then do some math with your default settings. Eg. Default settings is 480x854, pixelRect is 800x1280. So difference in width is 800f/480f. Do the same for height.

使用的差,并将其乘到对象在层次结构的顶部。

Use the difference and multiply it to the object at the top of the hierarchy.

希望它帮助。

这篇关于如何显示的游戏在使用Unity Android设备各个方面比同一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆