ObjectAnimation.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Resource/Resource.h"
  5. #include "../Scene/AnimationDefs.h"
  6. namespace Urho3D
  7. {
  8. class ValueAnimation;
  9. class ValueAnimationInfo;
  10. class XMLElement;
  11. class JSONValue;
  12. /// Object animation class, an object animation include one or more attribute animations and theirs wrap mode and speed for an Animatable object.
  13. class URHO3D_API ObjectAnimation : public Resource
  14. {
  15. URHO3D_OBJECT(ObjectAnimation, Resource);
  16. public:
  17. /// Construct.
  18. explicit ObjectAnimation(Context* context);
  19. /// Destruct.
  20. ~ObjectAnimation() override;
  21. /// Register object factory.
  22. /// @nobind
  23. static void RegisterObject(Context* context);
  24. /// Load resource from stream. May be called from a worker thread. Return true if successful.
  25. bool BeginLoad(Deserializer& source) override;
  26. /// Save resource. Return true if successful.
  27. bool Save(Serializer& dest) const override;
  28. /// Load from XML data. Return true if successful.
  29. bool LoadXML(const XMLElement& source);
  30. /// Save as XML data. Return true if successful.
  31. bool SaveXML(XMLElement& dest) const;
  32. /// Load from JSON data. Return true if successful.
  33. bool LoadJSON(const JSONValue& source);
  34. /// Save as JSON data. Return true if successful.
  35. bool SaveJSON(JSONValue& dest) const;
  36. /// Add attribute animation, attribute name can in following format: "attribute" or "#0/#1/attribute" or ""#0/#1/@component#1/attribute.
  37. void AddAttributeAnimation
  38. (const String& name, ValueAnimation* attributeAnimation, WrapMode wrapMode = WM_LOOP, float speed = 1.0f);
  39. /// Remove attribute animation, attribute name can in following format: "attribute" or "#0/#1/attribute" or ""#0/#1/@component#1/attribute.
  40. void RemoveAttributeAnimation(const String& name);
  41. /// Remove attribute animation.
  42. void RemoveAttributeAnimation(ValueAnimation* attributeAnimation);
  43. /// Return attribute animation by name.
  44. /// @property{get_attributeAnimations}
  45. ValueAnimation* GetAttributeAnimation(const String& name) const;
  46. /// Return attribute animation wrap mode by name.
  47. /// @property{get_wrapModes}
  48. WrapMode GetAttributeAnimationWrapMode(const String& name) const;
  49. /// Return attribute animation speed by name.
  50. /// @property{get_speeds}
  51. float GetAttributeAnimationSpeed(const String& name) const;
  52. /// Return all attribute animations infos.
  53. const HashMap<String, SharedPtr<ValueAnimationInfo>>& GetAttributeAnimationInfos() const { return attributeAnimationInfos_; }
  54. /// Return attribute animation info by name.
  55. ValueAnimationInfo* GetAttributeAnimationInfo(const String& name) const;
  56. private:
  57. /// Send attribute animation added event.
  58. void SendAttributeAnimationAddedEvent(const String& name);
  59. /// Send attribute animation remove event.
  60. void SendAttributeAnimationRemovedEvent(const String& name);
  61. /// Name to attribute animation info mapping.
  62. HashMap<String, SharedPtr<ValueAnimationInfo>> attributeAnimationInfos_;
  63. };
  64. }