PersistentIdComponent.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/Math/Uuid.h>
  11. #include <GraphCanvas/Components/EntitySaveDataBus.h>
  12. #include <GraphCanvas/Components/PersistentIdBus.h>
  13. #include <GraphCanvas/Components/SceneBus.h>
  14. #include <GraphCanvas/Types/EntitySaveData.h>
  15. namespace GraphCanvas
  16. {
  17. // PersistentIdComponent provides an Id for GraphCanvas objects that will persist across loads/unloads.
  18. // This enables the ability to not serialize out the entire GraphCanvas object, and instead serialize out only
  19. // the user configurable information. But still enable things like NodeGroups to maintain some references to
  20. // specific GraphCanvas objects in order to maintain their state correctly.
  21. class PersistentIdComponent
  22. : public AZ::Component
  23. , public PersistentIdRequestBus::Handler
  24. , public PersistentMemberRequestBus::Handler
  25. , public SceneMemberNotificationBus::Handler
  26. {
  27. public:
  28. AZ_COMPONENT(PersistentIdComponent, "{57D546EE-C074-432E-A802-77CFC2E37AE7}", AZ::Component);
  29. static void Reflect(AZ::ReflectContext* reflectContext);
  30. PersistentIdComponent();
  31. ~PersistentIdComponent() = default;
  32. // Component
  33. void Init() override;
  34. void Activate() override;
  35. void Deactivate() override;
  36. ////
  37. // SceneMemberNotifications
  38. void OnSceneSet(const AZ::EntityId& graphId) override;
  39. void OnSceneMemberDeserialized(const AZ::EntityId& graphId, const GraphSerialization& serializationTarget) override;
  40. ////
  41. // PersistentIdRequestBus
  42. AZ::EntityId MapToEntityId() const override;
  43. ////
  44. // PersistentMemberRequestBus
  45. PersistentGraphMemberId GetPreviousGraphMemberId() const override;
  46. PersistentGraphMemberId GetPersistentGraphMemberId() const override;
  47. ////
  48. private:
  49. PersistentGraphMemberId m_previousId;
  50. PersistentIdComponentSaveData m_saveData;
  51. };
  52. }