在我的内置设置菜单中构建游戏后,为什么我没有得到正确的分辨率,但在编辑器内部一切正常?统一

问题描述 投票:0回答:1

当我真正尝试Unity内部的游戏时,一切都很好。当我构建游戏并尝试它时,每个分辨率显示两次并且它们被反转(例如:1920 x 1080是320 x 200,1680 x 1050是320 x 240,依此类推)。我会在这里给你我的代码:

public Dropdown resolutiondropdown;
 Resolution[] resolutions;
 void Start()
 {
     resolutions = Screen.resolutions;
     resolutiondropdown.ClearOptions();
     int currentresolutionindex = 0;
     List<string> options = new List<string>();
     for(int i=resolutions.Length-1;i>=0;i--)
     {
         string option = resolutions[i].width + " x " + resolutions[i].height;
         options.Add(option);
         if (resolutions[i].width == Screen.width && resolutions[i].height == Screen.height)
             currentresolutionindex = i;
     }
     resolutiondropdown.AddOptions(options);
     resolutiondropdown.value = currentresolutionindex;
     resolutiondropdown.RefreshShownValue();
 }
 public void SetResolution(int resolutionindex)
 {
     Resolution resolution = resolutions[resolutionindex];
     Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
 }

我拍了一张截图:Settings menu

unity3d build resolution
1个回答
0
投票

本视频中的这个家伙实施分辨率设置,试试看:https://www.youtube.com/watch?v=YOaYQrN1oYQ

所以,我不能重复你的问题 - 你的解决方案也可以正常工作

这是windows默认构建与您的代码:

screenshot

尝试在播放器设置中查看“分辨率和演示文稿”

这是分辨率列表的源代码 - 统一只需从您的电脑中获取:

/// <summary>
///   <para>All full-screen resolutions supported by the monitor (Read Only).</para>
/// </summary>
public static extern Resolution[] resolutions { [FreeFunction("ScreenScripting::GetResolutions"), MethodImpl(MethodImplOptions.InternalCall)] get; }

这就是为什么只有一个解决方案 - 手动检查重复项并从列表中删除它

© www.soinside.com 2019 - 2024. All rights reserved.