AMEventAction.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using UnityEngine;
  5. [Serializable]
  6. public class AMEventAction : AMAction
  7. {
  8. public MethodInfo methodInfo
  9. {
  10. get
  11. {
  12. if (this.component == null)
  13. {
  14. return null;
  15. }
  16. if (this.cachedMethodInfo != null)
  17. {
  18. return this.cachedMethodInfo;
  19. }
  20. if (this.methodName == null)
  21. {
  22. return null;
  23. }
  24. try
  25. {
  26. this.cachedMethodInfo = this.component.GetType().GetMethod(this.methodName);
  27. }
  28. catch
  29. {
  30. this.cachedMethodInfo = null;
  31. Debug.LogError("MonoBehaviorでなければなりません。");
  32. }
  33. return this.cachedMethodInfo;
  34. }
  35. set
  36. {
  37. if (value != null)
  38. {
  39. this.methodName = value.Name;
  40. }
  41. else
  42. {
  43. this.methodName = null;
  44. }
  45. this.cachedMethodInfo = value;
  46. }
  47. }
  48. public override void execute(int frameRate, float delay, string trackId)
  49. {
  50. if (this.useSendMessage)
  51. {
  52. if (this.component == null || this.methodName == null)
  53. {
  54. return;
  55. }
  56. if (this.parameters == null || this.parameters.Count <= 0)
  57. {
  58. AMTween.SendMessage(this.component.gameObject, AMTween.Hash(new object[]
  59. {
  60. "delay",
  61. base.getWaitTime(frameRate, delay),
  62. "methodname",
  63. this.methodName
  64. }));
  65. }
  66. else
  67. {
  68. AMTween.SendMessage(this.component.gameObject, AMTween.Hash(new object[]
  69. {
  70. "trackid",
  71. trackId,
  72. "delay",
  73. base.getWaitTime(frameRate, delay),
  74. "methodname",
  75. this.methodName,
  76. "parameter",
  77. this.parameters[0].toObject()
  78. }));
  79. }
  80. return;
  81. }
  82. else
  83. {
  84. if (this.component == null || this.methodInfo == null)
  85. {
  86. return;
  87. }
  88. object[] array = new object[this.parameters.Count];
  89. for (int i = 0; i < this.parameters.Count; i++)
  90. {
  91. if (this.parameters[i].isArray())
  92. {
  93. this.setObjectInArray(ref array[i], this.parameters[i].lsArray);
  94. }
  95. else
  96. {
  97. array[i] = this.parameters[i].toObject();
  98. }
  99. }
  100. if (array.Length <= 0)
  101. {
  102. array = null;
  103. }
  104. AMTween.InvokeMethod(this.component, AMTween.Hash(new object[]
  105. {
  106. "trackid",
  107. trackId,
  108. "delay",
  109. base.getWaitTime(frameRate, delay),
  110. "methodinfo",
  111. this.methodInfo,
  112. "parameters",
  113. array
  114. }));
  115. return;
  116. }
  117. }
  118. public void setObjectInArray(ref object obj, List<AMEventParameter> lsArray)
  119. {
  120. if (lsArray.Count <= 0)
  121. {
  122. return;
  123. }
  124. int valueType = lsArray[0].valueType;
  125. if (valueType == 9)
  126. {
  127. string[] array = new string[lsArray.Count];
  128. for (int i = 0; i < lsArray.Count; i++)
  129. {
  130. array[i] = (string)lsArray[i].toObject();
  131. }
  132. obj = array;
  133. return;
  134. }
  135. if (valueType == 10)
  136. {
  137. char[] array2 = new char[lsArray.Count];
  138. for (int j = 0; j < lsArray.Count; j++)
  139. {
  140. array2[j] = (char)lsArray[j].toObject();
  141. }
  142. obj = array2;
  143. return;
  144. }
  145. if (valueType == 0 || valueType == 1)
  146. {
  147. int[] array3 = new int[lsArray.Count];
  148. for (int k = 0; k < lsArray.Count; k++)
  149. {
  150. array3[k] = (int)lsArray[k].toObject();
  151. }
  152. obj = array3;
  153. return;
  154. }
  155. if (valueType == 2 || valueType == 3)
  156. {
  157. float[] array4 = new float[lsArray.Count];
  158. for (int l = 0; l < lsArray.Count; l++)
  159. {
  160. array4[l] = (float)lsArray[l].toObject();
  161. }
  162. obj = array4;
  163. return;
  164. }
  165. if (valueType == 4)
  166. {
  167. Vector2[] array5 = new Vector2[lsArray.Count];
  168. for (int m = 0; m < lsArray.Count; m++)
  169. {
  170. array5[m] = new Vector2(lsArray[m].val_vect2.x, lsArray[m].val_vect2.y);
  171. }
  172. obj = array5;
  173. return;
  174. }
  175. if (valueType == 5)
  176. {
  177. Vector3[] array6 = new Vector3[lsArray.Count];
  178. for (int n = 0; n < lsArray.Count; n++)
  179. {
  180. array6[n] = new Vector3(lsArray[n].val_vect3.x, lsArray[n].val_vect3.y, lsArray[n].val_vect3.z);
  181. }
  182. obj = array6;
  183. return;
  184. }
  185. if (valueType == 6)
  186. {
  187. Vector4[] array7 = new Vector4[lsArray.Count];
  188. for (int num = 0; num < lsArray.Count; num++)
  189. {
  190. array7[num] = new Vector4(lsArray[num].val_vect4.x, lsArray[num].val_vect4.y, lsArray[num].val_vect4.z, lsArray[num].val_vect4.w);
  191. }
  192. obj = array7;
  193. return;
  194. }
  195. if (valueType == 7)
  196. {
  197. Color[] array8 = new Color[lsArray.Count];
  198. for (int num2 = 0; num2 < lsArray.Count; num2++)
  199. {
  200. array8[num2] = new Color(lsArray[num2].val_color.r, lsArray[num2].val_color.g, lsArray[num2].val_color.b, lsArray[num2].val_color.a);
  201. }
  202. obj = array8;
  203. return;
  204. }
  205. if (valueType == 8)
  206. {
  207. Rect[] array9 = new Rect[lsArray.Count];
  208. for (int num3 = 0; num3 < lsArray.Count; num3++)
  209. {
  210. array9[num3] = new Rect(lsArray[num3].val_rect.x, lsArray[num3].val_rect.y, lsArray[num3].val_rect.width, lsArray[num3].val_rect.height);
  211. }
  212. obj = array9;
  213. return;
  214. }
  215. if (valueType == 11)
  216. {
  217. UnityEngine.Object[] array10 = new UnityEngine.Object[lsArray.Count];
  218. for (int num4 = 0; num4 < lsArray.Count; num4++)
  219. {
  220. array10[num4] = (UnityEngine.Object)lsArray[num4].toObject();
  221. }
  222. obj = array10;
  223. return;
  224. }
  225. if (valueType == 12)
  226. {
  227. object[] array11 = new object[lsArray.Count];
  228. for (int num5 = 0; num5 < lsArray.Count; num5++)
  229. {
  230. this.setObjectInArray(ref array11[num5], lsArray[num5].lsArray);
  231. }
  232. obj = array11;
  233. return;
  234. }
  235. obj = null;
  236. }
  237. public string ToString(int codeLanguage, int frameRate, string methodInfoVarName)
  238. {
  239. if (this.component == null)
  240. {
  241. return null;
  242. }
  243. string text = string.Empty;
  244. if (!this.useSendMessage)
  245. {
  246. if (codeLanguage == 0)
  247. {
  248. string text2 = text;
  249. text = string.Concat(new object[]
  250. {
  251. text2,
  252. "AMTween.InvokeMethod(",
  253. methodInfoVarName,
  254. "CMP, AMTween.Hash (\"delay\", ",
  255. base.getWaitTime(frameRate, 0f),
  256. "f, \"methodinfo\", ",
  257. methodInfoVarName
  258. });
  259. if (this.parameters != null && this.parameters.Count > 0)
  260. {
  261. text = text + ", \"parameters\", new object[]{" + this.parametersToString(codeLanguage) + "}";
  262. }
  263. text += "));";
  264. }
  265. else
  266. {
  267. string text2 = text;
  268. text = string.Concat(new object[]
  269. {
  270. text2,
  271. "AMTween.InvokeMethod(",
  272. methodInfoVarName,
  273. "CMP, {\"delay\": ",
  274. base.getWaitTime(frameRate, 0f),
  275. ", \"methodinfo\": ",
  276. methodInfoVarName
  277. });
  278. if (this.parameters != null && this.parameters.Count > 0)
  279. {
  280. text = text + ", \"parameters\": [" + this.parametersToString(codeLanguage) + "]";
  281. }
  282. text += "});";
  283. }
  284. return text;
  285. }
  286. if (this.methodName == null)
  287. {
  288. return null;
  289. }
  290. if (codeLanguage == 0)
  291. {
  292. string text2 = text;
  293. text = string.Concat(new object[]
  294. {
  295. text2,
  296. "AMTween.SendMessage(obj.gameObject, AMTween.Hash (\"delay\", ",
  297. base.getWaitTime(frameRate, 0f),
  298. "f, \"methodname\", \"",
  299. this.methodName,
  300. "\""
  301. });
  302. if (this.parameters != null && this.parameters.Count > 0)
  303. {
  304. text = text + ", \"parameter\", " + this.parametersToString(codeLanguage);
  305. }
  306. text += "));";
  307. }
  308. else
  309. {
  310. string text2 = text;
  311. text = string.Concat(new object[]
  312. {
  313. text2,
  314. "AMTween.SendMessage(obj.gameObject, {\"delay\": ",
  315. base.getWaitTime(frameRate, 0f),
  316. ", \"methodname\": \"",
  317. this.methodName,
  318. "\""
  319. });
  320. if (this.parameters != null && this.parameters.Count > 0)
  321. {
  322. text = text + ", \"parameter\": " + this.parametersToString(codeLanguage);
  323. }
  324. text += "});";
  325. }
  326. return text;
  327. }
  328. private string parametersToString(int codeLanguage)
  329. {
  330. string text = string.Empty;
  331. for (int i = 0; i < this.parameters.Count; i++)
  332. {
  333. text += this.declareObjectToString(this.parameters[i].toObject(), codeLanguage);
  334. if (i < this.parameters.Count - 1)
  335. {
  336. text += ", ";
  337. }
  338. }
  339. return text;
  340. }
  341. private string declareObjectToString(object obj, int codeLanguage)
  342. {
  343. if (obj is string)
  344. {
  345. return "\"" + obj.ToString() + "\"";
  346. }
  347. if (obj is bool)
  348. {
  349. return obj.ToString().ToLower();
  350. }
  351. if (obj is char)
  352. {
  353. return "'" + obj.ToString() + "'";
  354. }
  355. if (codeLanguage == 0 && obj is decimal)
  356. {
  357. return obj.ToString() + "m";
  358. }
  359. if (codeLanguage == 0 && obj is float)
  360. {
  361. return obj.ToString() + "f";
  362. }
  363. if (obj is Vector2)
  364. {
  365. Vector2 vector = (Vector2)obj;
  366. if (codeLanguage == 0)
  367. {
  368. return string.Concat(new object[]
  369. {
  370. "new Vector2(",
  371. vector.x,
  372. "f, ",
  373. vector.y,
  374. "f)"
  375. });
  376. }
  377. return string.Concat(new object[]
  378. {
  379. "Vector2(",
  380. vector.x,
  381. ", ",
  382. vector.y,
  383. ")"
  384. });
  385. }
  386. else if (obj is Vector3)
  387. {
  388. Vector3 vector2 = (Vector3)obj;
  389. if (codeLanguage == 0)
  390. {
  391. return string.Concat(new object[]
  392. {
  393. "new Vector3(",
  394. vector2.x,
  395. "f, ",
  396. vector2.y,
  397. "f, ",
  398. vector2.z,
  399. "f)"
  400. });
  401. }
  402. return string.Concat(new object[]
  403. {
  404. "Vector3(",
  405. vector2.x,
  406. ", ",
  407. vector2.y,
  408. ", ",
  409. vector2.z,
  410. ")"
  411. });
  412. }
  413. else if (obj is Vector4)
  414. {
  415. Vector4 vector3 = (Vector4)obj;
  416. if (codeLanguage == 0)
  417. {
  418. return string.Concat(new object[]
  419. {
  420. "new Vector4(",
  421. vector3.x,
  422. "f, ",
  423. vector3.y,
  424. "f, ",
  425. vector3.z,
  426. "f, ",
  427. vector3.w,
  428. "f)"
  429. });
  430. }
  431. return string.Concat(new object[]
  432. {
  433. "Vector4(",
  434. vector3.x,
  435. ", ",
  436. vector3.y,
  437. ", ",
  438. vector3.z,
  439. ", ",
  440. vector3.w,
  441. ")"
  442. });
  443. }
  444. else if (obj is Color)
  445. {
  446. Color color = (Color)obj;
  447. if (codeLanguage == 0)
  448. {
  449. return string.Concat(new object[]
  450. {
  451. "new Color(",
  452. color.r,
  453. "f, ",
  454. color.g,
  455. "f, ",
  456. color.b,
  457. "f, ",
  458. color.a,
  459. "f)"
  460. });
  461. }
  462. return string.Concat(new object[]
  463. {
  464. "Color(",
  465. color.r,
  466. ", ",
  467. color.g,
  468. ", ",
  469. color.b,
  470. ", ",
  471. color.a,
  472. ")"
  473. });
  474. }
  475. else if (obj is Rect)
  476. {
  477. Rect rect = (Rect)obj;
  478. if (codeLanguage == 0)
  479. {
  480. return string.Concat(new object[]
  481. {
  482. "new Rect(",
  483. rect.x,
  484. "f, ",
  485. rect.y,
  486. "f, ",
  487. rect.width,
  488. "f, ",
  489. rect.height,
  490. "f)"
  491. });
  492. }
  493. return string.Concat(new object[]
  494. {
  495. "Rect(",
  496. rect.x,
  497. ", ",
  498. rect.y,
  499. ", ",
  500. rect.width,
  501. ", ",
  502. rect.height,
  503. ")"
  504. });
  505. }
  506. else
  507. {
  508. if (obj is GameObject)
  509. {
  510. return "GameObject.Find(\"" + (obj as GameObject).name + "\")";
  511. }
  512. if (obj is Component)
  513. {
  514. return string.Concat(new string[]
  515. {
  516. "GameObject.Find(\"",
  517. (obj as Component).gameObject.name,
  518. "\").GetComponent(\"",
  519. (obj as Component).GetType().Name,
  520. "\")"
  521. });
  522. }
  523. if (obj is Array)
  524. {
  525. Type elementType = (obj as Array).GetType().GetElementType();
  526. string text = string.Empty;
  527. if (codeLanguage == 0)
  528. {
  529. text += "new ";
  530. if (elementType == typeof(string))
  531. {
  532. text += "string";
  533. }
  534. else if (elementType == typeof(bool))
  535. {
  536. text += "bool";
  537. }
  538. else if (elementType == typeof(char))
  539. {
  540. text += "char";
  541. }
  542. else if (elementType == typeof(decimal))
  543. {
  544. text += "decimal";
  545. }
  546. else if (elementType == typeof(float))
  547. {
  548. text += "float";
  549. }
  550. else if (elementType == typeof(bool))
  551. {
  552. text += "bool";
  553. }
  554. else if (elementType == typeof(int))
  555. {
  556. text += "int";
  557. }
  558. else if (elementType == typeof(long))
  559. {
  560. text += "long";
  561. }
  562. else if (elementType == typeof(double))
  563. {
  564. text += "double";
  565. }
  566. else if (elementType == typeof(Vector2))
  567. {
  568. text += "Vector2";
  569. }
  570. else if (elementType == typeof(Vector3))
  571. {
  572. text += "Vector3";
  573. }
  574. else if (elementType == typeof(Color))
  575. {
  576. text += "Color";
  577. }
  578. else if (elementType == typeof(Rect))
  579. {
  580. text += "Rect";
  581. }
  582. else if (elementType == typeof(GameObject))
  583. {
  584. text += "GameObject";
  585. }
  586. else if (elementType == typeof(Component))
  587. {
  588. text += (obj as Component).GetType().Name;
  589. }
  590. else
  591. {
  592. text += "Object";
  593. }
  594. text += "[]{";
  595. }
  596. else
  597. {
  598. text += "[";
  599. }
  600. Array array = (Array)obj;
  601. for (int i = 0; i < array.Length; i++)
  602. {
  603. text += this.declareObjectToString(array.GetValue(i), codeLanguage);
  604. if (i < array.Length - 1)
  605. {
  606. text += ", ";
  607. }
  608. }
  609. if (codeLanguage == 0)
  610. {
  611. text += "}";
  612. }
  613. else
  614. {
  615. text += "]";
  616. }
  617. return text;
  618. }
  619. if (obj == null)
  620. {
  621. return null;
  622. }
  623. return obj.ToString();
  624. }
  625. }
  626. public override AnimatorTimeline.JSONAction getJSONAction(int frameRate)
  627. {
  628. if (this.component == null)
  629. {
  630. return null;
  631. }
  632. AnimatorTimeline.JSONAction jsonaction = new AnimatorTimeline.JSONAction();
  633. jsonaction.delay = base.getWaitTime(frameRate, 0f);
  634. jsonaction.go = this.component.gameObject.name;
  635. if (this.useSendMessage)
  636. {
  637. if (this.methodName == null)
  638. {
  639. return null;
  640. }
  641. jsonaction.method = "sendmessage";
  642. jsonaction.strings = new string[]
  643. {
  644. this.methodName
  645. };
  646. if (this.parameters != null && this.parameters.Count > 0)
  647. {
  648. jsonaction.eventParams = new AnimatorTimeline.JSONEventParameter[]
  649. {
  650. this.parameters[0].toJSON()
  651. };
  652. }
  653. }
  654. else
  655. {
  656. if (this.methodInfo == null)
  657. {
  658. return null;
  659. }
  660. jsonaction.method = "invokemethod";
  661. jsonaction.eventParams = new AnimatorTimeline.JSONEventParameter[this.parameters.Count];
  662. for (int i = 0; i < this.parameters.Count; i++)
  663. {
  664. jsonaction.eventParams[i] = this.parameters[i].toJSON();
  665. }
  666. jsonaction.strings = new string[]
  667. {
  668. this.component.GetType().Name,
  669. this.methodInfo.Name
  670. };
  671. }
  672. return jsonaction;
  673. }
  674. public Component component;
  675. public bool useSendMessage;
  676. public List<AMEventParameter> parameters;
  677. public string methodName;
  678. private MethodInfo cachedMethodInfo;
  679. }