SystemComponent.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/Jobs/JobContext.h>
  12. #include <AzCore/Jobs/JobManager.h>
  13. #include <AzCore/UserSettings/UserSettingsProvider.h>
  14. #include <AzCore/std/smart_ptr/unique_ptr.h>
  15. #include <AzToolsFramework/ActionManager/ActionManagerRegistrationNotificationBus.h>
  16. #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
  17. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  18. #include <AzToolsFramework/Asset/AssetSeedManager.h>
  19. #include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
  20. #include <AzToolsFramework/Entity/EditorEntityContextBus.h>
  21. #include <Builder/ScriptCanvasBuilder.h>
  22. #include <Builder/ScriptCanvasBuilderDataSystem.h>
  23. #include <Core/GraphBus.h>
  24. #include <Editor/View/Windows/Tools/UpgradeTool/Model.h>
  25. #include <ScriptCanvas/Bus/ScriptCanvasBus.h>
  26. #include <ScriptCanvas/Bus/ScriptCanvasExecutionBus.h>
  27. #include <Editor/Include/ScriptCanvas/Components/NodeReplacementSystem.h>
  28. namespace ScriptCanvasEditor
  29. {
  30. class SystemComponent
  31. : public AZ::Component
  32. , private SystemRequestBus::Handler
  33. , private AzToolsFramework::EditorEvents::Bus::Handler
  34. , private AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler
  35. , private ScriptCanvasExecutionBus::Handler
  36. , private AZ::UserSettingsNotificationBus::Handler
  37. , private AZ::Data::AssetBus::MultiHandler
  38. , private AzToolsFramework::AssetSeedManagerRequests::Bus::Handler
  39. , private AzToolsFramework::EditorEntityContextNotificationBus::Handler
  40. , private AzToolsFramework::AssetSystemBus::Handler
  41. , private AZ::SystemTickBus::Handler
  42. , private AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler
  43. {
  44. public:
  45. AZ_COMPONENT(SystemComponent, "{1DE7A120-4371-4009-82B5-8140CB1D7B31}");
  46. SystemComponent();
  47. ~SystemComponent() override;
  48. static void Reflect(AZ::ReflectContext* context);
  49. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  50. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  51. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  52. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  53. ////////////////////////////////////////////////////////////////////////
  54. // AZ::Component...
  55. void Init() override;
  56. void Activate() override;
  57. void Deactivate() override;
  58. ////////////////////////////////////////////////////////////////////////
  59. ////////////////////////////////////////////////////////////////////////
  60. // SystemRequestBus::Handler...
  61. void GetEditorCreatableTypes(AZStd::unordered_set<ScriptCanvas::Data::Type>& outCreatableTypes) override;
  62. void CreateEditorComponentsOnEntity(AZ::Entity* entity, const AZ::Data::AssetType& assetType) override;
  63. ////////////////////////////////////////////////////////////////////////
  64. ////////////////////////////////////////////////////////////////////////
  65. // AztoolsFramework::EditorEvents::Bus::Handler...
  66. void NotifyRegisterViews() override;
  67. ////////////////////////////////////////////////////////////////////////
  68. ////////////////////////////////////////////////////////////////////////
  69. // ScriptCanvasExecutionBus::Handler...
  70. Reporter RunAssetGraph(SourceHandle source, ScriptCanvas::ExecutionMode mode) override;
  71. Reporter RunGraph(AZStd::string_view path, ScriptCanvas::ExecutionMode mode) override;
  72. ////////////////////////////////////////////////////////////////////////
  73. ////////////////////////////////////////////////////////////////////////
  74. // AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus...
  75. AzToolsFramework::AssetBrowser::SourceFileDetails GetSourceFileDetails(const char* fullSourceFileName) override;
  76. void AddSourceFileCreators(const char* fullSourceFolderName, const AZ::Uuid& sourceUUID, AzToolsFramework::AssetBrowser::SourceFileCreatorList& creators) override;
  77. void AddSourceFileOpeners(const char* fullSourceFileName, const AZ::Uuid& sourceUUID, AzToolsFramework::AssetBrowser::SourceFileOpenerList& openers) override;
  78. ////////////////////////////////////////////////////////////////////////
  79. ////////////////////////////////////////////////////////////////////////
  80. // AZ::UserSettingsNotificationBus::Handler...
  81. void OnUserSettingsActivated() override;
  82. ////////////////////////////////////////////////////////////////////////
  83. ////////////////////////////////////////////////////////////////////////
  84. // AssetSeedManagerRequests::Bus::Handler...
  85. AzToolsFramework::AssetSeedManagerRequests::AssetTypePairs GetAssetTypeMapping() override;
  86. ////////////////////////////////////////////////////////////////////////
  87. ////////////////////////////////////////////////////////////////////////
  88. // ActionManagerRegistrationNotificationBus::Handler...
  89. void OnActionContextRegistrationHook() override;
  90. ////////////////////////////////////////////////////////////////////////
  91. ////////////////////////////////////////////////////////////////////////
  92. protected:
  93. void OnStartPlayInEditor() override;
  94. void OnStopPlayInEditor() override;
  95. void OnSystemTick() override;
  96. void RequestGarbageCollect() override;
  97. private:
  98. SystemComponent(const SystemComponent&) = delete;
  99. void PopulateEditorCreatableTypes();
  100. AZStd::unique_ptr<AZ::JobManager> m_jobManager;
  101. AZStd::unique_ptr<AZ::JobContext> m_jobContext;
  102. AZStd::unique_ptr<VersionExplorer::Model> m_versionExplorer;
  103. AZStd::unordered_set<ScriptCanvas::Data::Type> m_creatableTypes;
  104. AZStd::vector<AZ::Data::AssetId> m_assetsThatNeedManualUpgrade;
  105. bool m_isUpgrading = false;
  106. bool m_upgradeDisabled = false;
  107. bool m_isGarbageCollectRequested = true;
  108. ScriptCanvasBuilder::DataSystem m_dataSystem;
  109. NodeReplacementSystem m_nodeReplacementSystem;
  110. };
  111. }