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.

преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Interval action class for subclassing.
  8. /// </summary>
  9. public class ActionInterval : ActionInstant
  10. {
  11. protected float timer;
  12. protected float timeScale;
  13. private float dtrdata;
  14. public ActionInterval(float tgtDuration)
  15. : base()
  16. {
  17. duration = tgtDuration;
  18. timeScale = 1F;
  19. dtr = 0;
  20. }
  21. /// <summary>
  22. /// Returns a copy of the action.
  23. /// </summary>
  24. public override ActionInstant clone()
  25. {
  26. return new ActionInterval(duration);
  27. }
  28. /// <summary>
  29. /// Returns the reversed version of the action, if it is possible.
  30. /// </summary>
  31. public override ActionInstant reverse()
  32. {
  33. throw new Exception("Can reverse only the reversable interval actions");
  34. }
  35. /// <summary>
  36. /// This method is called at the action start.
  37. /// </summary>
  38. public override void start()
  39. {
  40. base.start();
  41. running = true;
  42. timer = 0F;
  43. }
  44. /// <summary>
  45. /// This method is called after the interval action is stopped.
  46. /// </summary>
  47. public override void stop()
  48. {
  49. base.stop();
  50. running = false;
  51. }
  52. /// <summary>
  53. /// This method is called every frame update. Don't override this method, when inheriting, put your code in stepInterval instead.
  54. /// </summary>
  55. public override void step(float dt)
  56. {
  57. dt *= timeScale;
  58. base.step(dt);
  59. if (timer + dt > duration)
  60. {
  61. float odt = dt;
  62. dt = duration - timer;
  63. timer += odt;
  64. }
  65. else
  66. {
  67. timer += dt;
  68. }
  69. stepInterval(dt);
  70. if (timer > duration)
  71. {
  72. stop();
  73. dtr = timer - duration;
  74. }
  75. }
  76. /// <summary>
  77. /// This method is called every frame update. Put your code here.
  78. /// </summary>
  79. public virtual void stepInterval(float dt)
  80. {
  81. }
  82. /// <summary>
  83. /// Immediately changes the time scale for this action and all nested ones.
  84. /// </summary>
  85. public void setTimeScale(float ts)
  86. {
  87. timeScale = ts;
  88. }
  89. }
  90. }