UE4筆記-系統對話框相關功能記錄和使用方法(打開/保存文件對話框系統對話框等等...)


(當前最新版本4.24)

 

UE4其實是有實現對話框打開保存等的相關的功能的,都在‘DesktopPlatform’ Module中..

但是‘DesktopPlatform’ Module屬於Developer模塊,是無法打包出ship ping程序包的...

會報錯:

  Error:Missing precompiled manifest for 'DesktopPlatform'

 

 

所以想在生產環境中使用該模塊需要自己整改一下Module的(突然想口吐芬芳~)

 

------------------------------------------------------------------------------------------------

 

整理步驟記錄:

在Engine\Source\Developer 找到DesktopPlatform和SlateFileDialogs(DesktopPlatform的依賴,也是屬於Developer)文件夾..

然后將其復制粘貼到自己Project(插件里也可以)的Source中..

再修改掉DesktopPlatform和SlateFileDialogs的Module名稱並builds裝載即可(防止模塊重名,不好區分),例如改成DesktopPlatformEx和SlateFileDialogsEx

 需要注意一下Build.cs 的PrivateIncludePaths路徑

------------------------------------------------------------------------------------------------

 

DesktopPlatform模塊的簡單使用示例(打開文件對話框):

FString UCommonBPLibrary::OpenFileDialog()
{
    void* ParentWindowPtr = FSlateApplication::Get().GetActiveTopLevelWindow()->GetNativeWindow()->GetOSWindowHandle();
    IDesktopPlatform* DesktopPlatform = FDesktopPlatformModuleEx::Get();

    FJsonSerializableArray OutFileNames;

    if (DesktopPlatform)
    {

        EFileDialogFlags::Type SelectionFlag = EFileDialogFlags::None; 
        //A value of 0 represents single file selection while a value of 1 represents multiple file selection
        DesktopPlatform->OpenFileDialog( ParentWindowPtr, 
                                         TEXT( "選取一張圖片" ), 
                                         TEXT( "/" ), 
                                         TEXT( "" ), 
                                         TEXT( "(Image Files)|*.BMP;*.JPG;*.PNG;*.JPEG;)" ), 
                                         SelectionFlag ,
                                         OutFileNames );

    }


    if (OutFileNames.Num() > 0)
    {
        return FString (OutFileNames[0]);
    }
    else 
    {
        return TEXT("");
    }  
}

TArray<FString> UCommonBPLibrary::OpenFileDialogMultiple()
{
    TArray<FString> ret_arr;

    void* ParentWindowPtr = FSlateApplication::Get().GetActiveTopLevelWindow()->GetNativeWindow()->GetOSWindowHandle();
    IDesktopPlatform* DesktopPlatform = FDesktopPlatformModuleEx::Get();

    FJsonSerializableArray OutFileNames;

    if (DesktopPlatform)
    {
        EFileDialogFlags::Type SelectionFlag = EFileDialogFlags::Multiple;
        //A value of 0 represents single file selection while a value of 1 represents multiple file selection
        DesktopPlatform->OpenFileDialog(ParentWindowPtr,
            TEXT("選取圖片"),
            TEXT("/"),
            TEXT(""),
            TEXT("(Image Files)|*.BMP;*.JPG;*.PNG;*.JPEG;)"),
            SelectionFlag,
            OutFileNames);
    }

    for (int i = 0; i < OutFileNames.Num(); i++) 
    {
        ret_arr.Add(FString(OutFileNames[i]));
    }

    return ret_arr;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM