看板 GameDesign 關於我們 聯絡資訊
網頁版 https://yekdniwue.blogspot.com/2021/03/BatchConsoleCmd.html 有的時候我們會想要執行一連串的console command,才能得到結果, 可是又不想要為這一串console command, 專門寫一個console command把他們集合起來。怎麼辦? 作法(只需要做一次) 把功能加在CheatManager 在你繼承的CheatManager.h加上函式 UFUNCTION(exec) void ExecComboCommand(const FString& ComboCommandName); 在你繼承的CheatManager.cpp實作函式 void UMyCheatManager::ExecComboCommand (const FString& ComboCommandName) { FConfigSection* CommandsToRun = GConfig->GetSectionPrivate (*ComboCommandName, false, true, GGameIni); if (!CommandsToRun) { return; } if (!IsValid(GetOuterAPlayerController())) { return; } for (FConfigSectionMap::TIterator It(*CommandsToRun); It; ++It) { GetOuterAPlayerController()-> ConsoleCommand(*It.Value().GetValue()); } } 使用組合指令 在ini裡面製作要批次執行的指令,例如在 [Project]\Saved\Config\Windows\Game.ini 新增 [Debug.ComboCommand1] +Cmds=stat fps +Cmds=stat unit (新增的時候請先關閉Editor,以免修改被Editor蓋掉) 如果要上平台也能測試,可能就要新增在 [Project]\Config\DefaultGame.ini 內不過記得最後要拔掉。 然後打開你的Editor或是執行目標平台的遊戲,先輸入 EnableCheats 再輸入 ExecComboCommand Debug.ComboCommand1 就成功了 優點 不用再記各個詳細的指令怎麼打,只要記別名就好 有很多的command不用一直重複輸入 不用怕指令忘記,因為ini會記得(除非刪掉) 靠字串組合,所以程式碼只要寫一次(一個函式),就能支援多種指令 ComboCommand1,ComboCommand2, ... 缺點 還是要執行EnableCheats 因為靠CheatManager,所以應該只能在Game中執行, 編輯模式不確定是否有效。 為了開發方便可能會想要記在 [Project]\Config\DefaultGame.ini ,最後要記得拔掉。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.166.44.144 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/GameDesign/M.1615017476.A.55B.html
metallican: 專業推 感謝分享 03/06 16:38
coolrobin: 推 03/06 18:14