Last active
November 13, 2020 17:56
-
-
Save crssnky/d60e65f2b55909a1af17176f9e58f3d0 to your computer and use it in GitHub Desktop.
SObjectPropertyEntryBoxでActorアセットを選択する話のやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// crssnky | |
#include "BlueprintSelectBox.h" | |
#include "PropertyCustomizationHelpers.h" | |
UBlueprintSelectBox::UBlueprintSelectBox(const FObjectInitializer& ObjectInitializer) | |
: Super(ObjectInitializer) | |
{} | |
void UBlueprintSelectBox::GenerateWidget(UClass* targetClass) | |
{ | |
// reset | |
if (m_entryBox.IsValid()) | |
{ | |
m_entryBox.Reset(); | |
} | |
m_selected = nullptr; | |
// class | |
const auto targetClas_BP = UBlueprint::GetBlueprintFromClass(targetClass); | |
// widget | |
SAssignNew(m_entryBox, SObjectPropertyEntryBox) | |
.AllowedClass(targetClas_BP ? UBlueprint::StaticClass() : targetClass) | |
.OnShouldFilterAsset_Lambda([targetClas_BP](const FAssetData& assetData) | |
{ | |
if (targetClas_BP) | |
{ | |
const auto asset = Cast<UBlueprint>(assetData.GetAsset()); | |
if (asset) | |
{ | |
return !(asset->ParentClass->IsChildOf(targetClas_BP->ParentClass)); | |
} | |
else | |
{ | |
return true; | |
} | |
} | |
else | |
{ | |
return false; | |
} | |
}) | |
.ObjectPath_Lambda([this]()->FString const | |
{ | |
return m_selected ? m_selected->GetPathName() : TEXT(""); | |
}) | |
.OnObjectChanged_Lambda([this](const FAssetData& assetData) | |
{ | |
m_selected = Cast<UObject>(assetData.GetAsset()); | |
BlueprintSelectedDelegate.Broadcast(m_selected); | |
}); | |
SetContent(m_entryBox.ToSharedRef()); | |
} | |
FAssetData UBlueprintSelectBox::GetAssetData() const | |
{ | |
return m_selected; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// crssnky | |
#pragma once | |
#include "CoreMinimal.h" | |
#include "Components/NativeWidgetHost.h" | |
#include "BlueprintSelectBox.generated.h" | |
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FBlueprintSelected, const UObject*, selected); | |
class SObjectPropertyEntryBox; | |
/** | |
* | |
*/ | |
UCLASS() | |
class SKYATMOSPHERE_API UBlueprintSelectBox : public UNativeWidgetHost | |
{ | |
GENERATED_BODY() | |
public: | |
UBlueprintSelectBox(const FObjectInitializer& ObjectInitializer); | |
UFUNCTION(BlueprintCallable, Category = "MyPrj|UMG") | |
void GenerateWidget(UClass* targetClass); | |
UFUNCTION(BlueprintCallable, Category = "MyPrj|UMG") | |
FAssetData GetAssetData()const; | |
UPROPERTY(BlueprintReadWrite, Category = "MyPrj|UMG") | |
FBlueprintSelected BlueprintSelectedDelegate; | |
private: | |
TSharedPtr<SObjectPropertyEntryBox> m_entryBox = nullptr; | |
UObject* m_selected = nullptr; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
この スニペット は クリエイティブ・コモンズ 表示 4.0 国際 ライセンスの下に提供されているとする