Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
Repozitorijs ir arhivēts. Tam var aplūkot failus un to var klonēt, bet nevar iesūtīt jaunas izmaiņas, kā arī atvērt jaunas problēmas/izmaiņu pieprasījumus.

125 rindas
3.3KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Basic action class for subclassing. To inherit interval actions, consider using the ActionInterval as the base class.
  8. /// </summary>
  9. public class ActionInstant
  10. {
  11. protected Actor target;
  12. protected Transform transform;
  13. protected Renderer renderer;
  14. protected bool is2d = false;
  15. private float durationValue = 0;
  16. private float dtrValue = 0;
  17. private bool isRunning = false;
  18. public ActionInstant()
  19. {
  20. }
  21. /// <summary>
  22. /// Returns a copy of the action.
  23. /// </summary>
  24. public virtual ActionInstant clone()
  25. {
  26. return new ActionInstant();
  27. }
  28. /// <summary>
  29. /// Returns the reversed version of the action, if it is possible.
  30. /// </summary>
  31. public virtual 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. Usable for instant and interval actions.
  37. /// </summary>
  38. public virtual void start()
  39. {
  40. if (target == null)
  41. throw new Exception("Can start the action only after it's atached to the actor");
  42. transform = target.transformCached;
  43. renderer = target.rendererCached;
  44. }
  45. /// <summary>
  46. /// This method is called at every frame update. Not usable for instant actions.
  47. /// </summary>
  48. public virtual void step(float dt)
  49. {
  50. if (target == null)
  51. throw new Exception("Can update the action only after it's atached to the actor");
  52. }
  53. /// <summary>
  54. /// This method is called after the interval action is stopped. Not usable for instant actions.
  55. /// </summary>
  56. public virtual void stop()
  57. {
  58. if (target == null)
  59. throw new Exception("Can stop the action only after it's atached to the actor");
  60. }
  61. /// <summary>
  62. /// This method sets the actor for the action.
  63. /// </summary>
  64. public void setActor(Actor actor)
  65. {
  66. target = actor;
  67. }
  68. /// <summary>
  69. /// Readonly property. Shows the remaining time of the action.
  70. /// </summary>
  71. public float duration
  72. {
  73. get
  74. {
  75. return durationValue;
  76. }
  77. protected set
  78. {
  79. durationValue = value;
  80. }
  81. }
  82. /// <summary>
  83. /// Readonly property. Shows if the action is running or not.
  84. /// </summary>
  85. public bool running
  86. {
  87. get
  88. {
  89. return isRunning;
  90. }
  91. protected set
  92. {
  93. isRunning = value;
  94. }
  95. }
  96. /// <summary>
  97. /// Readonly property. Contains the remaining tick time after action finished.
  98. /// </summary>
  99. public float dtr
  100. {
  101. get
  102. {
  103. return dtrValue;
  104. }
  105. protected set
  106. {
  107. dtrValue = value;
  108. }
  109. }
  110. }
  111. }