为什么我在内置设置菜单中构建游戏后没有获得正确的分辨率,但在编辑器中一切正常?统一
Why don't I get the right resolution after I build the game in my in-built settings menu but inside Editor everything is fine? Unity
当我在 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 使用您的代码的默认构建:
尝试在播放器设置中检查您的'Resolution and presentation'
这是解析列表的源代码 - Unity 只是从您的电脑上获取它:
/// <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; }
这就是为什么只有一种解决方案 - 手动检查重复项并将其从列表中删除
当我在 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 使用您的代码的默认构建:
尝试在播放器设置中检查您的'Resolution and presentation'
这是解析列表的源代码 - Unity 只是从您的电脑上获取它:
/// <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; }
这就是为什么只有一种解决方案 - 手动检查重复项并将其从列表中删除