本文整理汇总了C++中FArchive::UseToResolveEnumerators方法的典型用法代码示例。如果您正苦于以下问题:C++ FArchive::UseToResolveEnumerators方法的具体用法?C++ FArchive::UseToResolveEnumerators怎么用?C++ FArchive::UseToResolveEnumerators使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FArchive
的用法示例。
在下文中一共展示了FArchive::UseToResolveEnumerators方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SerializeItem
/*-----------------------------------------------------------------------------
UByteProperty.
-----------------------------------------------------------------------------*/
void UByteProperty::SerializeItem( FArchive& Ar, void* Value, void const* Defaults ) const
{
if(Enum && Ar.UseToResolveEnumerators())
{
const int32 ResolvedIndex = Enum->ResolveEnumerator(Ar, *(uint8*)Value);
*(uint8*)Value = static_cast<uint8>(ResolvedIndex);
return;
}
// Serialize enum values by name unless we're not saving or loading OR for backwards compatibility
const bool bUseBinarySerialization = (Enum == NULL) || (!Ar.IsLoading() && !Ar.IsSaving());
if( bUseBinarySerialization )
{
Super::SerializeItem(Ar, Value, Defaults);
}
// Loading
else if (Ar.IsLoading())
{
FName EnumValueName;
Ar << EnumValueName;
// Make sure enum is properly populated
if( Enum->HasAnyFlags(RF_NeedLoad) )
{
Ar.Preload(Enum);
}
// There's no guarantee EnumValueName is still present in Enum, in which case Value will be set to the enum's max value.
// On save, it will then be serialized as NAME_None.
int32 EnumIndex = Enum->FindEnumIndex(EnumValueName);
if (EnumIndex == INDEX_NONE)
{
*(uint8*)Value = Enum->GetMaxEnumValue();
}
else
{
*(uint8*)Value = Enum->GetValueByIndex(EnumIndex);
}
}
// Saving
else
{
FName EnumValueName;
uint8 ByteValue = *(uint8*)Value;
// subtract 1 because the last entry in the enum's Names array
// is the _MAX entry
if ( Enum->IsValidEnumValue(ByteValue) )
{
EnumValueName = Enum->GetNameByValue(ByteValue);
}
else
{
EnumValueName = NAME_None;
}
Ar << EnumValueName;
}
}
示例2: ResolveEnumerator
int32 FEnumEditorUtils::ResolveEnumerator(const UEnum* Enum, FArchive& Ar, int32 EnumeratorIndex)
{
check(Ar.UseToResolveEnumerators());
const FArchiveEnumeratorResolver* EnumeratorResolver = (FArchiveEnumeratorResolver*)(&Ar);
if(Enum == EnumeratorResolver->Enum)
{
const auto& OldNames = EnumeratorResolver->OldNames;
if(EnumeratorIndex < OldNames.Num())
{
const FName EnumeratorName = OldNames[EnumeratorIndex].Key;
const int32 NewEnumIndex = Enum->FindEnumIndex(EnumeratorName);
if(INDEX_NONE != NewEnumIndex)
{
return NewEnumIndex;
}
}
return (Enum->NumEnums() - 1);
}
return EnumeratorIndex;
}
示例3: ResolveEnumerator
int32 FEnumEditorUtils::ResolveEnumerator(const UEnum* Enum, FArchive& Ar, int32 EnumeratorValue)
{
check(Ar.UseToResolveEnumerators());
const FArchiveEnumeratorResolver* EnumeratorResolver = (FArchiveEnumeratorResolver*)(&Ar);
if(Enum == EnumeratorResolver->Enum)
{
for (TPair<FName, uint8> OldName : EnumeratorResolver->OldNames)
{
if (OldName.Value == EnumeratorValue)
{
const FName EnumeratorName = OldName.Key;
const int32 NewEnumValue = Enum->GetValueByName(EnumeratorName);
if(INDEX_NONE != NewEnumValue)
{
return NewEnumValue;
}
}
}
return Enum->GetMaxEnumValue();
}
return EnumeratorValue;
}