// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_6 #include "CoreMinimal.h" #endif // UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_6 #include "Editor.h" #include "PropertyHandle.h" #define LOCTEXT_NAMESPACE "MassMovementEditor" namespace UE::MassMovement::PropertyUtils { // Expects T is struct. template TOptional GetValue(const TSharedPtr& ValueProperty) { if (!ValueProperty) { return TOptional(); } FStructProperty* StructProperty = CastFieldChecked(ValueProperty->GetProperty()); if (!StructProperty) { return TOptional(); } if (StructProperty->Struct != TBaseStructure::Get()) { return TOptional(); } T Value = T(); bool bValueSet = false; TArray RawData; ValueProperty->AccessRawData(RawData); for (void* Data : RawData) { if (Data) { T CurValue = *reinterpret_cast(Data); if (!bValueSet) { bValueSet = true; Value = CurValue; } else if (CurValue != Value) { // Multiple values return TOptional(); } } } return TOptional(Value); } // Expects T is struct. template void SetValue(TSharedPtr& ValueProperty, T NewValue, EPropertyValueSetFlags::Type Flags = 0) { if (!ValueProperty) { return; } FStructProperty* StructProperty = CastFieldChecked(ValueProperty->GetProperty()); if (!StructProperty) { return; } if (StructProperty->Struct != TBaseStructure::Get()) { return; } const bool bTransactable = (Flags & EPropertyValueSetFlags::NotTransactable) == 0; bool bNotifiedPreChange = false; TArray RawData; ValueProperty->AccessRawData(RawData); for (void* Data : RawData) { if (Data) { if (!bNotifiedPreChange) { if (bTransactable && GEditor) { GEditor->BeginTransaction(FText::Format(LOCTEXT("SetPropertyValue", "Set {0}"), ValueProperty->GetPropertyDisplayName())); } ValueProperty->NotifyPreChange(); bNotifiedPreChange = true; } T* Value = reinterpret_cast(Data); *Value = NewValue; } } if (bNotifiedPreChange) { ValueProperty->NotifyPostChange(EPropertyChangeType::ValueSet); if (bTransactable && GEditor) { GEditor->EndTransaction(); } } ValueProperty->NotifyFinishedChangingProperties(); } } // UE::MassMovement::PropertyUtils #undef LOCTEXT_NAMESPACE