Fixing pivot offset when performing undo on Transform component (#6150)

* Fixing undo offest on transform component

Signed-off-by: Mikhail Naumov <mnaumov@amazon.com>

* Fixining possible issue with firing an unnecessary OnTransformChanged event when entity is manually disabled/enabled

Signed-off-by: Mikhail Naumov <mnaumov@amazon.com>

* Adding better comments

Signed-off-by: Mikhail Naumov <mnaumov@amazon.com>

* Unit tests

Signed-off-by: Mikhail Naumov <mnaumov@amazon.com>

* Cherrupicking changes

Signed-off-by: Mikhail Naumov <mnaumov@amazon.com>
This commit is contained in:
Mikhail Naumov
2021-12-06 08:46:47 -06:00
committed by GitHub
parent dc8f9dc233
commit c5615f812c
6 changed files with 181 additions and 79 deletions
@@ -18,7 +18,10 @@
#include <AzFramework/Components/TransformComponent.h>
#include <AzToolsFramework/Application/ToolsApplication.h>
#include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
#include <AzToolsFramework/ToolsComponents/TransformComponent.h>
#include <AzToolsFramework/Entity/PrefabEditorEntityOwnershipInterface.h>
#include <Prefab/PrefabTestFixture.h>
#include <AZTestShared/Math/MathTestHelpers.h>
@@ -1063,4 +1066,67 @@ R"DELIMITER(<ObjectStream version="1">
}
}
}
// Fixture provides a root prefab with Transform component and listens for TransformNotificationBus.
class TransformComponentActivationTest
: public PrefabTestFixture
, public TransformNotificationBus::Handler
{
protected:
void SetUpEditorFixtureImpl() override
{
PrefabTestFixture::SetUpEditorFixtureImpl();
CreateRootPrefab();
}
void TearDownEditorFixtureImpl() override
{
BusDisconnect();
PrefabTestFixture::TearDownEditorFixtureImpl();
}
void OnTransformChanged(const Transform& /*local*/, const Transform& /*world*/) override
{
m_transformUpdated = true;
}
void MoveEntity(AZ::EntityId entityId)
{
AzToolsFramework::ScopedUndoBatch undoBatch("Move Entity");
TransformBus::Event(entityId, &TransformInterface::SetWorldTranslation, Vector3(1.f, 0.f, 0.f));
}
bool m_transformUpdated = false;
};
TEST_F(TransformComponentActivationTest, TransformChangedEventIsSentWhenEntityIsActivatedViaUndoRedo)
{
AZ::EntityId entityId = CreateEntityUnderRootPrefab("Entity");
MoveEntity(entityId);
BusConnect(entityId);
// verify that undoing/redoing move operations fires TransformChanged event
Undo();
EXPECT_TRUE(m_transformUpdated);
m_transformUpdated = false;
Redo();
EXPECT_TRUE(m_transformUpdated);
m_transformUpdated = false;
}
TEST_F(TransformComponentActivationTest, TransformChangedEventIsNotSentWhenEntityIsDeactivatedAndActivated)
{
AZ::EntityId entityId = CreateEntityUnderRootPrefab("Entity");
BusConnect(entityId);
// verify that simply activating/deactivating an entity does not fire TransformChanged event
Entity* entity = nullptr;
ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationRequests::FindEntity, entityId);
entity->Deactivate();
entity->Activate();
EXPECT_FALSE(m_transformUpdated);
}
} // namespace UnitTest