CameraControllerComponent.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 <Atom/Component/DebugCamera/CameraControllerComponent.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. namespace AZ
  11. {
  12. namespace Debug
  13. {
  14. void CameraControllerComponent::Reflect(AZ::ReflectContext* context)
  15. {
  16. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  17. {
  18. serializeContext->Class<CameraControllerComponent, AZ::Component>()
  19. ->Version(1);
  20. }
  21. }
  22. void CameraControllerComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  23. {
  24. required.push_back(AZ_CRC("TransformService", 0x8ee22c50));
  25. required.push_back(AZ_CRC("CameraService", 0x1dd1caa4));
  26. }
  27. void CameraControllerComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  28. {
  29. provided.push_back(AZ_CRC("CameraControllerService", 0xc35788f9));
  30. }
  31. void CameraControllerComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  32. {
  33. incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
  34. }
  35. void CameraControllerComponent::Enable(TypeId typeId)
  36. {
  37. // Enable this controller if type id matches, otherwise disable this controller
  38. if (typeId == RTTI_GetType())
  39. {
  40. if (!m_enabled)
  41. {
  42. m_enabled = true;
  43. OnEnabled();
  44. }
  45. }
  46. else
  47. {
  48. if (m_enabled)
  49. {
  50. m_enabled = false;
  51. OnDisabled();
  52. }
  53. }
  54. }
  55. void CameraControllerComponent::Disable()
  56. {
  57. if (m_enabled)
  58. {
  59. m_enabled = false;
  60. OnDisabled();
  61. }
  62. }
  63. void CameraControllerComponent::Reset()
  64. {
  65. if (m_enabled)
  66. {
  67. OnDisabled();
  68. OnEnabled();
  69. }
  70. }
  71. void CameraControllerComponent::Activate()
  72. {
  73. CameraControllerRequestBus::Handler::BusConnect(GetEntityId());
  74. }
  75. void CameraControllerComponent::Deactivate()
  76. {
  77. if (m_enabled)
  78. {
  79. m_enabled = false;
  80. OnDisabled();
  81. }
  82. CameraControllerRequestBus::Handler::BusDisconnect();
  83. }
  84. } // namespace Debug
  85. } // namespace AZ