简体   繁体   English

如何在 Unity 中为 Windows 构建设置纵向纵横比

[英]How to set portrait aspect ratio for Windows build in Unity

I'm trying to build a unity project for standalone and the game is in portrait configuration.我正在尝试为独立构建一个统一项目,并且游戏处于纵向配置。 Everything works fine when I test it in the editor, but when I build it, everything UI related is messed up and by that I mean it tries to fit to the screen's aspect ratio causing many buttons and UI elements to be off-screen despite even manually trying to change the screen size by doing Screen.SetResolution(1080, 1920, false);当我在编辑器中测试它时一切正常,但是当我构建它时,所有与 UI 相关的东西都搞砸了,我的意思是它试图适应屏幕的纵横比,导致许多按钮和 UI 元素在屏幕外,尽管即使通过执行Screen.SetResolution(1080, 1920, false);手动尝试更改屏幕尺寸Screen.SetResolution(1080, 1920, false); and stopping the game from entering full-screen mode in the build settings so that it would become a portrait aspect ratio but nothing is working.并在构建设置中阻止游戏进入全屏模式,使其成为纵向纵横比,但没有任何效果。 The game itself is working fine which is not a part of UI or any canvas obviously.游戏本身运行良好,这显然不是 UI 或任何画布的一部分。 Any help would be much appreciated!任何帮助将非常感激!

UI scaling is tricky particularly is you have different aspect ratios, and also if you have different resolutions ( although they are different ). UI 缩放很棘手,特别是当您有不同的纵横比,并且如果您有不同的分辨率(尽管它们不同)。 The most important things from my experience are making sure you've anchored things as reasonably as you can, used layout groups for dynamic content (dropdowns, instantiated elements, etc.) and used the CanvasScaler component on your canvas.根据我的经验,最重要的事情是确保您尽可能合理地锚定事物,将布局组用于动态内容(下拉列表、实例化元素等)并在画布上使用CanvasScaler组件。

The Canvas Scaler component can be found on your canvas object in the scene, and is the first place to start when dealing with variable screen sizes. Canvas Scaler 组件可以在场景中的画布对象上找到,并且是处理可变屏幕尺寸时的第一个起点。 “缩放到屏幕大小”选项在 Unity 检查器选项卡中的 Canvas Scaler 组件上突出显示。 . . This mode is the best for variable screen sizes, you can set this up to be your preferred screen size and then make your UI fit that size, then automatically scale based on your ideal size.此模式最适合可变屏幕尺寸,您可以将其设置为您喜欢的屏幕尺寸,然后让您的 UI 适合该尺寸,然后根据您的理想尺寸自动缩放。

It's hard to say what is the best way to anchor your UI elements generally speaking, but if you don't want them centred on the middle of the screen it likely isn't the default.很难说一般来说锚定 UI 元素的最佳方式是什么,但如果您不希望它们居中在屏幕中间,这可能不是默认设置。 I often find anchoring the sides of an area, or corners, is best.我经常发现锚定区域的侧面或角落是最好的。

Finally, depending on your platform and handled screen orientations, you can also set device orientation preferences in Player Preferences .最后,根据您的平台和处理的屏幕方向,您还可以在Player Preferences 中设置设备方向首选项 在此处输入图片说明 . . Exactly what you set may depend on your project, but can be an important step in making sure your UI scales correctly for you targets.您设置的确切内容可能取决于您的项目,但可能是确保您的 UI 针对您的目标正确缩放的重要步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用自定义纵横比统一构建项目? - How to build project in unity with custom aspect ratio? 我应该如何在 Unity c# 中保持纵横比并将 3D 对象设置为在所选纵横比的纵横比内缩放? - How should I Maintain aspect ratio in Unity c# and set the 3D object to scale within the aspect ratio of the selected aspect ratio? 如何在Windows 10通用APP中设置相机分辨率纵横比16; 9 - How to set a Camera Resolution Aspect Ratio 16;9 in Windows 10 Universal APP 如何在Unity 3D中控制相机的宽高比 - How to contol camera aspect ratio in Unity 3D Unity)我怎样才能保持精灵的纵横比? - Unity) How can I maintain sprites aspect ratio? 如何在Unity中拉伸某些东西而又不损失宽高比? - How to stretch something in Unity without losing the aspect ratio? 如何根据场景在统一游戏视图窗口中更改宽高比 - How to change aspect ratio in unity game view window depending on scene 如何使用 C# 更改 Windows 媒体播放器的纵横比 - How to change the aspect ratio of an Windows media player by using C# 如何在不运行Windows运行时保留纵横比的情况下实现压缩变焦? - How implement pinch zoom without preserving aspect ratio in windows runtime? 将 android 应用程序构建为一个统一的独立应用程序(在 PC 上使用),同时保持正确的纵横比 - Build android app as a unity stand-alone (for use on a PC) while maintaining correct aspect ratio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM