//反射UI UPROPERTY(meta = (BindWidget)) class UNamedSlot* InventoryWidgetSlot; //反射UI UPROPERTY(meta = (BindWidget)) class UHorizontalBox* GameButtonSlot;
加载Widget
UMainWidget* AInventorySystemHUD::GetMainWidget() { if (!MainWidget) { //加载指定模板类 TSubclassOf<UMainWidget>MainWidgetClass = LoadClass<UMainWidget> ( GetWorld(), TEXT("WidgetBlueprint'/Game/BluePrint/MainWidget_WBP.MainWidget_WBP_C'") //加载蓝图资源后缀_C ); check(MainWidgetClass && "MainWidgetClass == NULL"); //创建MainWidget MainWidget = CreateWidget<UMainWidget>(GetWorld(), MainWidgetClass); //添加到视口 MainWidget->AddToViewport(); } check(MainWidget && "MainWidget == NULL"); return MainWidget; }