EditorSequenceComponent.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 <AzCore/Component/TickBus.h>
  11. #include <Maestro/Bus/EditorSequenceComponentBus.h>
  12. #include "SequenceComponent.h"
  13. #include "../Cinematics/AnimSequence.h"
  14. namespace Maestro
  15. {
  16. class EditorSequenceComponent
  17. : public AzToolsFramework::Components::EditorComponentBase
  18. , public Maestro::EditorSequenceComponentRequestBus::Handler
  19. , public Maestro::SequenceComponentRequestBus::Handler
  20. , public AZ::TickBus::Handler // for refreshing propertyGrids after SetAnimatedPropertyValue events
  21. {
  22. public:
  23. AZ_EDITOR_COMPONENT(EditorSequenceComponent, EditorSequenceComponentTypeId); // EditorSequenceComponentTypeId is defined in EditorSequenceComponentBus.h
  24. using AnimatablePropertyAddress = Maestro::SequenceComponentRequests::AnimatablePropertyAddress;
  25. using AnimatedValue = Maestro::SequenceComponentRequests::AnimatedValue;
  26. EditorSequenceComponent();
  27. ~EditorSequenceComponent();
  28. //////////////////////////////////////////////////////////////////////////
  29. // AZ::Component interface implementation
  30. void Init() override;
  31. void Activate() override;
  32. void Deactivate() override;
  33. //////////////////////////////////////////////////////////////////////////
  34. //////////////////////////////////////////////////////////////////////////
  35. // EditorSequenceComponentRequestBus::Handler Interface
  36. void GetAllAnimatablePropertiesForComponent(IAnimNode::AnimParamInfos& addressList, AZ::EntityId id, AZ::ComponentId componentId) override;
  37. void GetAnimatableComponents(AZStd::vector<AZ::ComponentId>& componentIds, AZ::EntityId id) override;
  38. bool AddEntityToAnimate(AZ::EntityId entityToAnimate) override;
  39. void RemoveEntityToAnimate(AZ::EntityId removedEntityId) override;
  40. bool MarkEntityAsDirty() const override;
  41. AnimValueType GetValueType(const AZStd::string& animatableAddress) override;
  42. // ~EditorSequenceComponentRequestBus::Handler Interface
  43. //////////////////////////////////////////////////////////////////////////
  44. // SequenceComponentRequestBus::Handler Interface
  45. /**
  46. * Get the current value for a property
  47. * @param returnValue holds the value to get - this must be instance of one of the concrete subclasses of AnimatedValue, corresponding to the type of the property referenced by the animatedAdresss
  48. * @param animatedEntityId the entity Id of the entity containing the animatedAddress
  49. * @param animatedAddress identifies the component and property to be set
  50. */
  51. bool GetAnimatedPropertyValue(AnimatedValue& returnValue, const AZ::EntityId& animatedEntityId, const AnimatablePropertyAddress& animatableAddress) override;
  52. /**
  53. * Set a value for an animated property at the given address on the given entity.
  54. * @param animatedEntityId the entity Id of the entity containing the animatedAddress
  55. * @param animatedAddress identifies the component and property to be set
  56. * @param value the value to set - this must be instance of one of the concrete subclasses of AnimatedValue, corresponding to the type of the property referenced by the animatedAdresss
  57. * @return true if the value was changed.
  58. */
  59. bool SetAnimatedPropertyValue(const AZ::EntityId& animatedEntityId, const AnimatablePropertyAddress& animatableAddress, const AnimatedValue& value) override;
  60. AZ::Uuid GetAnimatedAddressTypeId(const AZ::EntityId& animatedEntityId, const Maestro::SequenceComponentRequests::AnimatablePropertyAddress& animatableAddress) override;
  61. void GetAssetDuration(AnimatedValue& returnValue, const AZ::EntityId& animatedEntityId, AZ::ComponentId componentId, const AZ::Data::AssetId& assetId) override;
  62. //////////////////////////////////////////////////////////////////////////
  63. //////////////////////////////////////////////////////////////////////////
  64. // TickBus - used to refresh property displays when values are animated
  65. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  66. //////////////////////////////////////////////////////////////////////////
  67. // TODO - this should be on a Bus, right?
  68. IAnimSequence* GetSequence() { return m_sequence.get(); }
  69. protected:
  70. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  71. {
  72. provided.push_back(AZ_CRC_CE("SequenceService"));
  73. }
  74. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  75. {
  76. // This guarantees that only one SequenceComponent will ever be on an entity
  77. incompatible.push_back(AZ_CRC_CE("SequenceService"));
  78. incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
  79. }
  80. // Required Reflect function.
  81. static void Reflect(AZ::ReflectContext* context);
  82. ////////////////////////////////////////////////////////////////////////
  83. void BuildGameEntity(AZ::Entity* gameEntity) override;
  84. ////////////////////////////////////////////////////////////////////////
  85. private:
  86. // pointer and id of the CryMovie anim sequence responsible for playback/recording
  87. AZStd::intrusive_ptr<IAnimSequence> m_sequence;
  88. uint32 m_sequenceId;
  89. static AZ::ScriptTimePoint s_lastPropertyRefreshTime;
  90. static const double s_refreshPeriodMilliseconds; // property refresh period for SetAnimatedPropertyValue events
  91. static const uint32 s_invalidSequenceId;
  92. };
  93. } // namespace Maestro