为屏幕分辨率传递命令行参数
Passing command line argument for screen resolution
我正在尝试通过命令提示符打开我的 Unity 应用程序。我想传递宽度和高度,以便它可以在该分辨率下打开。我正在使用 Screen.SetResolution() 但我不知道如何传递参数:
// Use this for initialization
void Awake()
{
Screen.SetResolution(h, w, false);
}
命令行 - UnityApp.exe -screen-width 800 -screen-height 570 -screen-fullscreen 0
您应该能够通过以下使用 System.Environment.CommandLine & System.Environment.CommandLineArgs:
获取应用程序命令行参数
string[] args = System.Environment.GetCommandLineArgs();
int widthInput;
int heightInput;
for (int i = 0; i < args.Length; i++)
{
Debug.Log("ARG " + i + ": " + args[i]);
if (args[i] == "-screen-width")
{
int.TryParse(args[i+1], out widthInput);
} else if(args[i] == "-screen-height") {
int.TryParse(args[i+1], out heightInput);
}
}
if(heightInput != null && widthInput!=null)
Screen.SetResolution(heightInput , widthInput, false);
这是根据您的需要重新调整的 link 源代码:https://answers.unity.com/questions/138715/read-command-line-arguments.html
希望对您有所帮助!
我正在尝试通过命令提示符打开我的 Unity 应用程序。我想传递宽度和高度,以便它可以在该分辨率下打开。我正在使用 Screen.SetResolution() 但我不知道如何传递参数:
// Use this for initialization
void Awake()
{
Screen.SetResolution(h, w, false);
}
命令行 - UnityApp.exe -screen-width 800 -screen-height 570 -screen-fullscreen 0
您应该能够通过以下使用 System.Environment.CommandLine & System.Environment.CommandLineArgs:
获取应用程序命令行参数 string[] args = System.Environment.GetCommandLineArgs();
int widthInput;
int heightInput;
for (int i = 0; i < args.Length; i++)
{
Debug.Log("ARG " + i + ": " + args[i]);
if (args[i] == "-screen-width")
{
int.TryParse(args[i+1], out widthInput);
} else if(args[i] == "-screen-height") {
int.TryParse(args[i+1], out heightInput);
}
}
if(heightInput != null && widthInput!=null)
Screen.SetResolution(heightInput , widthInput, false);
这是根据您的需要重新调整的 link 源代码:https://answers.unity.com/questions/138715/read-command-line-arguments.html
希望对您有所帮助!