如何在Unity中将iPhone X屏幕尺寸添加到不同iPhone尺寸的混合中 [英] How to add the iPhone X screen dimensions to the mix of different iPhone dimensions in Unity

查看:152
本文介绍了如何在Unity中将iPhone X屏幕尺寸添加到不同iPhone尺寸的混合中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常为Unity工作,我在Illustrator中设计所有作品.因此,我首先使用1440x1920(用于肖像游戏)并勾勒出1080x1920的红色框.因此,对于我来说,非常适合1080x1920的所有内容都涵盖了iOS设备系列.然后,将所有图像的像素单位"设置为192.这种方法确实很好地为我服务.现在有了iPhone X,我该如何以类似的方式迎合它呢?

Generally for Unity I design all my artwork in Illustrator. So I start off with 1440x1920 (for portrait games) and outline a red frame of 1080x1920. So everything that fits well within the 1080x1920 usually covers the family of iOS devices for me. Then I set the Pixels Per Unit to 192 for all my images. This approach has really served me well. Now that the iPhone X is in the mix, how can I cater for it in a similar way?

推荐答案

根据我的经验,您不必做很多事情,场景中的游戏对象恰好适合您,Unity会为您做到这一点如果您使用的是UGUI,您可能需要做的就是调整UI画布,这也很容易,为什么?因为大多数手机的宽高比都差不多,所以在我们的团队中,我们会像这样进行修复:

As My experience, you don't have to do many things, the gameobject in a scene will just fit well, Unity has done that for you the only thing you maybe need to do is adjust the UI canvas if you are using UGUI, and it pretty easy too, why? because most phones have the similar width/height ratio, and in our team, we do the fix thing like this:

  1. 基于1080p(1080x1920)设计所有UI内容(也可以使用720p,但我们认为将来会有更多1080p设备)

  1. design all the UI stuff based on 1080p(1080x1920) (720p is fine too, but we presume there will be more 1080p device in the future)

将以下脚本附加到所有画布上以进行自动修复:

attach following scripts to all the canvas to make an auto-fix thing:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CanvasScreenAutoFix : MonoBehaviour
{
    public static CanvasScreenAutoFix instance;

    private static float DEPEND_W = 1080;
    private static float DEPEND_H = 1920;

    public float scaleRatio = 1.0f;


    private void ResizeCanvas()
    {
        int screenW = Screen.width;
        int screenH = Screen.height;
        if (DEPEND_W == screenW && DEPEND_H == screenH)
        {
            scaleRatio = 1.0f;
            return;
        }
        else
        {
            float W_scale = screenW / (float)DEPEND_W;
            float H_scale = screenH / (float)DEPEND_H;
            float scale = W_scale < H_scale ? W_scale : H_scale;

            GetComponent<CanvasScaler>().scaleFactor = scale;

            scaleRatio = scale;
        }
    }

    private void Awake()
    {
        ResizeCanvas();
        if(instance == null)
       {
           instance = this;
       }
    }

}

结果变得非常好,实际上,此后我们不必再担心iPhone系列的缩放问题了(iphone4可能存在一些问题,因为它们的宽高比不同,但是几乎没有那种设备了……).

And the result turns to be pretty well, actually, we don't have to care about the scale things with the iPhone Family anymore after this(there may be some issue with iphone4 cause they have a different aspect ratio, but as there a rarely that devices anymore ...).

这篇关于如何在Unity中将iPhone X屏幕尺寸添加到不同iPhone尺寸的混合中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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