EditorRandomTimedSpawnerComponent.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 "EditorRandomTimedSpawnerComponent.h"
  9. #include <AzCore/Serialization/EditContext.h>
  10. namespace LmbrCentral
  11. {
  12. void EditorRandomTimedSpawnerConfiguration::Reflect(AZ::ReflectContext * context)
  13. {
  14. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  15. {
  16. serializeContext->Class<EditorRandomTimedSpawnerConfiguration, RandomTimedSpawnerConfiguration>()
  17. ->Version(1);
  18. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  19. {
  20. editContext->Class<RandomTimedSpawnerConfiguration>("RandomTimedSpawner Configuration", "")
  21. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  22. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  23. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  24. ->DataElement(AZ::Edit::UIHandlers::Default, &RandomTimedSpawnerConfiguration::m_enabled, "Enabled", "")
  25. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &RandomTimedSpawnerConfiguration::m_randomDistribution, "Random Distribution", "")
  26. ->EnumAttribute(AZ::RandomDistributionType::Normal, "Normal")
  27. ->EnumAttribute(AZ::RandomDistributionType::UniformReal, "Uniform Real")
  28. ->ClassElement(AZ::Edit::ClassElements::Group, "Timing")
  29. ->Attribute(AZ::Edit::Attributes::AutoExpand, false)
  30. ->DataElement(AZ::Edit::UIHandlers::Default, &RandomTimedSpawnerConfiguration::m_spawnDelay, "Spawn Delay", "Time in seconds it takes to spawn")
  31. ->DataElement(AZ::Edit::UIHandlers::Default, &RandomTimedSpawnerConfiguration::m_spawnDelayVariation, "Spawn Delay Variation", "Variation applied to the spawn delay")
  32. ;
  33. }
  34. }
  35. }
  36. void EditorRandomTimedSpawnerComponent::Reflect(AZ::ReflectContext* context)
  37. {
  38. if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  39. {
  40. serializeContext->Class<EditorRandomTimedSpawnerComponent, AzToolsFramework::Components::EditorComponentBase>()
  41. ->Version(1)
  42. ->Field("m_config", &EditorRandomTimedSpawnerComponent::m_config)
  43. ;
  44. AZ::EditContext* editContext = serializeContext->GetEditContext();
  45. if (editContext)
  46. {
  47. editContext->Class<EditorRandomTimedSpawnerComponent>("Random Timed Spawner", "")
  48. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  49. ->Attribute(AZ::Edit::Attributes::Category, "Gameplay")
  50. ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/RandomTimedSpawner.svg")
  51. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/RandomTimedSpawner.svg")
  52. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  53. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  54. ->DataElement(AZ::Edit::UIHandlers::Default, &EditorRandomTimedSpawnerComponent::m_config, "m_config", "No Description")
  55. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  56. ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
  57. ;
  58. }
  59. }
  60. EditorRandomTimedSpawnerConfiguration::Reflect(context);
  61. }
  62. void EditorRandomTimedSpawnerComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  63. {
  64. provided.push_back(AZ_CRC_CE("RandomTimedSpawnerService"));
  65. }
  66. void EditorRandomTimedSpawnerComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  67. {
  68. //Only compatible with Box and Cylinder shapes
  69. incompatible.push_back(AZ_CRC_CE("CapsuleShapeService"));
  70. incompatible.push_back(AZ_CRC_CE("SphereShapeService"));
  71. incompatible.push_back(AZ_CRC_CE("CompoundShapeService"));
  72. incompatible.push_back(AZ_CRC_CE("TubeShapeService"));
  73. incompatible.push_back(AZ_CRC_CE("PrismShapeService"));
  74. incompatible.push_back(AZ_CRC_CE("PolygonPrismShapeService"));
  75. }
  76. void EditorRandomTimedSpawnerComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  77. {
  78. required.push_back(AZ_CRC_CE("TransformService"));
  79. required.push_back(AZ_CRC_CE("ShapeService"));
  80. required.push_back(AZ_CRC_CE("SpawnerService"));
  81. }
  82. void EditorRandomTimedSpawnerComponent::Activate()
  83. {
  84. RandomTimedSpawnerComponentRequestBus::Handler::BusConnect(GetEntityId());
  85. }
  86. void EditorRandomTimedSpawnerComponent::Deactivate()
  87. {
  88. RandomTimedSpawnerComponentRequestBus::Handler::BusDisconnect(GetEntityId());
  89. }
  90. void EditorRandomTimedSpawnerComponent::BuildGameEntity(AZ::Entity* gameEntity)
  91. {
  92. gameEntity->CreateComponent<RandomTimedSpawnerComponent>(&m_config);
  93. }
  94. } //namespace LmbrCentral