以PS设置启动参数为例:
2. 要在游戏中获取启动参数值,需要知道启动参数,保存的位置:
2.1 需要了解【Engine\Source\Runtime\Core\Public\Misc\CommandLine.h】/** * Returns an edited version of the executable's command line * with the game name and certain other parameters removed * 获取启动参数字符串. */ static const TCHAR* Get(); /** * Parses a string into tokens, separating switches (beginning with -) from * other parameters * 解析命令字符串 * * @param CmdLine the string to parse * @param Tokens [out] filled with all parameters found in the string * @param Switches [out] filled with all switches found in the string */ static void Parse(const TCHAR* CmdLine, TArray<FString>& Tokens, TArray<FString>& Switches);
- 使用方式
TArray<FString> Tokens; TArray<FString> Switches; FCommandLine::Parse(FCommandLine::Get(), Tokens, Switches);只需要解析Switches的字符串就可以获取,key与Value;在这里key:Dev,Value:PS4测试服;具体如何使用,由游戏决定