Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SObjectPropertyEntryBoxでActorアセットを選択する話のやつ
// 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;
}
// 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;
};
@crssnky

This comment has been minimized.

Copy link
Owner Author

@crssnky crssnky commented Nov 13, 2020

クリエイティブ・コモンズ・ライセンス
この スニペット は クリエイティブ・コモンズ 表示 4.0 国際 ライセンスの下に提供されているとする

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.