GameEntityContextComponent.h 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #ifndef AZFRAMEWORK_GAMEENTITYCONTEXTCOMPONENT_H
  9. #define AZFRAMEWORK_GAMEENTITYCONTEXTCOMPONENT_H
  10. #include <AzCore/Math/Uuid.h>
  11. #include <AzCore/Math/Transform.h>
  12. #include <AzCore/std/containers/unordered_set.h>
  13. #include <AzCore/Component/Component.h>
  14. #include <AzFramework/Entity/GameEntityContextBus.h>
  15. #include <AzFramework/Entity/SliceGameEntityOwnershipService.h>
  16. #include <AzFramework/Visibility/EntityVisibilityBoundsUnionSystem.h>
  17. #include "EntityContext.h"
  18. namespace AzFramework
  19. {
  20. /**
  21. * System component responsible for owning the game entity context.
  22. *
  23. * The game entity context owns entities in the game runtime, as well as during play-in-editor.
  24. * These entities typically own game/runtime components, *not* inheriting from EditorComponentBase.
  25. */
  26. class GameEntityContextComponent
  27. : public AZ::Component
  28. , public EntityContext
  29. , private GameEntityContextRequestBus::Handler
  30. {
  31. public:
  32. AZ_COMPONENT(GameEntityContextComponent, "{DA235454-DD9C-468C-AE70-404E415BAA6C}");
  33. GameEntityContextComponent();
  34. ~GameEntityContextComponent() override;
  35. //////////////////////////////////////////////////////////////////////////
  36. // Component overrides
  37. void Init() override;
  38. void Activate() override;
  39. void Deactivate() override;
  40. //////////////////////////////////////////////////////////////////////////
  41. //////////////////////////////////////////////////////////////////////////
  42. // GameEntityContextRequestBus
  43. AZ::Uuid GetGameEntityContextId() override { return GetContextId(); }
  44. EntityContext* GetGameEntityContextInstance() override { return this; }
  45. void ResetGameContext() override;
  46. AZ::Entity* CreateGameEntity(const char* name) override;
  47. BehaviorEntity CreateGameEntityForBehaviorContext(const char* name) override;
  48. void AddGameEntity(AZ::Entity* entity) override;
  49. void DestroyGameEntity(const AZ::EntityId&) override;
  50. void DestroyGameEntityAndDescendants(const AZ::EntityId&) override;
  51. void ActivateGameEntity(const AZ::EntityId&) override;
  52. void DeactivateGameEntity(const AZ::EntityId&) override;
  53. bool LoadFromStream(AZ::IO::GenericStream& stream, bool remapIds) override;
  54. AZStd::string GetEntityName(const AZ::EntityId& id) override;
  55. //////////////////////////////////////////////////////////////////////////
  56. //////////////////////////////////////////////////////////////////////////
  57. void DestroyGameEntityInternal(const AZ::EntityId&, bool destroyChildren);
  58. //////////////////////////////////////////////////////////////////////////
  59. //////////////////////////////////////////////////////////////////////////
  60. // EntityContext
  61. AZ::Entity* CreateEntity(const char* name) override;
  62. void OnRootEntityReloaded() override;
  63. void OnContextEntitiesAdded(const EntityList& entities) override;
  64. void OnContextReset() override;
  65. bool ValidateEntitiesAreValidForContext(const EntityList& entities) override;
  66. //////////////////////////////////////////////////////////////////////////
  67. static void Reflect(AZ::ReflectContext* context);
  68. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  69. {
  70. provided.push_back(AZ_CRC_CE("GameEntityContextService"));
  71. }
  72. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  73. {
  74. incompatible.push_back(AZ_CRC_CE("GameEntityContextService"));
  75. }
  76. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  77. {
  78. required.push_back(AZ_CRC_CE("SliceSystemService"));
  79. }
  80. private:
  81. AzFramework::EntityVisibilityBoundsUnionSystem m_entityVisibilityBoundsUnionSystem;
  82. };
  83. } // namespace AzFramework
  84. #endif // AZFRAMEWORK_GAMEENTITYCONTEXTCOMPONENT_H