ValueAnimationInfo.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../Container/Ptr.h"
  5. #include "../Container/RefCounted.h"
  6. #include "../Container/Vector.h"
  7. #include "../Scene/AnimationDefs.h"
  8. namespace Urho3D
  9. {
  10. class Object;
  11. class ValueAnimation;
  12. class Variant;
  13. struct VAnimEventFrame;
  14. /// Base class for a value animation instance, which includes animation runtime information and updates the target object's value automatically.
  15. class URHO3D_API ValueAnimationInfo : public RefCounted
  16. {
  17. public:
  18. /// Construct without target object.
  19. ValueAnimationInfo(ValueAnimation* animation, WrapMode wrapMode, float speed);
  20. /// Construct with target object.
  21. ValueAnimationInfo(Object* target, ValueAnimation* animation, WrapMode wrapMode, float speed);
  22. /// Copy construct.
  23. ValueAnimationInfo(const ValueAnimationInfo& other);
  24. /// Destruct.
  25. ~ValueAnimationInfo() override;
  26. /// Advance time position and apply. Return true when the animation is finished. No-op when the target object is not defined.
  27. bool Update(float timeStep);
  28. /// Set time position and apply. Return true when the animation is finished. No-op when the target object is not defined.
  29. bool SetTime(float time);
  30. /// Set wrap mode.
  31. void SetWrapMode(WrapMode wrapMode) { wrapMode_ = wrapMode; }
  32. /// Set speed.
  33. void SetSpeed(float speed) { speed_ = speed; }
  34. /// Return target object.
  35. Object* GetTarget() const;
  36. /// Return animation.
  37. ValueAnimation* GetAnimation() const { return animation_; }
  38. /// Return wrap mode.
  39. WrapMode GetWrapMode() const { return wrapMode_; }
  40. /// Return time position.
  41. float GetTime() const { return currentTime_; }
  42. /// Return speed.
  43. float GetSpeed() const { return speed_; }
  44. protected:
  45. /// Apply new animation value to the target object. Called by Update().
  46. virtual void ApplyValue(const Variant& newValue);
  47. /// Calculate scaled time.
  48. float CalculateScaledTime(float currentTime, bool& finished) const;
  49. /// Return event frames.
  50. void GetEventFrames(float beginTime, float endTime, Vector<const VAnimEventFrame*>& eventFrames);
  51. /// Target object.
  52. WeakPtr<Object> target_;
  53. /// Attribute animation.
  54. SharedPtr<ValueAnimation> animation_;
  55. /// Wrap mode.
  56. WrapMode wrapMode_;
  57. /// Animation speed.
  58. float speed_;
  59. /// Current time.
  60. float currentTime_;
  61. /// Last scaled time.
  62. float lastScaledTime_;
  63. };
  64. }