AMOrientationAction.cs 6.7 KB

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