/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include #include #include #include #include #include #include #include #include #include namespace AZ { namespace Render { EditorCommonFeaturesSystemComponent::EditorCommonFeaturesSystemComponent() = default; EditorCommonFeaturesSystemComponent::~EditorCommonFeaturesSystemComponent() = default; //! Main system component for the Atom Common Feature Gem's editor/tools module. void EditorCommonFeaturesSystemComponent::Reflect(AZ::ReflectContext* context) { if (AZ::SerializeContext* serialize = azrtti_cast(context)) { serialize->Class() ->Version(1) ->Field("Atom Level Default Asset Path", &EditorCommonFeaturesSystemComponent::m_atomLevelDefaultAssetPath); if (AZ::EditContext* ec = serialize->GetEditContext()) { ec->Class("AtomEditorCommonFeaturesSystemComponent", "Configures editor- and tool-specific functionality for common render features.") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ->DataElement(nullptr, &EditorCommonFeaturesSystemComponent::m_atomLevelDefaultAssetPath, "Atom Level Default Asset Path", "path to the slice the instantiate for a new Atom level") ; } } } void EditorCommonFeaturesSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC("EditorCommonFeaturesService", 0x94945c0c)); } void EditorCommonFeaturesSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC("EditorCommonFeaturesService", 0x94945c0c)); } void EditorCommonFeaturesSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { required.push_back(AZ_CRC_CE("ThumbnailerService")); required.push_back(AZ_CRC_CE("PreviewRendererSystem")); } void EditorCommonFeaturesSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) { AZ_UNUSED(dependent); } void EditorCommonFeaturesSystemComponent::Init() { } void EditorCommonFeaturesSystemComponent::Activate() { m_skinnedMeshDebugDisplay = AZStd::make_unique(); AzToolsFramework::AssetBrowser::PreviewerRequestBus::Handler::BusConnect(); if (auto settingsRegistry{ AZ::SettingsRegistry::Get() }; settingsRegistry != nullptr) { auto LifecycleCallback = [this](const AZ::SettingsRegistryInterface::NotifyEventArgs&) { SetupThumbnails(); }; AZ::ComponentApplicationLifecycle::RegisterHandler(*settingsRegistry, m_criticalAssetsHandler, AZStd::move(LifecycleCallback), "CriticalAssetsCompiled"); } AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusConnect(); } void EditorCommonFeaturesSystemComponent::Deactivate() { AzFramework::ApplicationLifecycleEvents::Bus::Handler::BusDisconnect(); m_criticalAssetsHandler = {}; AzToolsFramework::AssetBrowser::PreviewerRequestBus::Handler::BusDisconnect(); m_skinnedMeshDebugDisplay.reset(); TeardownThumbnails(); } const AzToolsFramework::AssetBrowser::PreviewerFactory* EditorCommonFeaturesSystemComponent::GetPreviewerFactory( const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry) const { return m_previewerFactory->IsEntrySupported(entry) ? m_previewerFactory.get() : nullptr; } void EditorCommonFeaturesSystemComponent::OnApplicationAboutToStop() { TeardownThumbnails(); } void EditorCommonFeaturesSystemComponent::SetupThumbnails() { using namespace AzToolsFramework::Thumbnailer; using namespace LyIntegration; ThumbnailerRequestBus::Broadcast( &ThumbnailerRequests::RegisterThumbnailProvider, MAKE_TCACHE(SharedThumbnailCache)); if (!m_thumbnailRenderer) { m_thumbnailRenderer = AZStd::make_unique(); } if (!m_previewerFactory) { m_previewerFactory = AZStd::make_unique(); } } void EditorCommonFeaturesSystemComponent::TeardownThumbnails() { using namespace AzToolsFramework::Thumbnailer; using namespace LyIntegration; ThumbnailerRequestBus::Broadcast(&ThumbnailerRequests::UnregisterThumbnailProvider, SharedThumbnailCache::ProviderName); m_thumbnailRenderer.reset(); m_previewerFactory.reset(); } } // namespace Render } // namespace AZ