如何调整纵向和横向模式的屏幕,以便可以看到所有 UI 个元素?
How to adjust the screen for portrait and landscape mode such that all UI elements can be seen?
我正在构建一个 app.I 将我的参考分辨率游戏视图设置保持为 (800 x 1200)。canvas 的设置如下所示
当我检查 Iphone6(750 x 1334) 分辨率时,我可以看到内容,但某些组件相对于 width.The 游戏视图被裁剪如下所示。我在我的应用程序中使用面板、垂直布局组、水平布局组许多 UI 组件。
现在我将我的游戏视图分辨率更改为 ipad pro(2224 x 1668)。现在我看不到我的 images.The 游戏视图如下所示
我不知道如何根据不同的屏幕调整 UI 元素 sizes.Some 我观察到的答案是我应该将设置保持为随屏幕尺寸缩放、匹配宽度或高度和匹配滑块到 0.5。我保留了这些设置(见第一张图片)。仍然没有根据不同的屏幕尺寸而改变。
我在父元素(Showdata)中尝试了 Aspect ratio fitter 但没有 use.What 我应该根据不同的屏幕尺寸更改屏幕吗?是因为我没有锚定 UI 元素以适当的方式?
你将如何锚定这样的东西(Canvas>面板(沿 XY 拉伸)>面板(垂直布局)>许多 UI 元素)
我看过很多关于如何为图像和按钮使用锚点的教程,但是如何为嵌套元素使用锚点,或者当我们使用垂直或水平布局并且它包含许多 UI 元素时。
每个 UI 元素的矩形变换如下所示。
这是一个简短的提示列表,从最紧急到最不紧急:
- 将您的 canvas 缩放设置为恒定物理尺寸。在 iPhone X 设备上,比例因子是 3x。 Find other physical scale factors here。这样做的目的是使您的 Canvas 的布局坐标与设备点相对应,同时以设备的原始分辨率进行渲染。这是你痛苦的最紧迫的来源。
- 对于全屏对应的
RectTransform
个组件,将它的anchor设置为(0, 0)
,(1, 1
),即填充父级。使用 Top
、Right
等属性。不过你好像已经知道了。
- 垂直/水平布局组的子元素应该有一个
LayoutElement
并且通常在非滚动轴上具有固定大小,即现在不要在行上使用 ContentSizeFitter
,让它在固定高度工作。无论如何,这在移动设备上几乎总是正确的行为。
- 试验
LayoutElement
的 Ignore Layout 标志。
- 正确设置纹理上的每单位像素设置。
- 在移动设备上,您会错过角落中的切口和斜角等问题。使用 NotchSolution for Unity 2019.2 and earlier, and the new Device Simulator 2019.3 及更高版本,以可视化和适应这些问题。
- 使用回收滚动视图组件,例如Optimized ScrollView Adapter。这还将包括有关如何布局的深思熟虑的教程。如果您在回收滚动视图中需要内容适合高度的元素,您将需要此资源。
- 要通常根据屏幕布局触发更改,请使用
OnRectTransformDimensionsChanged()
。 没有别的,不要检查Screen
中的变化!您应该大致熟悉 EventSystem
。
- 熟悉各种设备的纵横比,并使用
Camera.main.aspect
在针对这些纵横比的手动调整布局之间正确切换。 iOS. 中有4个
这是一个平台 canvas 缩放器的示例:
using UnityEngine;
using UnityEngine.EventSystems;
#if UNITY_IPHONE
using UnityEngine.iOS;
#endif
using UnityEngine.UI;
namespace Whosebug
{
[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()
{
}
}
}
观察我对什么是 HiDPI 设备做出了一些决定。
不幸的是,我最喜欢的 UI 屏幕管理资产 MaterialUI
已弃用。希望有人可以评论他们与他人的经历。
我正在构建一个 app.I 将我的参考分辨率游戏视图设置保持为 (800 x 1200)。canvas 的设置如下所示
现在我将我的游戏视图分辨率更改为 ipad pro(2224 x 1668)。现在我看不到我的 images.The 游戏视图如下所示
我不知道如何根据不同的屏幕调整 UI 元素 sizes.Some 我观察到的答案是我应该将设置保持为随屏幕尺寸缩放、匹配宽度或高度和匹配滑块到 0.5。我保留了这些设置(见第一张图片)。仍然没有根据不同的屏幕尺寸而改变。
我在父元素(Showdata)中尝试了 Aspect ratio fitter 但没有 use.What 我应该根据不同的屏幕尺寸更改屏幕吗?是因为我没有锚定 UI 元素以适当的方式? 你将如何锚定这样的东西(Canvas>面板(沿 XY 拉伸)>面板(垂直布局)>许多 UI 元素)
我看过很多关于如何为图像和按钮使用锚点的教程,但是如何为嵌套元素使用锚点,或者当我们使用垂直或水平布局并且它包含许多 UI 元素时。
每个 UI 元素的矩形变换如下所示。
这是一个简短的提示列表,从最紧急到最不紧急:
- 将您的 canvas 缩放设置为恒定物理尺寸。在 iPhone X 设备上,比例因子是 3x。 Find other physical scale factors here。这样做的目的是使您的 Canvas 的布局坐标与设备点相对应,同时以设备的原始分辨率进行渲染。这是你痛苦的最紧迫的来源。
- 对于全屏对应的
RectTransform
个组件,将它的anchor设置为(0, 0)
,(1, 1
),即填充父级。使用Top
、Right
等属性。不过你好像已经知道了。 - 垂直/水平布局组的子元素应该有一个
LayoutElement
并且通常在非滚动轴上具有固定大小,即现在不要在行上使用ContentSizeFitter
,让它在固定高度工作。无论如何,这在移动设备上几乎总是正确的行为。 - 试验
LayoutElement
的 Ignore Layout 标志。 - 正确设置纹理上的每单位像素设置。
- 在移动设备上,您会错过角落中的切口和斜角等问题。使用 NotchSolution for Unity 2019.2 and earlier, and the new Device Simulator 2019.3 及更高版本,以可视化和适应这些问题。
- 使用回收滚动视图组件,例如Optimized ScrollView Adapter。这还将包括有关如何布局的深思熟虑的教程。如果您在回收滚动视图中需要内容适合高度的元素,您将需要此资源。
- 要通常根据屏幕布局触发更改,请使用
OnRectTransformDimensionsChanged()
。 没有别的,不要检查Screen
中的变化!您应该大致熟悉EventSystem
。 - 熟悉各种设备的纵横比,并使用
Camera.main.aspect
在针对这些纵横比的手动调整布局之间正确切换。 iOS. 中有4个
这是一个平台 canvas 缩放器的示例:
using UnityEngine;
using UnityEngine.EventSystems;
#if UNITY_IPHONE
using UnityEngine.iOS;
#endif
using UnityEngine.UI;
namespace Whosebug
{
[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()
{
}
}
}
观察我对什么是 HiDPI 设备做出了一些决定。
不幸的是,我最喜欢的 UI 屏幕管理资产 MaterialUI
已弃用。希望有人可以评论他们与他人的经历。