You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

69 lines
1.5KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. class ActionRepeat : ActionInterval
  5. {
  6. protected ActionInterval action;
  7. protected int count;
  8. protected int counter;
  9. protected bool forever;
  10. public ActionRepeat(ActionInterval tgtAction, int tgtCount)
  11. : base(0)
  12. {
  13. action = tgtAction;
  14. count = tgtCount;
  15. counter = 0;
  16. forever = false;
  17. }
  18. public ActionRepeat(ActionInterval tgtAction)
  19. : base(0)
  20. {
  21. action = tgtAction;
  22. count = 0;
  23. counter = 0;
  24. forever = true;
  25. }
  26. public override Action clone()
  27. {
  28. return new ActionRepeat((ActionInterval) action.clone(), count);
  29. }
  30. public override Action reverse()
  31. {
  32. return new ActionRepeat((ActionInterval) action.reverse(), count);
  33. }
  34. public override void start()
  35. {
  36. base.start();
  37. action.setActor(target);
  38. action.start();
  39. counter = 0;
  40. }
  41. public override void step(float dt)
  42. {
  43. dt *= timeScale;
  44. if (action.isRunning())
  45. {
  46. action.step(dt);
  47. }
  48. if (!action.isRunning() && (forever || counter < count - 1))
  49. {
  50. float dtrdata = action.dtr;
  51. action.start();
  52. if (dtrdata > 0)
  53. action.step(dtrdata);
  54. counter += 1;
  55. }
  56. else if (!action.isRunning() && counter >= count - 1)
  57. {
  58. dtr = action.dtr;
  59. stop();
  60. }
  61. }
  62. }