AimSim 代码学习记录

逃离我推掉我的手 2022-11-11 05:48 163阅读 0赞

1、获得UClass方法:

  1. #include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h"
  2. static ConstructorHelpers::FClassFinder<UUserWidget> hud_widget_class(TEXT("WidgetBlueprint'/AirSim/Blueprints/BP_SimHUDWidget'"));
  3. UClass* widget_class_ = hud_widget_class.Succeeded() ? hud_widget_class.Class : nullptr;

2、生成Widget

  1. USimHUDWidget* widget_ = CreateWidget<USimHUDWidget>(player_controller, widget_class_);
  2. widget_->AddToViewport();

3、创建对话框

  1. UAirBlueprintLib::ShowMessage(EAppMsgType::Ok, std::string("Error at startup: ") + ex.what(), "Error");
  2. EAppReturnType::Type UAirBlueprintLib::ShowMessage(EAppMsgType::Type message_type, const std::string& message, const std::string& title)
  3. {
  4. FText title_text = FText::FromString(title.c_str());
  5. return FMessageDialog::Open(message_type,
  6. FText::FromString(message.c_str()),
  7. &title_text);
  8. }

4、代码方式执行console,设置参数。

  1. //use two different methods to set console var because sometime it doesn't seem to work
  2. static const auto custom_depth_var = IConsoleManager::Get().FindConsoleVariable(TEXT("r.CustomDepth"));
  3. custom_depth_var->Set(3);
  4. //Equivalent to enabling Custom Stencil in Project > Settings > Rendering > Postprocessing
  5. UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(), FString("r.CustomDepth 3"));
  6. //during startup we init stencil IDs to random hash and it takes long time for large environments
  7. //we get error that GameThread has timed out after 30 sec waiting on render thread
  8. static const auto render_timeout_var = IConsoleManager::Get().FindConsoleVariable(TEXT("g.TimeoutForBlockOnRenderFence"));
  9. render_timeout_var->Set(300000);

5、代码方式开启GameViewport()的各项参数。

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NoMTUyODUxMTg1ODY_size_16_color_FFFFFF_t_70

  1. GetWorld()->GetGameViewport()->GetEngineShowFlags()->SetMotionBlur(false);

6、屏幕输出:

  1. UENUM(BlueprintType)
  2. enum class LogDebugLevel : uint8 {
  3. Informational UMETA(DisplayName = "Informational"),
  4. Success UMETA(DisplayName = "Success"),
  5. Failure UMETA(DisplayName = "Failure"),
  6. Unimportant UMETA(DisplayName = "Unimportant")
  7. };
  8. void UAirBlueprintLib::LogMessage(const FString &prefix, const FString &suffix, LogDebugLevel level, float persist_sec)
  9. {
  10. if (log_messages_hidden_)
  11. return;
  12. static TMap<FString, int> loggingKeys;
  13. static int counter = 1;
  14. int key = loggingKeys.FindOrAdd(prefix);
  15. if (key == 0) {
  16. key = counter++;
  17. loggingKeys[prefix] = key;
  18. }
  19. FColor color;
  20. switch (level) {
  21. case LogDebugLevel::Informational:
  22. color = FColor(147, 231, 237);
  23. //UE_LOG(LogTemp, Log, TEXT("%s%s"), *prefix, *suffix);
  24. break;
  25. case LogDebugLevel::Success:
  26. color = FColor(156, 237, 147);
  27. //UE_LOG(LogTemp, Log, TEXT("%s%s"), *prefix, *suffix);
  28. break;
  29. case LogDebugLevel::Failure:
  30. color = FColor(237, 147, 168);
  31. //UE_LOG(LogAirSim, Error, TEXT("%s%s"), *prefix, *suffix);
  32. break;
  33. case LogDebugLevel::Unimportant:
  34. color = FColor(237, 228, 147);
  35. //UE_LOG(LogTemp, Verbose, TEXT("%s%s"), *prefix, *suffix);
  36. break;
  37. default: color = FColor::Black; break;
  38. }
  39. if (GEngine) {
  40. GEngine->AddOnScreenDebugMessage(key, persist_sec, color, prefix + suffix);
  41. }
  42. //GEngine->AddOnScreenDebugMessage(key + 10, 60.0f, color, FString::FromInt(key));
  43. }

7, 遍历world中所有Actor,并挑选目标Actor

  1. typedef AUrdfBotPawn TVehiclePawn;
  2. void ASimModeUrdfBot::getExistingVehiclePawns(TArray<AirsimVehicle*>& pawns) const
  3. {
  4. for (TActorIterator<TVehiclePawn> it(this->GetWorld()); it; ++it)
  5. {
  6. pawns.Add(static_cast<AirsimVehicle*>(*it));
  7. }
  8. }

发表评论

表情:
评论列表 (有 0 条评论,163人围观)

还没有评论,来说两句吧...

相关阅读

    相关 VINS-Mono代码学习记录(一)

    写在前面的话 看代码真是一个令人头疼的过程,由于代码量很大,而脑子又不够使,看了总是忘,忘了又接着看,所以还是决定写博客来记录一下这个过程,也方便自己日后回忆是咋学的,哈