No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
Este repositorio está archivado. Puede ver los archivos y clonarlo, pero no puede subir cambios o reportar incidencias ni pedir Pull Requests.

87 líneas
2.3KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Runs the given action the several times. Also can repeat the action forever.
  8. /// </summary>
  9. class ActionRepeat : ActionInterval
  10. {
  11. protected ActionInterval action;
  12. protected int count;
  13. protected int counter;
  14. protected bool forever;
  15. public ActionRepeat(ActionInterval tgtAction, int tgtCount)
  16. : base(0)
  17. {
  18. action = tgtAction;
  19. count = tgtCount;
  20. counter = 0;
  21. forever = false;
  22. }
  23. public ActionRepeat(ActionInterval tgtAction)
  24. : base(0)
  25. {
  26. action = tgtAction;
  27. count = 0;
  28. counter = 0;
  29. forever = true;
  30. }
  31. /// <summary>
  32. /// Returns a copy of the action.
  33. /// </summary>
  34. public override ActionInstant clone()
  35. {
  36. return new ActionRepeat((ActionInterval)action.clone(), count);
  37. }
  38. /// <summary>
  39. /// Returns the reversed version of the action, if it is possible.
  40. /// </summary>
  41. public override ActionInstant reverse()
  42. {
  43. return new ActionRepeat((ActionInterval)action.reverse(), count);
  44. }
  45. /// <summary>
  46. /// This method is called at the action start.
  47. /// </summary>
  48. public override void start()
  49. {
  50. base.start();
  51. action.setActor(target);
  52. action.start();
  53. counter = 0;
  54. }
  55. /// <summary>
  56. /// This method is called every frame update.
  57. /// </summary>
  58. public override void step(float dt)
  59. {
  60. dt *= timeScale;
  61. if (action.running)
  62. {
  63. action.step(dt);
  64. }
  65. if (!action.running && (forever || counter < count - 1))
  66. {
  67. float dtrdata = action.dtr;
  68. action.start();
  69. if (dtrdata > 0)
  70. action.step(dtrdata);
  71. counter += 1;
  72. }
  73. else if (!action.running && counter >= count - 1)
  74. {
  75. dtr = action.dtr;
  76. stop();
  77. }
  78. }
  79. }
  80. }