/* * 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 "ScriptEventsSystemComponent.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include AZ_DEFINE_BUDGET(ScriptCanvas); namespace ScriptEvents { void ScriptEventsSystemComponent::Reflect(AZ::ReflectContext* context) { using namespace ScriptEvents; if (AZ::SerializeContext* serialize = azrtti_cast(context)) { serialize->Class() ->Version(1) // ScriptEvents avoids a use dependency on the AssetBuilderSDK. Therefore the Crc is used directly to register this component with the Gem builder ->Attribute(AZ::Edit::Attributes::SystemComponentTags, AZStd::vector({ AZ_CRC_CE("AssetBuilder") })); ; } ScriptEventData::VersionedProperty::Reflect(context); Parameter::Reflect(context); Method::Reflect(context); ScriptEvent::Reflect(context); ScriptEvents::ScriptEventsAsset::Reflect(context); ScriptEvents::ScriptEventsAssetRef::Reflect(context); ScriptEvents::ScriptEventsAssetPtr::Reflect(context); } void ScriptEventsSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) { provided.push_back(AZ_CRC_CE("ScriptEventsService")); } void ScriptEventsSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) { incompatible.push_back(AZ_CRC_CE("ScriptEventsService")); } void ScriptEventsSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required) { required.push_back(AZ_CRC_CE("AssetDatabaseService")); } void ScriptEventsSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent) { AZ_UNUSED(dependent); } void ScriptEventsSystemComponent::Init() { } void ScriptEventsSystemComponent::Activate() { ScriptEventsSystemComponentImpl* moduleConfiguration = nullptr; ScriptEventModuleConfigurationRequestBus::BroadcastResult(moduleConfiguration, &ScriptEventModuleConfigurationRequests::GetSystemComponentImpl); if (moduleConfiguration) { moduleConfiguration->RegisterAssetHandler(); } } void ScriptEventsSystemComponent::Deactivate() { for (auto& asset : m_scriptEvents) { asset.second.reset(); } m_scriptEvents.clear(); ScriptEventsSystemComponentImpl* moduleConfiguration = nullptr; ScriptEventModuleConfigurationRequestBus::BroadcastResult(moduleConfiguration, &ScriptEventModuleConfigurationRequests::GetSystemComponentImpl); if (moduleConfiguration) { moduleConfiguration->UnregisterAssetHandler(); moduleConfiguration->CleanUp(); } } void ScriptEventsSystemComponentRuntimeImpl::RegisterAssetHandler() { AZ::Data::AssetType assetType(azrtti_typeid()); if (AZ::Data::AssetManager::Instance().GetHandler(assetType)) { return; // Asset Type already handled } m_assetHandler = AZStd::make_unique(ScriptEvents::ScriptEventsAsset::GetDisplayName(), ScriptEvents::ScriptEventsAsset::GetGroup(), ScriptEvents::ScriptEventsAsset::GetFileFilter(), AZ::AzTypeInfo::Uuid()); AZ::Data::AssetManager::Instance().RegisterHandler(m_assetHandler.get(), assetType); // Use AssetCatalog service to register ScriptCanvas asset type and extension AZ::Data::AssetCatalogRequestBus::Broadcast(&AZ::Data::AssetCatalogRequests::AddAssetType, assetType); AZ::Data::AssetCatalogRequestBus::Broadcast(&AZ::Data::AssetCatalogRequests::EnableCatalogForAsset, assetType); AZ::Data::AssetCatalogRequestBus::Broadcast(&AZ::Data::AssetCatalogRequests::AddExtension, ScriptEvents::ScriptEventsAsset::GetFileFilter()); } void ScriptEventsSystemComponentRuntimeImpl::UnregisterAssetHandler() { AZ::Data::AssetManager::Instance().UnregisterHandler(m_assetHandler.get()); m_assetHandler.reset(); } }