You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
Moved SmartObjects out of restricted folder Moved StateTree out of restricted folder Moved ZoneGraph out of restricted folder Moved ZoneGraphAnnotations out of restricted folder #jira UE-115297 #ROBOMERGE-OWNER: mieszko.zielinski #ROBOMERGE-AUTHOR: mieszko.zielinski #ROBOMERGE-SOURCE: CL 17648223 via CL 17648246 via CL 17648261 via CL 17648385 via CL 17648390 via CL 17648742 #ROBOMERGE-BOT: STARSHIP (Release-Engine-Test -> Main) (v875-17642767) [CL 17648750 by mieszko zielinski in ue5-main branch]
120 lines
2.5 KiB
C++
120 lines
2.5 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
#pragma once
|
|
#include "CoreMinimal.h"
|
|
#include "PropertyEditorModule.h"
|
|
#include "Editor.h"
|
|
#include "ZoneGraphTypes.h"
|
|
#include "Misc/Guid.h"
|
|
|
|
class IPropertyHandle;
|
|
|
|
#define LOCTEXT_NAMESPACE "ZoneGraphEditor"
|
|
|
|
namespace UE::ZoneGraph::PropertyUtils
|
|
{
|
|
|
|
// Expects T is struct.
|
|
template<typename T>
|
|
TOptional<T> GetValue(const TSharedPtr<IPropertyHandle>& ValueProperty)
|
|
{
|
|
if (!ValueProperty)
|
|
{
|
|
return TOptional<T>();
|
|
}
|
|
|
|
FStructProperty* StructProperty = CastFieldChecked<FStructProperty>(ValueProperty->GetProperty());
|
|
if (!StructProperty)
|
|
{
|
|
return TOptional<T>();
|
|
}
|
|
if (StructProperty->Struct != TBaseStructure<T>::Get())
|
|
{
|
|
return TOptional<T>();
|
|
}
|
|
|
|
T Value = T();
|
|
bool bValueSet = false;
|
|
|
|
TArray<void*> RawData;
|
|
ValueProperty->AccessRawData(RawData);
|
|
for (void* Data : RawData)
|
|
{
|
|
if (Data)
|
|
{
|
|
T CurValue = *reinterpret_cast<T*>(Data);
|
|
if (!bValueSet)
|
|
{
|
|
bValueSet = true;
|
|
Value = CurValue;
|
|
}
|
|
else if (CurValue != Value)
|
|
{
|
|
// Multiple values
|
|
return TOptional<T>();
|
|
}
|
|
}
|
|
}
|
|
|
|
return TOptional<T>(Value);
|
|
}
|
|
|
|
// Expects T is struct.
|
|
template<typename T>
|
|
void SetValue(TSharedPtr<IPropertyHandle>& ValueProperty, T NewValue, EPropertyValueSetFlags::Type Flags = 0)
|
|
{
|
|
if (!ValueProperty)
|
|
{
|
|
return;
|
|
}
|
|
|
|
FStructProperty* StructProperty = CastFieldChecked<FStructProperty>(ValueProperty->GetProperty());
|
|
if (!StructProperty)
|
|
{
|
|
return;
|
|
}
|
|
if (StructProperty->Struct != TBaseStructure<T>::Get())
|
|
{
|
|
return;
|
|
}
|
|
|
|
const bool bTransactable = (Flags & EPropertyValueSetFlags::NotTransactable) == 0;
|
|
bool bNotifiedPreChange = false;
|
|
TArray<void*> 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<T*>(Data);
|
|
*Value = NewValue;
|
|
}
|
|
}
|
|
|
|
if (bNotifiedPreChange)
|
|
{
|
|
ValueProperty->NotifyPostChange(EPropertyChangeType::ValueSet);
|
|
if (bTransactable && GEditor)
|
|
{
|
|
GEditor->EndTransaction();
|
|
}
|
|
}
|
|
|
|
ValueProperty->NotifyFinishedChangingProperties();
|
|
}
|
|
|
|
FLinearColor GetMaskColor(TSharedPtr<IPropertyHandle> MaskProperty);
|
|
FText GetMaskDescription(TSharedPtr<IPropertyHandle> MaskProperty);
|
|
|
|
} // UE::ZoneGraph::PropertyUtils
|
|
|
|
#undef LOCTEXT_NAMESPACE |