ActorComponentAttachmentTest.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Component/Entity.h>
  9. #include <AzFramework/Components/TransformComponent.h>
  10. #include <Integration/Components/ActorComponent.h>
  11. #include <EMotionFX/Source/Allocators.h>
  12. #include <Tests/Integration/EntityComponentFixture.h>
  13. #include <Tests/TestAssetCode/TestActorAssets.h>
  14. #include <Tests/TestAssetCode/JackActor.h>
  15. #include <Tests/TestAssetCode/ActorFactory.h>
  16. namespace EMotionFX
  17. {
  18. TEST_F(EntityComponentFixture, ActorComponent_Attachment)
  19. {
  20. // Entity 1
  21. AZ::EntityId entityId(740216387);
  22. auto gameEntity = AZStd::make_unique<AZ::Entity>();
  23. gameEntity->SetId(entityId);
  24. AZ::Data::AssetId actorAssetId("{5060227D-B6F4-422E-BF82-41AAC5F228A5}");
  25. AZStd::unique_ptr<Actor> actor = ActorFactory::CreateAndInit<JackNoMeshesActor>();
  26. AZ::Data::Asset<Integration::ActorAsset> actorAsset = TestActorAssets::GetAssetFromActor(actorAssetId, AZStd::move(actor));
  27. gameEntity->CreateComponent<AzFramework::TransformComponent>();
  28. auto actorComponent = gameEntity->CreateComponent<Integration::ActorComponent>();
  29. gameEntity->Init();
  30. gameEntity->Activate();
  31. actorComponent->SetActorAsset(actorAsset);
  32. // Entity 2 - attaches to previous entity
  33. auto gameEntityAttachment = AZStd::make_unique<AZ::Entity>();
  34. Integration::ActorComponent::Configuration actorConfig;
  35. actorConfig.m_attachmentTarget = entityId;
  36. actorConfig.m_attachmentType = Integration::AttachmentType::SkinAttachment;
  37. gameEntityAttachment->CreateComponent<AzFramework::TransformComponent>();
  38. auto actorComponentAttachmentEntity = gameEntityAttachment->CreateComponent<Integration::ActorComponent>(&actorConfig);
  39. gameEntityAttachment->Init();
  40. gameEntityAttachment->Activate();
  41. actorComponentAttachmentEntity->SetActorAsset(actorAsset);
  42. // Deactivate main actor first
  43. gameEntity->Deactivate();
  44. gameEntityAttachment->Deactivate();
  45. EXPECT_TRUE(true);
  46. }
  47. TEST_F(EntityComponentFixture, ActorComponent_AttachmentDeactivatesFirst)
  48. {
  49. AZ::EntityId entityId(740216387);
  50. auto gameEntity = AZStd::make_unique<AZ::Entity>();
  51. gameEntity->SetId(entityId);
  52. AZ::Data::AssetId actorAssetId("{5060227D-B6F4-422E-BF82-41AAC5F228A5}");
  53. AZStd::unique_ptr<Actor> actor = ActorFactory::CreateAndInit<JackNoMeshesActor>();
  54. AZ::Data::Asset<Integration::ActorAsset> actorAsset = TestActorAssets::GetAssetFromActor(actorAssetId, AZStd::move(actor));
  55. gameEntity->CreateComponent<AzFramework::TransformComponent>();
  56. auto actorComponent = gameEntity->CreateComponent<Integration::ActorComponent>();
  57. gameEntity->Init();
  58. gameEntity->Activate();
  59. actorComponent->SetActorAsset(actorAsset);
  60. // Entity 2 - attaches to previous entity
  61. auto gameEntityAttachment = AZStd::make_unique<AZ::Entity>();
  62. Integration::ActorComponent::Configuration actorConfig;
  63. actorConfig.m_attachmentTarget = entityId;
  64. actorConfig.m_attachmentType = Integration::AttachmentType::SkinAttachment;
  65. gameEntityAttachment->CreateComponent<AzFramework::TransformComponent>();
  66. auto actorComponentAttachmentEntity = gameEntityAttachment->CreateComponent<Integration::ActorComponent>(&actorConfig);
  67. gameEntityAttachment->Init();
  68. gameEntityAttachment->Activate();
  69. actorComponentAttachmentEntity->SetActorAsset(actorAsset);
  70. // Deactivate attachment first
  71. gameEntityAttachment->Deactivate();
  72. gameEntity->Deactivate();
  73. EXPECT_TRUE(true);
  74. }
  75. }