${Name}ComponentController.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #include <Components/${Name}ComponentController.h>
  9. #include <AzCore/Asset/AssetManager.h>
  10. #include <AzCore/Asset/AssetManagerBus.h>
  11. #include <AzCore/Asset/AssetSerializer.h>
  12. #include <AzCore/Serialization/SerializeContext.h>
  13. #include <AzFramework/Entity/EntityContextBus.h>
  14. #include <AzFramework/Entity/EntityContext.h>
  15. #include <AzFramework/Scene/Scene.h>
  16. #include <AzFramework/Scene/SceneSystemInterface.h>
  17. #include <AzCore/RTTI/BehaviorContext.h>
  18. #include <Atom/RPI.Public/Scene.h>
  19. namespace ${Name}
  20. {
  21. void ${Name}ComponentConfig::Reflect(AZ::ReflectContext* context)
  22. {
  23. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  24. {
  25. serializeContext->Class<${Name}ComponentConfig>()
  26. ;
  27. }
  28. }
  29. void ${Name}ComponentController::Reflect(AZ::ReflectContext* context)
  30. {
  31. ${Name}ComponentConfig::Reflect(context);
  32. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  33. {
  34. serializeContext->Class<${Name}ComponentController>()
  35. ->Version(0)
  36. ->Field("Configuration", &${Name}ComponentController::m_configuration);
  37. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  38. {
  39. editContext->Class<${Name}ComponentController>(
  40. "${Name}ComponentController", "")
  41. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  42. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  43. ->DataElement(AZ::Edit::UIHandlers::Default, &${Name}ComponentController::m_configuration, "Configuration", "")
  44. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  45. ;
  46. }
  47. }
  48. }
  49. void ${Name}ComponentController::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  50. {
  51. dependent.push_back(AZ_CRC_CE("TransformService"));
  52. }
  53. void ${Name}ComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  54. {
  55. provided.push_back(AZ_CRC_CE("${Name}Service"));
  56. }
  57. void ${Name}ComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  58. {
  59. incompatible.push_back(AZ_CRC_CE("${Name}Service"));
  60. }
  61. void ${Name}ComponentController::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  62. {
  63. required.push_back(AZ_CRC_CE("TransformService"));
  64. }
  65. ${Name}ComponentController::${Name}ComponentController(const ${Name}ComponentConfig& config)
  66. : m_configuration(config)
  67. {
  68. }
  69. void ${Name}ComponentController::Activate(AZ::EntityId entityId)
  70. {
  71. m_entityId = entityId;
  72. AZ::TransformNotificationBus::Handler::BusConnect(m_entityId);
  73. m_featureProcessor = AZ::RPI::Scene::GetFeatureProcessorForEntity<${Name}FeatureProcessorInterface>(entityId);
  74. AZ_Assert(m_featureProcessor, "${Name}ComponentController was unable to find a ${Name}FeatureProcessor on the EntityContext provided.");
  75. }
  76. void ${Name}ComponentController::Deactivate()
  77. {
  78. AZ::TransformNotificationBus::Handler::BusDisconnect();
  79. }
  80. void ${Name}ComponentController::SetConfiguration(const ${Name}ComponentConfig& config)
  81. {
  82. m_configuration = config;
  83. }
  84. const ${Name}ComponentConfig& ${Name}ComponentController::GetConfiguration() const
  85. {
  86. return m_configuration;
  87. }
  88. void ${Name}ComponentController::OnTransformChanged([[maybe_unused]] const AZ::Transform& local, [[maybe_unused]] const AZ::Transform& world)
  89. {
  90. if (!m_featureProcessor)
  91. {
  92. return;
  93. }
  94. }
  95. }