2
0

ScaleTo.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Urho;
  2. namespace Urho.Actions
  3. {
  4. public class ScaleTo : FiniteTimeAction
  5. {
  6. public float EndScaleX { get; }
  7. public float EndScaleY { get; }
  8. public float EndScaleZ { get; }
  9. #region Constructors
  10. public ScaleTo (float duration, float scale) : this (duration, scale, scale, scale)
  11. {
  12. }
  13. public ScaleTo (float duration, float scaleX, float scaleY, float scaleZ) : base (duration)
  14. {
  15. EndScaleX = scaleX;
  16. EndScaleY = scaleY;
  17. EndScaleZ = scaleZ;
  18. }
  19. #endregion Constructors
  20. public override FiniteTimeAction Reverse()
  21. {
  22. throw new System.NotImplementedException ();
  23. }
  24. protected internal override ActionState StartAction(Node target)
  25. {
  26. return new ScaleToState (this, target);
  27. }
  28. }
  29. public class ScaleToState : FiniteTimeActionState
  30. {
  31. protected float DeltaX;
  32. protected float DeltaY;
  33. protected float DeltaZ;
  34. protected float EndScaleX;
  35. protected float EndScaleY;
  36. protected float EndScaleZ;
  37. protected float StartScaleX;
  38. protected float StartScaleY;
  39. protected float StartScaleZ;
  40. public ScaleToState (ScaleTo action, Node target)
  41. : base (action, target)
  42. {
  43. var scale = target.Scale;
  44. StartScaleX = scale.X;
  45. StartScaleY = scale.Y;
  46. StartScaleZ = scale.Z;
  47. EndScaleX = action.EndScaleX;
  48. EndScaleY = action.EndScaleY;
  49. EndScaleZ = action.EndScaleZ;
  50. DeltaX = EndScaleX - StartScaleX;
  51. DeltaY = EndScaleY - StartScaleY;
  52. DeltaZ = EndScaleZ - StartScaleZ;
  53. }
  54. public override void Update (float time)
  55. {
  56. if (Target != null)
  57. {
  58. Target.Scale = new Vector3(StartScaleX + DeltaX * time, StartScaleY + DeltaY * time, StartScaleZ + DeltaZ * time);
  59. }
  60. }
  61. }
  62. }