EditorAttachmentComponent.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
  10. #include "AttachmentComponent.h"
  11. namespace AZ
  12. {
  13. namespace Render
  14. {
  15. /*!
  16. * In-editor attachment component.
  17. * \ref AttachmentComponent
  18. */
  19. class EditorAttachmentComponent
  20. : public AzToolsFramework::Components::EditorComponentBase
  21. {
  22. private:
  23. using Base = AzToolsFramework::Components::EditorComponentBase;
  24. public:
  25. AZ_COMPONENT(EditorAttachmentComponent, "{DA6072FD-E696-47D8-81D9-1F77D3464200}", Base);
  26. static void Reflect(AZ::ReflectContext* context);
  27. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  28. {
  29. AttachmentComponent::GetProvidedServices(provided);
  30. }
  31. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  32. {
  33. AttachmentComponent::GetIncompatibleServices(incompatible);
  34. }
  35. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  36. {
  37. AttachmentComponent::GetRequiredServices(required);
  38. }
  39. ~EditorAttachmentComponent() override = default;
  40. void BuildGameEntity(AZ::Entity* gameEntity) override;
  41. protected:
  42. //////////////////////////////////////////////////////////////////////////
  43. // AZ::Component interface implementation
  44. void Activate() override;
  45. void Deactivate() override;
  46. //////////////////////////////////////////////////////////////////////////
  47. AZ::u32 OnTargetIdChanged();
  48. AZ::u32 OnTargetBoneChanged();
  49. AZ::u32 OnTargetOffsetChanged();
  50. AZ::u32 OnAttachedInitiallyChanged();
  51. AZ::u32 OnScaleSourceChanged();
  52. //! Invoked when an attachment property changes
  53. void AttachOrDetachAsNecessary();
  54. //! For populating ComboBox
  55. AZStd::vector<AZStd::string> GetTargetBoneOptions() const;
  56. //! Create runtime configuration from editor configuration
  57. AttachmentConfiguration CreateAttachmentConfiguration() const;
  58. //! Create AZ::Transform from position and rotation
  59. AZ::Transform GetTargetOffset() const;
  60. //! Attach to this entity.
  61. AZ::EntityId m_targetId;
  62. //! Attach to this bone on target entity.
  63. AZStd::string m_targetBoneName;
  64. //! Offset from target bone's position.
  65. AZ::Vector3 m_positionOffset = AZ::Vector3::CreateZero();
  66. //! Offset from target bone's rotation.
  67. AZ::Vector3 m_rotationOffset = AZ::Vector3::CreateZero();
  68. //! Offset from target entity's scale.
  69. float m_uniformScaleOffset = 1.0f;
  70. //! Observe scale information from the specified source.
  71. AttachmentConfiguration::ScaleSource m_scaleSource = AttachmentConfiguration::ScaleSource::WorldScale;
  72. //! Whether to attach to target upon activation.
  73. //! If false, the entity remains detached until Attach() is called.
  74. bool m_attachedInitially = true;
  75. //! Implements actual attachment functionality
  76. AZ::Render::BoneFollower m_boneFollower;
  77. };
  78. } // namespace Render
  79. } // namespace AZ