zyo*_*neo 3 android screen-resolution unity-game-engine ios
我正在构建一个应用程序。我将我的参考分辨率游戏视图设置保留为 (800 x 1200)。画布设置如下所示
当我检查 Iphone6(750 x 1334) 分辨率时,我可以看到内容,但某些组件会根据宽度进行裁剪。游戏视图如下所示。我在我的应用程序中使用面板、垂直布局组、水平布局组许多 UI 组件。
现在我将我的游戏视图分辨率更改为 ipad pro(2224 x 1668)。现在我看不到我的图像。游戏视图如下所示

我不知道如何根据不同的屏幕尺寸调整 UI 元素。我观察到的一些答案是我应该将设置保持为按屏幕尺寸缩放,匹配宽度或高度并将滑块匹配到 0.5。我保留了这些设置(见第一张图片)。它仍然没有根据不同的屏幕尺寸而改变。
我在父元素(Showdata)中尝试了Aspect ratio fitter但没有用。根据不同的屏幕尺寸我应该怎么做来改变屏幕?是不是因为我没有以正确的方式锚定UI元素?你将如何锚定这样的东西(画布>面板(沿 XY 拉伸)>面板(垂直布局)>许多 UI 元素)
我看过很多关于如何将锚用于图像和按钮的教程,但如何用于嵌套元素,或者当我们使用垂直或水平布局并且它包含许多 UI 元素时。
以下是从最紧急到最不紧急的提示的简要列表:
RectTransform全屏对应的组件,将其锚点设置为(0, 0), (1, 1),即填充父级。与戏剧Top,Right等特性。但好像你已经知道了。LayoutElement并且在非滚动轴上通常应该具有固定大小,即,暂时不要ContentSizeFitter在行上使用,让它在固定高度下工作。无论如何,这几乎总是移动设备上的正确行为。LayoutElement的忽略布局标志。OnRectTransformDimensionsChanged(). 没有别的,不要检查中的变化Screen!您应该熟悉EventSystem一般情况。Camera.main.aspect这些纵横比在手动调整的布局之间正确切换。iOS中有4个。这是平台画布缩放器的示例:
using UnityEngine;
using UnityEngine.EventSystems;
#if UNITY_IPHONE
using UnityEngine.iOS;
#endif
using UnityEngine.UI;
namespace StackOverflow
{
[ExecuteInEditMode]
public sealed class PlatformCanvasScaler : UIBehaviour
{
public static PlatformCanvasScaler instance { get; private set; }
public float scaleFactor
{
get
{
if (m_CanvasScaler != null)
{
return m_CanvasScaler.scaleFactor;
}
return 1.0f;
}
}
[SerializeField] private CanvasScaler m_CanvasScaler;
[SerializeField] private float m_PhoneScaleFactor = 1.15f;
private PlatformCanvasScaler()
{
instance = this;
}
protected override void Awake()
{
base.Awake();
if (!enabled)
{
return;
}
Refresh();
}
private void Refresh()
{
var scaleFactor = 1f;
var isMobile = PlatformCanvasScaler.isMobile;
if (isMobile)
{
#if UNITY_IPHONE
switch (Device.generation)
{
case DeviceGeneration.iPhoneX:
case DeviceGeneration.iPhoneXSMax:
case DeviceGeneration.Unknown:
case DeviceGeneration.iPadUnknown:
case DeviceGeneration.iPodTouchUnknown:
scaleFactor = 3f;
break;
case DeviceGeneration.iPhone5:
case DeviceGeneration.iPhoneSE1Gen:
case DeviceGeneration.iPhone5C:
case DeviceGeneration.iPhone5S:
case DeviceGeneration.iPhone6:
case DeviceGeneration.iPhone6S:
case DeviceGeneration.iPhone7:
case DeviceGeneration.iPhone8:
case DeviceGeneration.iPhoneXR:
case DeviceGeneration.iPhoneUnknown:
scaleFactor = 2f;
break;
case DeviceGeneration.iPhone6Plus:
case DeviceGeneration.iPhone7Plus:
case DeviceGeneration.iPhone8Plus:
case DeviceGeneration.iPhone6SPlus:
scaleFactor = 3f / 1.15f;
break;
case DeviceGeneration.iPhone:
case DeviceGeneration.iPhone3G:
case DeviceGeneration.iPhone3GS:
case DeviceGeneration.iPad1Gen:
case DeviceGeneration.iPad2Gen:
case DeviceGeneration.iPad3Gen:
scaleFactor = 1f;
break;
default:
scaleFactor = 2f;
break;
}
scaleFactor *= m_PhoneScaleFactor;
#else
scaleFactor = 2f * Screen.dpi / 326f;
#endif
}
else
{
if (Screen.dpi > 140)
{
scaleFactor = 2.0f;
}
else
{
scaleFactor = 1.0f;
}
}
m_CanvasScaler.scaleFactor = scaleFactor;
}
public static bool isMobile
{
get
{
var isPhone = false;
#if UNITY_IPHONE
isPhone = true;
#endif
var isMobile = Application.platform == RuntimePlatform.IPhonePlayer ||
(Application.isEditor && isPhone);
return isMobile;
}
}
#if UNITY_EDITOR
private void OnValidate()
{
Refresh();
}
#endif
// Update is called once per frame
private void Update()
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
观察我对什么被认为是 HiDPI 设备做出了一些决定。
不幸的是,我最喜欢的用于屏幕管理的 UI 资产MaterialUI已弃用。希望有人可以评论他们与他人的经历。