Skip to content

Instantly share code, notes, and snippets.

@crssnky
Last active November 13, 2020 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crssnky/d60e65f2b55909a1af17176f9e58f3d0 to your computer and use it in GitHub Desktop.
Save crssnky/d60e65f2b55909a1af17176f9e58f3d0 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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