UE4部分常用源码功能抽取及实现

Unreal版本4.19.2


功能& 源码编号对照表
场景&功能 关键源码编号 定义位置&头文件名 备注
Content Browser 中选择路径获取及是否导入合法判断
1
SContentBrowser.h  
点击按钮事件-打开选择文件夹 2

Engine\Source\Editor\DetailCustomizations\Private\AutoReimportDirectoryCustomization.cpp

注意不要重复包含GameplayTask.generated.h,否则编译出错

                                                                        源码编号&实现方法对照表

1
#include " SContentBrowser.h"

FText SContentBrowser::GetImportTooltipText() const
{
const FSourcesData& SourcesData = AssetViewPtr->GetSourcesData();
if ( SourcesData.PackagePaths.Num() == 1 )
{
const FString CurrentPath = SourcesData.PackagePaths[0].ToString();
if ( ContentBrowserUtils::IsClassPath( CurrentPath ) )
{
return LOCTEXT( "ImportAssetToolTip_InvalidClassPath", "Cannot import assets to class paths." );
}
else
{
return FText::Format( LOCTEXT( "ImportAssetToolTip", "Import to {0}..." ), FText::FromString( CurrentPath ) );
}
}
else if ( SourcesData.PackagePaths.Num() > 1 )
{
return LOCTEXT( "ImportAssetToolTip_MultiplePaths", "Cannot import assets to multiple paths." );
}

return LOCTEXT( "ImportAssetToolTip_NoPath", "No path is selected as an import target." );
}


2 #include "Editor/PropertyEditor/Public/PropertyHandle.h"
#include "Developer/DesktopPlatform/Public/IDesktopPlatform.h"
#include "Developer/DesktopPlatform/Public/DesktopPlatformModule.h"
#include "Runtime/Slate/Public/Framework/Application/SlateApplication.h"

//选择路径方法
FReply SWidgetDemoA::clickSelectButton()
{
//定义显示路径及初始化路径
FString filePath_str, InitialDir;

if (InitialDir.IsEmpty())
{
InitialDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir());
}
else if (!FPackageName::GetPackageMountPoint(InitialDir).IsNone())
{
InitialDir = FPaths::ConvertRelativePathToFull(FPackageName::LongPackageNameToFilename(InitialDir));
}

IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
if (DesktopPlatform)
{
FString FolderName;
const FString Title = LOCTEXT("BrowseForFolderTitle", "Choose a directory to monitor").ToString();
const bool bFolderSelected = DesktopPlatform->OpenDirectoryDialog(FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr), Title, InitialDir, FolderName);
if (bFolderSelected)
{
FolderName /= TEXT("");
filePath_str = FolderName;
}
}

filePath->SetText(FText::FromString(filePath_str));

UE_LOG(MyLog, Warning, TEXT("选择按钮被点击,文件路径为 %s"), *filePath_str);


return FReply::Handled();
}
 

猜你喜欢

转载自blog.csdn.net/qq_35221523/article/details/80254292