AMTranslationAction.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. using System;
  2. using UnityEngine;
  3. [Serializable]
  4. public class AMTranslationAction : AMAction
  5. {
  6. public override string ToString(int codeLanguage, int frameRate)
  7. {
  8. if (this.path.Length <= 1)
  9. {
  10. return null;
  11. }
  12. if (this.getNumberOfFrames() <= 0)
  13. {
  14. return null;
  15. }
  16. string text;
  17. if (codeLanguage == 0)
  18. {
  19. text = string.Concat(new object[]
  20. {
  21. "AMTween.MoveTo (obj.gameObject, AMTween.Hash (\"delay\", ",
  22. base.getWaitTime(frameRate, 0f),
  23. "f, \"time\", ",
  24. this.getTime(frameRate),
  25. "f, "
  26. });
  27. if (this.path.Length == 2)
  28. {
  29. text += "\"position\", ";
  30. string text2 = text;
  31. text = string.Concat(new object[]
  32. {
  33. text2,
  34. "new Vector3(",
  35. this.path[1].x,
  36. "f, ",
  37. this.path[1].y,
  38. "f, ",
  39. this.path[1].z,
  40. "f), "
  41. });
  42. }
  43. else
  44. {
  45. text += "\"path\", new Vector3[]{";
  46. for (int i = 0; i < this.path.Length; i++)
  47. {
  48. string text2 = text;
  49. text = string.Concat(new object[]
  50. {
  51. text2,
  52. "new Vector3(",
  53. this.path[i].x,
  54. "f, ",
  55. this.path[i].y,
  56. "f, ",
  57. this.path[i].z,
  58. "f)"
  59. });
  60. if (i < this.path.Length - 1)
  61. {
  62. text += ", ";
  63. }
  64. }
  65. text += "}, ";
  66. }
  67. text = text + base.getEaseString(codeLanguage) + "));";
  68. }
  69. else
  70. {
  71. text = string.Concat(new object[]
  72. {
  73. "AMTween.MoveTo (obj.gameObject, {\"delay\": ",
  74. base.getWaitTime(frameRate, 0f),
  75. ", \"time\": ",
  76. this.getTime(frameRate),
  77. ", "
  78. });
  79. if (this.path.Length == 2)
  80. {
  81. text += "\"position\": ";
  82. string text2 = text;
  83. text = string.Concat(new object[]
  84. {
  85. text2,
  86. " Vector3(",
  87. this.path[1].x,
  88. ", ",
  89. this.path[1].y,
  90. ", ",
  91. this.path[1].z,
  92. "), "
  93. });
  94. }
  95. else
  96. {
  97. text += "\"path\": [";
  98. for (int j = 0; j < this.path.Length; j++)
  99. {
  100. string text2 = text;
  101. text = string.Concat(new object[]
  102. {
  103. text2,
  104. " Vector3(",
  105. this.path[j].x,
  106. ", ",
  107. this.path[j].y,
  108. ", ",
  109. this.path[j].z,
  110. ")"
  111. });
  112. if (j < this.path.Length - 1)
  113. {
  114. text += ", ";
  115. }
  116. }
  117. text += "], ";
  118. }
  119. text = text + base.getEaseString(codeLanguage) + "});";
  120. }
  121. return text;
  122. }
  123. public override int getNumberOfFrames()
  124. {
  125. return this.endFrame - this.startFrame;
  126. }
  127. public float getTime(int frameRate)
  128. {
  129. return (float)this.getNumberOfFrames() / (float)frameRate;
  130. }
  131. public override void execute(int frameRate, float delay, string trackId)
  132. {
  133. if (!this.obj)
  134. {
  135. return;
  136. }
  137. if (this.path.Length <= 1)
  138. {
  139. return;
  140. }
  141. if (this.getNumberOfFrames() <= 0)
  142. {
  143. return;
  144. }
  145. if (this.path.Length == 2)
  146. {
  147. if (base.hasCustomEase())
  148. {
  149. AMTween.MoveTo(this.obj.gameObject, AMTween.Hash(new object[]
  150. {
  151. "trackid",
  152. trackId,
  153. "delay",
  154. base.getWaitTime(frameRate, delay),
  155. "time",
  156. this.getTime(frameRate),
  157. "position",
  158. this.path[1],
  159. "easecurve",
  160. base.easeCurve
  161. }));
  162. }
  163. else
  164. {
  165. AMTween.MoveTo(this.obj.gameObject, AMTween.Hash(new object[]
  166. {
  167. "trackid",
  168. trackId,
  169. "delay",
  170. base.getWaitTime(frameRate, delay),
  171. "time",
  172. this.getTime(frameRate),
  173. "position",
  174. this.path[1],
  175. "easetype",
  176. (AMTween.EaseType)this.easeType
  177. }));
  178. }
  179. return;
  180. }
  181. if (base.hasCustomEase())
  182. {
  183. AMTween.MoveTo(this.obj.gameObject, AMTween.Hash(new object[]
  184. {
  185. "trackid",
  186. trackId,
  187. "delay",
  188. base.getWaitTime(frameRate, delay),
  189. "time",
  190. this.getTime(frameRate),
  191. "path",
  192. this.path,
  193. "easecurve",
  194. base.easeCurve
  195. }));
  196. }
  197. else
  198. {
  199. AMTween.MoveTo(this.obj.gameObject, AMTween.Hash(new object[]
  200. {
  201. "trackid",
  202. trackId,
  203. "delay",
  204. base.getWaitTime(frameRate, delay),
  205. "time",
  206. this.getTime(frameRate),
  207. "path",
  208. this.path,
  209. "easetype",
  210. (AMTween.EaseType)this.easeType
  211. }));
  212. }
  213. }
  214. public override AnimatorTimeline.JSONAction getJSONAction(int frameRate)
  215. {
  216. if (!this.obj)
  217. {
  218. return null;
  219. }
  220. if (this.path.Length <= 1)
  221. {
  222. return null;
  223. }
  224. if (this.getNumberOfFrames() <= 0)
  225. {
  226. return null;
  227. }
  228. AnimatorTimeline.JSONAction jsonaction = new AnimatorTimeline.JSONAction();
  229. jsonaction.go = this.obj.gameObject.name;
  230. jsonaction.method = "moveto";
  231. jsonaction.delay = base.getWaitTime(frameRate, 0f);
  232. jsonaction.time = this.getTime(frameRate);
  233. base.setupJSONActionEase(jsonaction);
  234. if (this.path.Length == 2)
  235. {
  236. jsonaction.setPath(new Vector3[]
  237. {
  238. this.path[1]
  239. });
  240. }
  241. else
  242. {
  243. jsonaction.setPath(this.path);
  244. }
  245. return jsonaction;
  246. }
  247. public int endFrame;
  248. public Transform obj;
  249. public Vector3[] path;
  250. }