PrefabBuilderComponent.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 <AssetBuilderSDK/AssetBuilderSDK.h>
  10. #include <AssetBuilderSDK/SerializationDependencies.h>
  11. #include <AzCore/Component/Component.h>
  12. #include <AzCore/IO/SystemFile.h>
  13. #include <AzCore/Module/Module.h>
  14. #include <AzCore/Module/DynamicModuleHandle.h>
  15. #include <AzCore/Serialization/Json/JsonUtils.h>
  16. #include <AzToolsFramework/Prefab/PrefabSystemComponent.h>
  17. #include <AzToolsFramework/Prefab/Spawnable/PrefabConversionPipeline.h>
  18. #include <Fingerprinting/TypeFingerprinter.h>
  19. #include <Prefab/PrefabDomUtils.h>
  20. namespace AZ::Prefab
  21. {
  22. class PrefabBuilderComponent
  23. : public AssetBuilderSDK::AssetBuilderCommandBus::Handler
  24. , public AZ::Component
  25. {
  26. public:
  27. static constexpr const char* BuilderId = "{A2E0791C-4607-4363-A7FD-73D01ED49660}";
  28. static constexpr const char* PrefabJobKey = "Prefabs";
  29. static constexpr const char* ConfigKey = "GameObjectCreation";
  30. AZ_COMPONENT(PrefabBuilderComponent, BuilderId);
  31. static void Reflect(AZ::ReflectContext* context);
  32. PrefabBuilderComponent()
  33. : m_builderId(BuilderId)
  34. {
  35. }
  36. //////////////////////////////////////////////////////////////////////////
  37. // AZ::Component
  38. void Activate() override;
  39. void Deactivate() override;
  40. //////////////////////////////////////////////////////////////////////////
  41. void ShutDown() override;
  42. AzToolsFramework::Fingerprinting::TypeFingerprint CalculateBuilderFingerprint() const;
  43. AzToolsFramework::Fingerprinting::TypeFingerprint CalculatePrefabFingerprint(
  44. const AzToolsFramework::Prefab::PrefabDom& genericDocument) const;
  45. static AZStd::vector<AssetBuilderSDK::SourceFileDependency> GetSourceDependencies(
  46. const AzToolsFramework::Prefab::PrefabDom& genericDocument);
  47. bool ProcessPrefab(
  48. const AZ::PlatformTagSet& platformTags, const char* filePath, AZ::IO::PathView tempDirPath, const AZ::Uuid& sourceFileUuid,
  49. AzToolsFramework::Prefab::PrefabDom&& rootDom,
  50. AZStd::vector<AssetBuilderSDK::JobProduct>& jobProducts);
  51. protected:
  52. virtual AZStd::unique_ptr<AZ::IO::GenericStream> GetOutputStream(const AZ::IO::Path& path) const;
  53. private:
  54. void CreateJobs(const AssetBuilderSDK::CreateJobsRequest& request, AssetBuilderSDK::CreateJobsResponse& response) const;
  55. bool StoreProducts(
  56. AZ::IO::PathView tempDirPath,
  57. const AzToolsFramework::Prefab::PrefabConversionUtils::PrefabProcessorContext::ProcessedObjectStoreContainer& store,
  58. const AzToolsFramework::Prefab::PrefabConversionUtils::PrefabProcessorContext::ProductAssetDependencyContainer& registeredDependencies,
  59. AZStd::vector<AssetBuilderSDK::JobProduct>& outputProducts) const;
  60. void ProcessJob(const AssetBuilderSDK::ProcessJobRequest& request, AssetBuilderSDK::ProcessJobResponse& response);
  61. AzToolsFramework::Prefab::PrefabConversionUtils::PrefabConversionPipeline m_pipeline;
  62. AZ::Uuid m_builderId;
  63. AZStd::atomic_bool m_isShuttingDown{ false };
  64. AZStd::unique_ptr<AzToolsFramework::Fingerprinting::TypeFingerprinter> m_typeFingerprinter;
  65. };
  66. } // namespace AZ::Prefab