Speed.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Urho;
  2. namespace Urho.Actions
  3. {
  4. public class Speed : BaseAction
  5. {
  6. public float SpeedValue { get; }
  7. protected internal FiniteTimeAction InnerAction { get; }
  8. #region Constructors
  9. public Speed (FiniteTimeAction action, float speedValue)
  10. {
  11. InnerAction = action;
  12. SpeedValue = speedValue;
  13. }
  14. #endregion Constructors
  15. protected internal override ActionState StartAction(Node target)
  16. {
  17. return new SpeedState (this, target);
  18. }
  19. public virtual FiniteTimeAction Reverse ()
  20. {
  21. return (FiniteTimeAction)(BaseAction)new Speed ((FiniteTimeAction)InnerAction.Reverse(), SpeedValue);
  22. }
  23. }
  24. #region Action state
  25. internal class SpeedState : ActionState
  26. {
  27. #region Properties
  28. public float Speed { get; }
  29. protected FiniteTimeActionState InnerActionState { get; }
  30. public override bool IsDone
  31. {
  32. get { return InnerActionState.IsDone; }
  33. }
  34. #endregion Properties
  35. public SpeedState (Speed action, Node target) : base (action, target)
  36. {
  37. this.InnerActionState = (FiniteTimeActionState)action.InnerAction.StartAction (target);
  38. this.Speed = action.SpeedValue;
  39. }
  40. protected internal override void Stop ()
  41. {
  42. InnerActionState.Stop ();
  43. base.Stop ();
  44. }
  45. protected internal override void Step (float dt)
  46. {
  47. InnerActionState.Step (dt * Speed);
  48. }
  49. }
  50. #endregion Action state
  51. }