3
0

SystemComponent.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <AzCore/Component/TickBus.h>
  11. #include <AzCore/std/smart_ptr/unique_ptr.h>
  12. #include <Integration/AnimationBus.h>
  13. #include <Integration/EMotionFXBus.h>
  14. #include <Integration/Rendering/RenderBackendManager.h>
  15. #include <CrySystemBus.h>
  16. #if defined (EMOTIONFXANIMATION_EDITOR)
  17. # include <AzToolsFramework/ActionManager/ActionManagerRegistrationNotificationBus.h>
  18. # include <AzToolsFramework/API/ToolsApplicationAPI.h>
  19. # include <AzToolsFramework/API/EditorAnimationSystemRequestBus.h>
  20. # include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
  21. # include <AzToolsFramework/AssetBrowser/Entries/SourceAssetBrowserEntry.h>
  22. # include <EMotionStudio/EMStudioSDK/Source/EMStudioManager.h>
  23. #endif // EMOTIONFXANIMATION_EDITOR
  24. namespace AZ
  25. {
  26. namespace Data
  27. {
  28. class AssetHandler;
  29. }
  30. }
  31. namespace AzToolsFramework
  32. {
  33. class PropertyHandlerBase;
  34. }
  35. namespace EMotionFX
  36. {
  37. namespace Integration
  38. {
  39. class EMotionFXEventHandler;
  40. class SystemComponent
  41. : public AZ::Component
  42. , private SystemRequestBus::Handler
  43. , private AZ::TickBus::Handler
  44. , private CrySystemEventBus::Handler
  45. , private EMotionFXRequestBus::Handler
  46. , private IRaycastRequests
  47. #if defined (EMOTIONFXANIMATION_EDITOR)
  48. , private AzToolsFramework::EditorEvents::Bus::Handler
  49. , private AzToolsFramework::EditorAnimationSystemRequestsBus::Handler
  50. , private AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler
  51. , private AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler
  52. #endif // EMOTIONFXANIMATION_EDITOR
  53. {
  54. public:
  55. AZ_COMPONENT(SystemComponent, "{7AE4102B-387C-4157-B8C7-8D1EA3BCFD60}");
  56. SystemComponent();
  57. ~SystemComponent() override;
  58. static void ReflectEMotionFX(AZ::ReflectContext* context);
  59. static void Reflect(AZ::ReflectContext* context);
  60. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  61. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  62. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  63. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  64. private:
  65. //unique_ptr cannot be copied -> vector of unique_ptrs cannot be copied -> class cannot be copied
  66. SystemComponent(const SystemComponent&) = delete;
  67. ////////////////////////////////////////////////////////////////////////
  68. // AZ::Component interface implementation
  69. void Init() override;
  70. void Activate() override;
  71. void Deactivate() override;
  72. ////////////////////////////////////////////////////////////////////////
  73. ////////////////////////////////////////////////////////////////////////
  74. // AZ::TickBus::Handler
  75. void OnTick(float delta, AZ::ScriptTimePoint timePoint) override;
  76. int GetTickOrder() override;
  77. ////////////////////////////////////////////////////////////////////////
  78. ////////////////////////////////////////////////////////////////////////
  79. // CrySystemEventBus
  80. void OnCrySystemInitialized(ISystem&, const SSystemInitParams&) override;
  81. void OnCrySystemShutdown(ISystem&) override;
  82. ////////////////////////////////////////////////////////////////////////
  83. ////////////////////////////////////////////////////////////////////////
  84. // EMotionFXRequestBus
  85. void RegisterAnimGraphObjectType(EMotionFX::AnimGraphObject* objectTemplate) override;
  86. ////////////////////////////////////////////////////////////////////////
  87. ////////////////////////////////////////////////////////////////////////
  88. // IRaycastRequests overrides ...
  89. void EnableRayRequests() override;
  90. void DisableRayRequests() override;
  91. IRaycastRequests::RaycastResult Raycast(AZ::EntityId entityId, const IRaycastRequests::RaycastRequest& rayRequest) override;
  92. ////////////////////////////////////////////////////////////////////////
  93. void RegisterAssetTypesAndHandlers();
  94. void SetMediaRoot(const char* alias);
  95. #if defined (EMOTIONFXANIMATION_EDITOR)
  96. void NotifyRegisterViews() override;
  97. bool IsSystemActive(EditorAnimationSystemRequests::AnimationSystem systemType) override;
  98. //////////////////////////////////////////////////////////////////////////////////////
  99. // AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler
  100. AzToolsFramework::AssetBrowser::SourceFileDetails GetSourceFileDetails(const char* fullSourceFileName) override;
  101. void AddSourceFileOpeners(const char* fullSourceFileName, const AZ::Uuid& sourceUUID, AzToolsFramework::AssetBrowser::SourceFileOpenerList& openers) override;
  102. void AddSourceFileCreators(const char* fullSourceFolderName, const AZ::Uuid& sourceUUID, AzToolsFramework::AssetBrowser::SourceFileCreatorList& creators) override;
  103. //////////////////////////////////////////////////////////////////////////////////////
  104. // AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler...
  105. void OnActionContextRegistrationHook() override;
  106. bool HandlesSource(AZStd::string_view fileName) const;
  107. AZStd::vector<AzToolsFramework::PropertyHandlerBase*> m_propertyHandlers;
  108. #endif // EMOTIONFXANIMATION_EDITOR
  109. AZ::u32 m_numThreads;
  110. private:
  111. //! Synchronize the actor instance location with the entity or character controller.
  112. //! In case no character controller component is available, the entity will be moved
  113. //! to the actor instance position. The spatial difference between the entity and the
  114. //! actor instance will be calculated in case a character controller is present, and the
  115. //! velocity will be applied to it to move it towards the actor instance.
  116. void ApplyMotionExtraction(const ActorInstance* actorInstance, float timeDelta);
  117. AZStd::vector<AZStd::unique_ptr<AZ::Data::AssetHandler> > m_assetHandlers;
  118. AZStd::unique_ptr<EMotionFXEventHandler> m_eventHandler;
  119. AZStd::unique_ptr<RenderBackendManager> m_renderBackendManager;
  120. #if defined(EMOTIONFXANIMATION_EDITOR)
  121. AZStd::unique_ptr<EMStudio::EMStudioManager> m_emstudioManager;
  122. #endif // EMOTIONFXANIMATION_EDITOR
  123. };
  124. }
  125. }