${Name}Component.h 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // {BEGIN_LICENSE}
  2. /*
  3. * Copyright (c) Contributors to the Open 3D Engine Project.
  4. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0 OR MIT
  7. *
  8. */
  9. // {END_LICENSE}
  10. #pragma once
  11. #include <AzCore/Component/Component.h>
  12. #include <${GemName}/${SanitizedCppName}Interface.h>
  13. namespace ${GemName}
  14. {
  15. /*
  16. * TODO: Register this component in your Gem's AZ::Module interface by inserting the following into the list of m_descriptors:
  17. * ${SanitizedCppName}Component::CreateDescriptor(),
  18. */
  19. class ${SanitizedCppName}Component
  20. : public AZ::Component
  21. , public ${SanitizedCppName}RequestBus::Handler
  22. {
  23. public:
  24. AZ_COMPONENT_DECL(${SanitizedCppName}Component);
  25. /*
  26. * Reflects component data into the reflection contexts, including the serialization, edit, and behavior contexts.
  27. */
  28. static void Reflect(AZ::ReflectContext* context);
  29. /*
  30. * Specifies the services that this component provides.
  31. * Other components can declare a dependency on these services. The system uses this
  32. * information to determine the order of component activation.
  33. */
  34. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  35. /*
  36. * Specifies the services that this component cannot operate with.
  37. * For example, if two components provide a similar service and the system cannot use the
  38. * services simultaneously, each of those components would specify the other component as
  39. * an incompatible service.
  40. * If an entity cannot have multiple instances of this component, include this component's
  41. * provided service in the list of incompatible services.
  42. */
  43. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  44. /*
  45. * Specifies the services that this component requires.
  46. * The system activates the required services before it activates this component.
  47. * It also deactivates the required services after it deactivates this component.
  48. * If a required service is missing before this component is activated, the system
  49. * returns an error and does not activate this component.
  50. */
  51. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  52. /*
  53. * Specifies the services that this component depends on, but does not require.
  54. * The system activates the dependent services before it activates this component.
  55. * It also deactivates the dependent services after it deactivates this component.
  56. * If a dependent service is missing before this component is activated, the system
  57. * does not return an error and still activates this component.
  58. */
  59. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  60. protected:
  61. /*
  62. * Puts this component into an active state.
  63. * The system calls this function once during activation of each entity that owns the
  64. * component. You must override this function. The system calls a component's Activate()
  65. * function only if all services and components that the component depends on are present
  66. * and active.
  67. */
  68. void Activate() override;
  69. /*
  70. * Deactivates this component.
  71. * The system calls this function when the owning entity is being deactivated. You must
  72. * override this function. As a best practice, ensure that this function returns this component
  73. * to a minimal footprint. The order of deactivation is the reverse of activation, so your
  74. * component is deactivated before the components it depends on.
  75. *
  76. * The system always calls a component's Deactivate() function before destroying the component.
  77. * However, deactivation is not always followed by the destruction of the component. An entity and
  78. * its components can be deactivated and reactivated without being destroyed. Ensure that your
  79. * Deactivate() implementation can handle this scenario.
  80. */
  81. void Deactivate() override;
  82. };
  83. } // namespace ${GemName}