当我真正尝试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
本视频中的这个家伙实施分辨率设置,试试看:https://www.youtube.com/watch?v=YOaYQrN1oYQ
所以,我不能重复你的问题 - 你的解决方案也可以正常工作
这是windows默认构建与您的代码:
尝试在播放器设置中查看“分辨率和演示文稿”
这是分辨率列表的源代码 - 统一只需从您的电脑中获取:
/// <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; }
这就是为什么只有一个解决方案 - 手动检查重复项并从列表中删除它