ScriptEventsSystemEditorComponent.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "ScriptEventsSystemComponent.h"
  10. #include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
  11. #include <AzToolsFramework/AssetEditor/AssetEditorBus.h>
  12. #include <ScriptEvents/ScriptEventsAsset.h>
  13. #include <AzToolsFramework/AssetEditor/AssetEditorBus.h>
  14. #include <ScriptEvents/ScriptEventsAssetRef.h>
  15. namespace AzToolsFramework { class PropertyHandlerBase; }
  16. #if defined(SCRIPTEVENTS_EDITOR)
  17. namespace ScriptEventsEditor
  18. {
  19. // This is the ScriptEvent asset handler used by the Asset Editor, it does additional validation that is not
  20. // needed when saving the asset through the builder
  21. class ScriptEventAssetHandler
  22. : public AzFramework::GenericAssetHandler<ScriptEvents::ScriptEventsAsset>
  23. , AzToolsFramework::AssetEditor::AssetEditorValidationRequestBus::MultiHandler
  24. {
  25. public:
  26. AZ_CLASS_ALLOCATOR(ScriptEventAssetHandler, AZ::SystemAllocator)
  27. AZ_RTTI(ScriptEventAssetHandler, "{D81DE7D5-5ED0-4D70-8364-AA986E9C490E}", AzFramework::GenericAssetHandler<ScriptEvents::ScriptEventsAsset>);
  28. ScriptEventAssetHandler(const char* displayName, const char* group, const char* extension, const AZ::Uuid& componentTypeId = AZ::Uuid::CreateNull(), AZ::SerializeContext* serializeContext = nullptr);
  29. AZ::Data::AssetPtr CreateAsset(const AZ::Data::AssetId& id, const AZ::Data::AssetType& type) override;
  30. AZ::Data::AssetHandler::LoadResult LoadAssetData(
  31. const AZ::Data::Asset<AZ::Data::AssetData>& asset,
  32. AZStd::shared_ptr<AZ::Data::AssetDataStream> stream,
  33. const AZ::Data::AssetFilterCB& assetLoadFilterCB) override;
  34. bool SaveAssetData(const AZ::Data::Asset<AZ::Data::AssetData>& asset, AZ::IO::GenericStream* stream) override;
  35. void InitAsset(const AZ::Data::Asset<AZ::Data::AssetData>& asset, bool loadStageSucceeded, bool isReload) override;
  36. // AssetEditorValidationRequestBus::Handler
  37. AZ::Outcome<bool, AZStd::string> IsAssetDataValid(const AZ::Data::Asset<AZ::Data::AssetData>& asset) override;
  38. void PreAssetSave(AZ::Data::Asset<AZ::Data::AssetData> asset) override;
  39. void BeforePropertyEdit(AzToolsFramework::InstanceDataNode* node, AZ::Data::Asset<AZ::Data::AssetData> asset) override;
  40. void SetSaveAsBinary(bool saveAsBinary) { m_saveAsBinary = saveAsBinary; }
  41. private:
  42. struct PreviousNameSettings
  43. {
  44. AZStd::string m_previousName;
  45. AZ::u32 m_version;
  46. };
  47. AZStd::unordered_map< AZ::Data::AssetId, PreviousNameSettings > m_previousEbusNames;
  48. bool m_saveAsBinary;
  49. };
  50. class ScriptEventEditorSystemComponent
  51. : public AZ::Component
  52. {
  53. public:
  54. AZ_COMPONENT(ScriptEventEditorSystemComponent, "{8BAD5292-56C3-4657-99F2-515A2BDE23C1}");
  55. ScriptEventEditorSystemComponent() = default;
  56. ScriptEventEditorSystemComponent(const ScriptEventEditorSystemComponent&) = delete;
  57. protected:
  58. static void Reflect(AZ::ReflectContext* context);
  59. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  60. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  61. ////////////////////////////////////////////////////////////////////////
  62. // AZ::Component...
  63. void Init() override {}
  64. void Activate() override;
  65. void Deactivate() override;
  66. ////////////////////////////////////////////////////////////////////////
  67. // Script Event Assets
  68. AZStd::unordered_map<ScriptEvents::ScriptEventKey, AZStd::intrusive_ptr<ScriptEvents::Internal::ScriptEventRegistration>> m_scriptEvents;
  69. };
  70. }
  71. #endif