EditorCommonFeaturesSystemComponent.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/ComponentApplicationLifecycle.h>
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include <AzCore/Serialization/EditContextConstants.inl>
  11. #include <AzCore/Serialization/SerializeContext.h>
  12. #include <AzCore/Utils/Utils.h>
  13. #include <AzToolsFramework/API/EditorCameraBus.h>
  14. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  15. #include <EditorCommonFeaturesSystemComponent.h>
  16. #include <SharedPreview/SharedThumbnail.h>
  17. #include <SkinnedMesh/SkinnedMeshDebugDisplay.h>
  18. #include <IEditor.h>
  19. namespace AZ
  20. {
  21. namespace Render
  22. {
  23. EditorCommonFeaturesSystemComponent::EditorCommonFeaturesSystemComponent() = default;
  24. EditorCommonFeaturesSystemComponent::~EditorCommonFeaturesSystemComponent() = default;
  25. //! Main system component for the Atom Common Feature Gem's editor/tools module.
  26. void EditorCommonFeaturesSystemComponent::Reflect(AZ::ReflectContext* context)
  27. {
  28. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  29. {
  30. serialize->Class<EditorCommonFeaturesSystemComponent, AZ::Component>()
  31. ->Version(1)
  32. ->Field("Atom Level Default Asset Path", &EditorCommonFeaturesSystemComponent::m_atomLevelDefaultAssetPath);
  33. if (AZ::EditContext* ec = serialize->GetEditContext())
  34. {
  35. ec->Class<EditorCommonFeaturesSystemComponent>("AtomEditorCommonFeaturesSystemComponent",
  36. "Configures editor- and tool-specific functionality for common render features.")
  37. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  38. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  39. ->DataElement(nullptr, &EditorCommonFeaturesSystemComponent::m_atomLevelDefaultAssetPath, "Atom Level Default Asset Path",
  40. "path to the slice the instantiate for a new Atom level")
  41. ;
  42. }
  43. }
  44. }
  45. void EditorCommonFeaturesSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  46. {
  47. provided.push_back(AZ_CRC_CE("EditorCommonFeaturesService"));
  48. }
  49. void EditorCommonFeaturesSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  50. {
  51. incompatible.push_back(AZ_CRC_CE("EditorCommonFeaturesService"));
  52. }
  53. void EditorCommonFeaturesSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  54. {
  55. required.push_back(AZ_CRC_CE("ThumbnailerService"));
  56. required.push_back(AZ_CRC_CE("PreviewRendererSystem"));
  57. }
  58. void EditorCommonFeaturesSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  59. {
  60. AZ_UNUSED(dependent);
  61. }
  62. void EditorCommonFeaturesSystemComponent::Init()
  63. {
  64. }
  65. void EditorCommonFeaturesSystemComponent::Activate()
  66. {
  67. m_skinnedMeshDebugDisplay = AZStd::make_unique<SkinnedMeshDebugDisplay>();
  68. AzToolsFramework::AssetBrowser::PreviewerRequestBus::Handler::BusConnect();
  69. if (auto settingsRegistry{ AZ::SettingsRegistry::Get() }; settingsRegistry != nullptr)
  70. {
  71. auto LifecycleCallback = [this](const AZ::SettingsRegistryInterface::NotifyEventArgs&)
  72. {
  73. SetupThumbnails();
  74. };
  75. AZ::ComponentApplicationLifecycle::RegisterHandler(*settingsRegistry, m_criticalAssetsHandler,
  76. AZStd::move(LifecycleCallback), "CriticalAssetsCompiled");
  77. }
  78. AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusConnect();
  79. }
  80. void EditorCommonFeaturesSystemComponent::Deactivate()
  81. {
  82. AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusDisconnect();
  83. m_criticalAssetsHandler = {};
  84. AzToolsFramework::AssetBrowser::PreviewerRequestBus::Handler::BusDisconnect();
  85. m_skinnedMeshDebugDisplay.reset();
  86. TeardownThumbnails();
  87. }
  88. const AzToolsFramework::AssetBrowser::PreviewerFactory* EditorCommonFeaturesSystemComponent::GetPreviewerFactory(
  89. const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const
  90. {
  91. return m_previewerFactory->IsEntrySupported(entry) ? m_previewerFactory.get() : nullptr;
  92. }
  93. void EditorCommonFeaturesSystemComponent::OnApplicationAboutToStop()
  94. {
  95. TeardownThumbnails();
  96. }
  97. void EditorCommonFeaturesSystemComponent::SetupThumbnails()
  98. {
  99. using namespace AzToolsFramework::Thumbnailer;
  100. using namespace LyIntegration;
  101. ThumbnailerRequestBus::Broadcast(
  102. &ThumbnailerRequests::RegisterThumbnailProvider, MAKE_TCACHE(SharedThumbnailCache));
  103. if (!m_thumbnailRenderer)
  104. {
  105. m_thumbnailRenderer = AZStd::make_unique<AZ::LyIntegration::SharedThumbnailRenderer>();
  106. }
  107. if (!m_previewerFactory)
  108. {
  109. m_previewerFactory = AZStd::make_unique<LyIntegration::SharedPreviewerFactory>();
  110. }
  111. }
  112. void EditorCommonFeaturesSystemComponent::TeardownThumbnails()
  113. {
  114. using namespace AzToolsFramework::Thumbnailer;
  115. using namespace LyIntegration;
  116. ThumbnailerRequestBus::Broadcast(&ThumbnailerRequests::UnregisterThumbnailProvider, SharedThumbnailCache::ProviderName);
  117. m_thumbnailRenderer.reset();
  118. m_previewerFactory.reset();
  119. }
  120. } // namespace Render
  121. } // namespace AZ