问题
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?
回答1:
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:
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; } } }
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 ...).
来源:https://stackoverflow.com/questions/46396983/how-to-add-the-iphone-x-screen-dimensions-to-the-mix-of-different-iphone-dimensi