AnimatorData.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. public class AnimatorData : MonoBehaviour
  6. {
  7. [HideInInspector]
  8. public bool isPlaying
  9. {
  10. get
  11. {
  12. return this.nowPlayingTake != null && !this.isPaused;
  13. }
  14. }
  15. [HideInInspector]
  16. public string takeName
  17. {
  18. get
  19. {
  20. if (this.nowPlayingTake != null)
  21. {
  22. return this.nowPlayingTake.name;
  23. }
  24. return null;
  25. }
  26. }
  27. public float GetTakeTime()
  28. {
  29. return this.takeTime;
  30. }
  31. public object Invoker(object[] args)
  32. {
  33. switch ((int)args[0])
  34. {
  35. case 0:
  36. return this.isPlaying;
  37. case 1:
  38. return this.takeName;
  39. case 2:
  40. this.Play((string)args[1], true, 0f, (bool)args[2]);
  41. break;
  42. case 3:
  43. this.StopLoop();
  44. break;
  45. case 4:
  46. this.PauseLoop();
  47. break;
  48. case 5:
  49. this.ResumeLoop();
  50. break;
  51. case 6:
  52. this.Play((string)args[1], false, (float)args[2], (bool)args[3]);
  53. break;
  54. case 7:
  55. this.Play((string)args[1], true, (float)((int)args[2]), (bool)args[3]);
  56. break;
  57. case 8:
  58. this.PreviewValue((string)args[1], true, (float)args[2]);
  59. break;
  60. case 9:
  61. this.PreviewValue((string)args[1], false, (float)args[2]);
  62. break;
  63. case 10:
  64. if (this.takeName == null)
  65. {
  66. return 0f;
  67. }
  68. return this.elapsedTime;
  69. case 11:
  70. if (this.takeName == null)
  71. {
  72. return 0f;
  73. }
  74. return (float)this.nowPlayingTake.numFrames / (float)this.nowPlayingTake.frameRate;
  75. case 12:
  76. if (this.takeName == null)
  77. {
  78. return false;
  79. }
  80. return this.isPaused;
  81. }
  82. return null;
  83. }
  84. private void Start()
  85. {
  86. if (this.playOnStart)
  87. {
  88. this.Play(this.playOnStart.name, true, 0f, false);
  89. this.playOnStart = null;
  90. }
  91. }
  92. private void OnDrawGizmos()
  93. {
  94. if (!this.isAnimatorOpen)
  95. {
  96. return;
  97. }
  98. this.takes[this.currentTake].drawGizmos(this.gizmo_size, this.inPlayMode);
  99. }
  100. private void Update()
  101. {
  102. if (this.bAutoTimeUpdate)
  103. {
  104. NTime.UpdateNowTime(Time.time);
  105. }
  106. if (RhythmAction_Mgr.Instance)
  107. {
  108. this.isPaused = RhythmAction_Mgr.Instance.IsPause;
  109. }
  110. if (this.isPaused || this.nowPlayingTake == null)
  111. {
  112. return;
  113. }
  114. this.elapsedTime = NTime.time;
  115. if (this.elapsedTime >= this.takeTime)
  116. {
  117. this.nowPlayingTake.stopAudio();
  118. if (this.isLooping)
  119. {
  120. this.Execute(this.nowPlayingTake, true, 0f);
  121. }
  122. else
  123. {
  124. this.nowPlayingTake = null;
  125. }
  126. }
  127. }
  128. public void Play(string take_name, bool isFrame, float value, bool loop)
  129. {
  130. this.nowPlayingTake = this.getTake(take_name);
  131. if (this.nowPlayingTake)
  132. {
  133. this.isLooping = loop;
  134. this.Execute(this.nowPlayingTake, isFrame, value);
  135. }
  136. }
  137. public void Play(string take_name, bool isFrame, float value, bool loop, List<int> exclusion_track_id_list)
  138. {
  139. this.nowPlayingTake = this.getTake(take_name);
  140. if (this.nowPlayingTake)
  141. {
  142. this.isLooping = loop;
  143. if (exclusion_track_id_list == null || exclusion_track_id_list.Count == 0)
  144. {
  145. this.Execute(this.nowPlayingTake, isFrame, value);
  146. }
  147. else
  148. {
  149. this.ExecuteExclusionTrack(this.nowPlayingTake, exclusion_track_id_list, isFrame, value);
  150. }
  151. }
  152. }
  153. public void PreviewValue(string take_name, bool isFrame, float value)
  154. {
  155. AMTake take;
  156. if (this.nowPlayingTake && this.nowPlayingTake.name == this.takeName)
  157. {
  158. take = this.nowPlayingTake;
  159. }
  160. else
  161. {
  162. take = this.getTake(take_name);
  163. }
  164. if (!take)
  165. {
  166. return;
  167. }
  168. float num = value;
  169. if (!isFrame)
  170. {
  171. num *= (float)take.frameRate;
  172. }
  173. take.previewFrameInvoker(num);
  174. }
  175. public void Execute(AMTake take, bool isFrame = true, float value = 0f)
  176. {
  177. AMTween.Stop();
  178. float num = value;
  179. float num2 = value;
  180. if (!isFrame)
  181. {
  182. num *= (float)take.frameRate;
  183. }
  184. if (isFrame)
  185. {
  186. num2 /= (float)take.frameRate;
  187. }
  188. take.executeActions(num);
  189. this.elapsedTime = num2;
  190. this.takeTime = (float)take.numFrames / (float)take.frameRate;
  191. this.nowPlayingTake = take;
  192. }
  193. public void ExecuteExclusionTrack(AMTake take, List<int> exclusion_track_id_list, bool isFrame = true, float value = 0f)
  194. {
  195. AMTween.Stop();
  196. float num = value;
  197. float num2 = value;
  198. if (!isFrame)
  199. {
  200. num *= (float)take.frameRate;
  201. }
  202. if (isFrame)
  203. {
  204. num2 /= (float)take.frameRate;
  205. }
  206. take.executeActions(exclusion_track_id_list, num);
  207. this.elapsedTime = num2;
  208. this.takeTime = (float)take.numFrames / (float)take.frameRate;
  209. this.nowPlayingTake = take;
  210. }
  211. public void PauseLoop()
  212. {
  213. if (this.nowPlayingTake == null)
  214. {
  215. return;
  216. }
  217. this.isPaused = true;
  218. this.nowPlayingTake.stopAudio();
  219. AMTween.Pause();
  220. }
  221. public void ResumeLoop()
  222. {
  223. if (this.nowPlayingTake == null)
  224. {
  225. return;
  226. }
  227. AMTween.Resume();
  228. this.isPaused = false;
  229. }
  230. public void StopLoop()
  231. {
  232. if (this.nowPlayingTake != null)
  233. {
  234. this.nowPlayingTake.stopAudio();
  235. this.nowPlayingTake.stopAnimations();
  236. this.nowPlayingTake = null;
  237. }
  238. this.isLooping = false;
  239. this.isPaused = false;
  240. AMTween.Stop();
  241. }
  242. public int getCurrentTakeValue()
  243. {
  244. return this.currentTake;
  245. }
  246. public int getTakeCount()
  247. {
  248. return this.takes.Count;
  249. }
  250. public bool setCurrentTakeValue(int _take)
  251. {
  252. if (_take != this.currentTake)
  253. {
  254. this.getCurrentTake().previewFrame(1f, false, true, false, false);
  255. this.currentTake = _take;
  256. return true;
  257. }
  258. return false;
  259. }
  260. public AMTake getCurrentTake()
  261. {
  262. return this.takes[this.currentTake];
  263. }
  264. public AMTake getTake(string takeName)
  265. {
  266. foreach (AMTake amtake in this.takes)
  267. {
  268. if (amtake.name == takeName)
  269. {
  270. return amtake;
  271. }
  272. }
  273. Debug.LogError("Animator: Take '" + takeName + "' not found.");
  274. return new AMTake(null);
  275. }
  276. public void addTake()
  277. {
  278. string name = "Take" + (this.takes.Count + 1);
  279. AMTake amtake = ScriptableObject.CreateInstance<AMTake>();
  280. amtake.name = name;
  281. this.makeTakeNameUnique(amtake);
  282. amtake.frameRate = 24;
  283. amtake.numFrames = 1440;
  284. amtake.startFrame = 1f;
  285. amtake.selectedFrame = 1;
  286. amtake.selectedTrack = -1;
  287. amtake.playbackSpeedIndex = 2;
  288. amtake.trackKeys = new List<int>();
  289. amtake.trackValues = new List<AMTrack>();
  290. this.takes.Add(amtake);
  291. this.selectTake(this.takes.Count - 1);
  292. }
  293. public void deleteTake(int index)
  294. {
  295. if (this.playOnStart == this.takes[index])
  296. {
  297. this.playOnStart = null;
  298. }
  299. this.takes[index].destroy();
  300. this.takes.RemoveAt(index);
  301. if (this.currentTake >= index && this.currentTake > 0)
  302. {
  303. this.currentTake--;
  304. }
  305. }
  306. public void deleteCurrentTake()
  307. {
  308. this.deleteTake(this.currentTake);
  309. }
  310. public void selectTake(int index)
  311. {
  312. this.currentTake = index;
  313. }
  314. public void selectTake(string name)
  315. {
  316. for (int i = 0; i < this.takes.Count; i++)
  317. {
  318. if (this.takes[i].name == name)
  319. {
  320. this.selectTake(i);
  321. break;
  322. }
  323. }
  324. }
  325. public void makeTakeNameUnique(AMTake take)
  326. {
  327. bool flag = false;
  328. int num = 0;
  329. do
  330. {
  331. if (flag)
  332. {
  333. flag = false;
  334. }
  335. foreach (AMTake amtake in this.takes)
  336. {
  337. if (amtake != take && amtake.name == take.name)
  338. {
  339. if (num > 0)
  340. {
  341. take.name = take.name.Substring(0, take.name.Length - 3);
  342. }
  343. num++;
  344. string name = take.name;
  345. take.name = string.Concat(new object[]
  346. {
  347. name,
  348. "(",
  349. num,
  350. ")"
  351. });
  352. flag = true;
  353. break;
  354. }
  355. }
  356. }
  357. while (flag);
  358. }
  359. public string[] getTakeNames()
  360. {
  361. string[] array = new string[this.takes.Count + 1];
  362. for (int i = 0; i < this.takes.Count; i++)
  363. {
  364. array[i] = this.takes[i].name;
  365. }
  366. array[array.Length - 1] = "Create new...";
  367. return array;
  368. }
  369. public int getTakeIndex(AMTake take)
  370. {
  371. for (int i = 0; i < this.takes.Count; i++)
  372. {
  373. if (this.takes[i] == take)
  374. {
  375. return i;
  376. }
  377. }
  378. return -1;
  379. }
  380. public bool setCodeLanguage(int codeLanguage)
  381. {
  382. if (this.codeLanguage != codeLanguage)
  383. {
  384. this.codeLanguage = codeLanguage;
  385. return true;
  386. }
  387. return false;
  388. }
  389. public bool setGizmoSize(float gizmo_size)
  390. {
  391. if (this.gizmo_size != gizmo_size)
  392. {
  393. this.gizmo_size = gizmo_size;
  394. foreach (UnityEngine.Object @object in UnityEngine.Object.FindObjectsOfType(typeof(AMTarget)))
  395. {
  396. if ((@object as AMTarget).gizmo_size != gizmo_size)
  397. {
  398. (@object as AMTarget).gizmo_size = gizmo_size;
  399. }
  400. }
  401. return true;
  402. }
  403. return false;
  404. }
  405. public void deleteAllTakesExcept(AMTake take)
  406. {
  407. for (int i = 0; i < this.takes.Count; i++)
  408. {
  409. if (!(this.takes[i] == take))
  410. {
  411. this.deleteTake(i);
  412. i--;
  413. }
  414. }
  415. }
  416. public void mergeWith(AnimatorData _aData)
  417. {
  418. foreach (AMTake amtake in _aData.takes)
  419. {
  420. this.takes.Add(amtake);
  421. this.makeTakeNameUnique(amtake);
  422. }
  423. }
  424. public List<GameObject> getDependencies(AMTake _take = null)
  425. {
  426. if (_take != null)
  427. {
  428. return _take.getDependencies().ToList<GameObject>();
  429. }
  430. List<GameObject> list = new List<GameObject>();
  431. foreach (AMTake amtake in this.takes)
  432. {
  433. list = list.Union(amtake.getDependencies()).ToList<GameObject>();
  434. }
  435. return list;
  436. }
  437. public List<GameObject> updateDependencies(List<GameObject> newReferences, List<GameObject> oldReferences)
  438. {
  439. List<GameObject> list = new List<GameObject>();
  440. foreach (AMTake amtake in this.takes)
  441. {
  442. list = list.Union(amtake.updateDependencies(newReferences, oldReferences)).ToList<GameObject>();
  443. }
  444. return list;
  445. }
  446. public List<AMTake> takes = new List<AMTake>();
  447. public AMTake playOnStart;
  448. [HideInInspector]
  449. public bool isAnimatorOpen;
  450. [HideInInspector]
  451. public bool isInspectorOpen;
  452. [HideInInspector]
  453. public bool inPlayMode;
  454. [HideInInspector]
  455. public float zoom = 0.4f;
  456. [HideInInspector]
  457. public int currentTake;
  458. [HideInInspector]
  459. public int codeLanguage;
  460. [HideInInspector]
  461. public float gizmo_size = 0.05f;
  462. [HideInInspector]
  463. public float width_track = 150f;
  464. [HideInInspector]
  465. public bool autoKey;
  466. [HideInInspector]
  467. public float elapsedTime;
  468. public bool bAutoTimeUpdate = true;
  469. private AMTake nowPlayingTake;
  470. private bool isPaused;
  471. private bool isLooping;
  472. private float takeTime;
  473. }