選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
このリポジトリはアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュや、課題・プルリクエストのオープンはできません。

200 行
6.2KB

  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. /// <summary>
  12. /// Axis locks - the action will try to preserve tha values of these axises when moving or rotating the target.
  13. /// </summary>
  14. public Axises locks = Axises.none;
  15. /// <summary>
  16. /// Sets if the action should stop when the actor's StopAllActions method is called.
  17. /// </summary>
  18. public bool unstopable = false;
  19. protected Actor target;
  20. protected Transform transform;
  21. protected Renderer renderer;
  22. private float durationValue = 0;
  23. private float dtrValue = 0;
  24. private bool isRunning = false;
  25. public ActionInstant()
  26. {
  27. }
  28. /// <summary>
  29. /// Returns a copy of the action.
  30. /// </summary>
  31. public virtual ActionInstant Clone()
  32. {
  33. return new ActionInstant();
  34. }
  35. /// <summary>
  36. /// Returns the reversed version of the action, if it is possible.
  37. /// </summary>
  38. public virtual ActionInstant Reverse()
  39. {
  40. throw new Exception("Can reverse only the reversable interval actions");
  41. }
  42. /// <summary>
  43. /// This method is called at the action start. Usable for instant and interval actions.
  44. /// </summary>
  45. public virtual void Start()
  46. {
  47. if (target == null)
  48. throw new Exception("Can start the action only after it's atached to the actor");
  49. transform = target.transformCached;
  50. renderer = target.rendererCached;
  51. }
  52. /// <summary>
  53. /// This method is called at every frame update. Not usable for instant actions.
  54. /// </summary>
  55. public virtual void StepTimer(float dt)
  56. {
  57. if (target == null)
  58. throw new Exception("Can update the action only after it's atached to the actor");
  59. }
  60. /// <summary>
  61. /// This method is called after the interval action is stopped. Not usable for instant actions.
  62. /// </summary>
  63. public virtual void Stop()
  64. {
  65. if (target == null)
  66. throw new Exception("Can stop the action only after it's atached to the actor");
  67. }
  68. /// <summary>
  69. /// This method sets the actor for the action.
  70. /// </summary>
  71. public void SetActor(Actor actor)
  72. {
  73. target = actor;
  74. }
  75. /// <summary>
  76. /// This method modifies the given vector to keep the locked axises untouched.
  77. /// </summary>
  78. protected void LockAxises(ref Vector3 point)
  79. {
  80. {
  81. if (target == null)
  82. throw new Exception("Can calculate axises only after the action is atached to the actor");
  83. }
  84. switch (locks)
  85. {
  86. case Axises.x:
  87. point.x = transform.position.x;
  88. break;
  89. case Axises.y:
  90. point.y = transform.position.y;
  91. break;
  92. case Axises.z:
  93. point.z = transform.position.z;
  94. break;
  95. case Axises.xy:
  96. point.x = transform.position.x;
  97. point.y = transform.position.y;
  98. break;
  99. case Axises.xz:
  100. point.x = transform.position.x;
  101. point.z = transform.position.z;
  102. break;
  103. case Axises.yz:
  104. point.y = transform.position.y;
  105. point.z = transform.position.z;
  106. break;
  107. case Axises.xyz:
  108. point.x = transform.position.x;
  109. point.y = transform.position.y;
  110. point.z = transform.position.z;
  111. break;
  112. case Axises.rx:
  113. point.x = transform.rotation.eulerAngles.x;
  114. break;
  115. case Axises.ry:
  116. point.y = transform.rotation.eulerAngles.y;
  117. break;
  118. case Axises.rz:
  119. point.z = transform.rotation.eulerAngles.z;
  120. break;
  121. case Axises.rxy:
  122. point.x = transform.rotation.eulerAngles.x;
  123. point.y = transform.rotation.eulerAngles.y;
  124. break;
  125. case Axises.rxz:
  126. point.x = transform.rotation.eulerAngles.x;
  127. point.z = transform.rotation.eulerAngles.z;
  128. break;
  129. case Axises.ryz:
  130. point.y = transform.rotation.eulerAngles.y;
  131. point.z = transform.rotation.eulerAngles.z;
  132. break;
  133. case Axises.rxyz:
  134. point.x = transform.rotation.eulerAngles.x;
  135. point.y = transform.rotation.eulerAngles.y;
  136. point.z = transform.rotation.eulerAngles.z;
  137. break;
  138. }
  139. }
  140. /// <summary>
  141. /// Readonly property. Shows the remaining time of the action.
  142. /// </summary>
  143. public float duration
  144. {
  145. get
  146. {
  147. return durationValue;
  148. }
  149. protected set
  150. {
  151. durationValue = value;
  152. }
  153. }
  154. /// <summary>
  155. /// Readonly property. Shows if the action is running or not.
  156. /// </summary>
  157. public bool running
  158. {
  159. get
  160. {
  161. return isRunning;
  162. }
  163. protected set
  164. {
  165. isRunning = value;
  166. }
  167. }
  168. /// <summary>
  169. /// Readonly property. Contains the remaining tick time after action finished.
  170. /// </summary>
  171. public float dtr
  172. {
  173. get
  174. {
  175. return dtrValue;
  176. }
  177. protected set
  178. {
  179. dtrValue = value;
  180. }
  181. }
  182. }
  183. }