EditorLookAtComponent.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #pragma once
  9. #include <AzCore/Component/EntityBus.h>
  10. #include <AzCore/Component/TickBus.h>
  11. #include <AzCore/Component/TransformBus.h>
  12. #include <AzCore/Math/Transform.h>
  13. #include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
  14. namespace AZ
  15. {
  16. class ReflectContext;
  17. }
  18. namespace LmbrCentral
  19. {
  20. //=========================================================================
  21. // EditorLookAtComponent
  22. //=========================================================================
  23. class EditorLookAtComponent
  24. : public AzToolsFramework::Components::EditorComponentBase
  25. , private AZ::TransformNotificationBus::MultiHandler
  26. , private AZ::TickBus::Handler
  27. , private AZ::EntityBus::Handler
  28. {
  29. public:
  30. AZ_COMPONENT(EditorLookAtComponent, "{68D07AA1-49E9-4283-9697-7F887EB19C91}", AzToolsFramework::Components::EditorComponentBase);
  31. //=====================================================================
  32. // AZ::Component
  33. void Activate() override;
  34. void Deactivate() override;
  35. //=====================================================================
  36. //=====================================================================
  37. // TransformBus
  38. void OnTransformChanged(const AZ::Transform& /*local*/, const AZ::Transform& /*world*/) override;
  39. //=====================================================================
  40. //=====================================================================
  41. // TickBus
  42. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  43. //=====================================================================
  44. //=====================================================================
  45. // EntityBus
  46. void OnEntityActivated(const AZ::EntityId& entityId) override;
  47. void OnEntityDeactivated(const AZ::EntityId& entityId) override;
  48. //=====================================================================
  49. //=====================================================================
  50. // EditorComponentBase
  51. void BuildGameEntity(AZ::Entity* gameEntity) override;
  52. //=====================================================================
  53. protected:
  54. static void Reflect(AZ::ReflectContext* context);
  55. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  56. {
  57. provided.push_back(AZ_CRC_CE("LookAtService"));
  58. }
  59. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  60. {
  61. required.push_back(AZ_CRC_CE("TransformService"));
  62. }
  63. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  64. {
  65. incompatible.push_back(AZ_CRC_CE("LookAtService"));
  66. }
  67. private:
  68. void OnTargetChanged();
  69. void RecalculateTransform();
  70. // Serialized data
  71. AZ::EntityId m_targetId;
  72. AZ::Transform::Axis m_forwardAxis;
  73. // Transient data
  74. AZ::EntityId m_oldTargetId;
  75. };
  76. } // namespace LmbrCentral