EMotionFXBuilderFixture.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "EMotionFXBuilderFixture.h"
  9. #include <EMotionFX/Source/EMotionFXManager.h>
  10. #include <EMotionFX/Source/Allocators.h>
  11. #include <EMotionFX/Source/AnimGraphObjectFactory.h>
  12. #include <EMotionFX/Source/Parameter/ParameterFactory.h>
  13. #include <EMotionFX/Source/MotionSet.h>
  14. #include <EMotionFX/Source/AnimGraphObject.h>
  15. #include <EMotionFX/Source/AnimGraph.h>
  16. #include <EMotionFX/Source/AnimGraphNodeGroup.h>
  17. #include <Integration/Assets/MotionSetAsset.h>
  18. #include <Integration/Assets/AnimGraphAsset.h>
  19. #include <AzCore/Serialization/SerializeContext.h>
  20. #include <AzCore/Serialization/EditContextConstants.inl>
  21. using ::testing::Return;
  22. using ::testing::_;
  23. namespace EMotionFX
  24. {
  25. void BuilderMockComponent::Activate()
  26. {
  27. ASSERT_TRUE(MCore::Initializer::Init());
  28. ASSERT_TRUE(EMotionFX::Initializer::Init());
  29. // Initialize asset handlers.
  30. m_assetHandlers.emplace_back(aznew EMotionFX::Integration::MotionSetAssetBuilderHandler);
  31. m_assetHandlers.emplace_back(aznew EMotionFX::Integration::AnimGraphAssetBuilderHandler);
  32. // Initialize an AssetCatalog AssetStreamInfo that will appear valid.
  33. AZ::Data::AssetStreamInfo mockAssetStreamInfo;
  34. mockAssetStreamInfo.m_streamFlags = AZ::IO::OpenMode::ModeRead;
  35. mockAssetStreamInfo.m_streamName = "test";
  36. m_assetCatalog.reset(aznew EMotionFXTest_MockCatalog());
  37. EXPECT_CALL(*(m_assetCatalog.get()), GetAssetInfoById(_)).WillRepeatedly(Return(AZ::Data::AssetInfo()));
  38. EXPECT_CALL(*(m_assetCatalog.get()), GetStreamInfoForLoad(_, _)).WillRepeatedly(Return(mockAssetStreamInfo));
  39. AZ::Data::AssetManager::Instance().RegisterCatalog(m_assetCatalog.get(), azrtti_typeid<EMotionFX::Integration::MotionSetAsset>());
  40. AZ::Data::AssetManager::Instance().RegisterCatalog(m_assetCatalog.get(), azrtti_typeid<EMotionFX::Integration::AnimGraphAsset>());
  41. }
  42. void BuilderMockComponent::Deactivate()
  43. {
  44. m_assetCatalog->DisableCatalog();
  45. m_assetCatalog.reset();
  46. m_assetHandlers.clear();
  47. EMotionFX::Initializer::Shutdown();
  48. MCore::Initializer::Shutdown();
  49. }
  50. void BuilderMockComponent::ReflectAnimGraphAndMotionSet(AZ::ReflectContext* context)
  51. {
  52. // Motion set
  53. EMotionFX::MotionSet::Reflect(context);
  54. EMotionFX::MotionSet::MotionEntry::Reflect(context);
  55. // Base AnimGraph objects
  56. EMotionFX::AnimGraphObject::Reflect(context);
  57. EMotionFX::AnimGraph::Reflect(context);
  58. EMotionFX::AnimGraphNodeGroup::Reflect(context);
  59. // Anim graph objects
  60. EMotionFX::AnimGraphObjectFactory::ReflectTypes(context);
  61. // Anim graph's parameters
  62. EMotionFX::ParameterFactory::ReflectParameterTypes(context);
  63. }
  64. void BuilderMockComponent::Reflect(AZ::ReflectContext* context)
  65. {
  66. ReflectAnimGraphAndMotionSet(context);
  67. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  68. {
  69. serialize->Class<BuilderMockComponent, AZ::Component>()
  70. ->Version(1);
  71. }
  72. }
  73. }