add version converter for editor transform to handle migration to uniform scale

main
greerdv 5 years ago
parent 0577c0f0dd
commit fc0a720468

@ -170,6 +170,23 @@ namespace AzToolsFramework
return true;
}
bool EditorTransformDataConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement)
{
if (classElement.GetVersion() < 3)
{
// version 3 replaces vector scale with uniform scale but does not yet delete the legacy scale data
// in order to allow for migration
AZ::Vector3 vectorScale;
if (classElement.FindSubElementAndGetData<AZ::Vector3>(AZ_CRC_CE("Scale"), vectorScale))
{
const float uniformScale = vectorScale.GetMaxElement();
classElement.AddElementWithData(context, "UniformScale", uniformScale);
}
}
return true;
}
} // namespace Internal
TransformComponent::TransformComponent()
@ -1123,6 +1140,8 @@ namespace AzToolsFramework
return AZ::Edit::PropertyRefreshLevels::EntireTree;
}
void TransformComponent::Reflect(AZ::ReflectContext* context)
{
// reflect data for script, serialization, editing..
@ -1133,7 +1152,8 @@ namespace AzToolsFramework
Field("Rotate", &EditorTransform::m_rotate)->
Field("Scale", &EditorTransform::m_scale)->
Field("Locked", &EditorTransform::m_locked)->
Version(2);
Field("UniformScale", &EditorTransform::m_uniformScale)->
Version(3, &Internal::EditorTransformDataConverter);
serializeContext->Class<Components::TransformComponent, EditorComponentBase>()->
Field("Parent Entity", &TransformComponent::m_parentEntityId)->
@ -1192,7 +1212,7 @@ namespace AzToolsFramework
Attribute(AZ::Edit::Attributes::Suffix, " deg")->
Attribute(AZ::Edit::Attributes::ReadOnly, &EditorTransform::m_locked)->
Attribute(AZ::Edit::Attributes::SliceFlags, AZ::Edit::SliceFlags::NotPushableOnSliceRoot)->
DataElement(TransformScaleHandler, &EditorTransform::m_scale, "Scale", "Local Scale")->
DataElement(AZ::Edit::UIHandlers::Default, &EditorTransform::m_uniformScale, "Uniform Scale", "Local Uniform Scale")->
Attribute(AZ::Edit::Attributes::Step, 0.1f)->
Attribute(AZ::Edit::Attributes::ReadOnly, &EditorTransform::m_locked)
;

@ -42,6 +42,7 @@ namespace AzToolsFramework
AZ::Vector3 m_translate; //! Translation in engine units (meters)
AZ::Vector3 m_scale;
float m_uniformScale;
AZ::Vector3 m_rotate; //! Rotation in degrees
bool m_locked;
};

Loading…
Cancel
Save