Last active
May 15, 2019 04:59
-
-
Save eman41/051391a5c3bf85ccbcfc976dbc2a4f9e to your computer and use it in GitHub Desktop.
This is an Unreal Editor header for creating a simple templated details customization to reduce boilerplate.
This file contains hidden or 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
#pragma once | |
#include "CoreMinimal.h" | |
#include "IDetailCustomization.h" | |
#include "DetailLayoutBuilder.h" | |
template<typename CustomizedType, typename DetailsClass> | |
class FGenericDetails : public IDetailCustomization | |
{ | |
public: | |
static TSharedRef<IDetailCustomization> MakeInstance(); | |
virtual void CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) override; | |
virtual void LayoutCustomDetails(IDetailLayoutBuilder& DetailBuilder) | |
{ | |
}; | |
protected: | |
TWeakObjectPtr<CustomizedType> Selected; | |
}; | |
template <typename CustomizedType, typename DetailsClass> | |
void FGenericDetails<CustomizedType, DetailsClass>::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder) | |
{ | |
const TArray< TWeakObjectPtr<UObject> >& SelectedObjects = DetailBuilder.GetSelectedObjects(); | |
for( int32 ObjectIndex = 0; !Selected.IsValid() && ObjectIndex < SelectedObjects.Num(); ++ObjectIndex ) | |
{ | |
const TWeakObjectPtr<UObject>& CurrentObject = SelectedObjects[ObjectIndex]; | |
if ( CurrentObject.IsValid() ) | |
{ | |
Selected = Cast<CustomizedType>(CurrentObject.Get()); | |
} | |
} | |
if(Selected.IsValid()) | |
{ | |
LayoutCustomDetails(DetailBuilder); | |
} | |
} | |
template <typename CustomizedType, typename DetailsClass> | |
TSharedRef<IDetailCustomization> FGenericDetails<CustomizedType, DetailsClass>::MakeInstance() | |
{ | |
return MakeShareable(new DetailsClass); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment