Animation.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. using System.Collections.Generic;
  2. namespace DragonBones
  3. {
  4. /**
  5. * @language zh_CN
  6. * 动画控制器,用来播放动画数据,管理动画状态。
  7. * @see DragonBones.AnimationData
  8. * @see DragonBones.AnimationState
  9. * @version DragonBones 3.0
  10. */
  11. public class Animation : BaseObject
  12. {
  13. private static int _sortAnimationState(AnimationState a, AnimationState b)
  14. {
  15. return a.layer > b.layer ? -1 : 1;
  16. }
  17. /**
  18. * @language zh_CN
  19. * 播放速度。 [0: 停止播放, (0~1): 慢速播放, 1: 正常播放, (1~N): 快速播放]
  20. * @default 1
  21. * @version DragonBones 3.0
  22. */
  23. public float timeScale;
  24. private bool _isPlaying;
  25. private bool _animationStateDirty;
  26. /**
  27. * @private
  28. */
  29. internal bool _timelineStateDirty;
  30. /**
  31. * @private
  32. */
  33. internal int _cacheFrameIndex;
  34. private readonly List<string> _animationNames = new List<string>();
  35. private readonly Dictionary<string, AnimationData> _animations = new Dictionary<string, AnimationData>();
  36. private readonly List<AnimationState> _animationStates = new List<AnimationState>();
  37. private Armature _armature;
  38. private AnimationState _lastAnimationState;
  39. private AnimationConfig _animationConfig;
  40. /**
  41. * @private
  42. */
  43. public Animation()
  44. {
  45. }
  46. /**
  47. * @private
  48. */
  49. override protected void _onClear()
  50. {
  51. foreach (var animationState in _animationStates)
  52. {
  53. animationState.ReturnToPool();
  54. }
  55. if (_animationConfig != null)
  56. {
  57. _animationConfig.ReturnToPool();
  58. }
  59. timeScale = 1.0f;
  60. _isPlaying = false;
  61. _animationStateDirty = false;
  62. _timelineStateDirty = false;
  63. _cacheFrameIndex = -1;
  64. _animationNames.Clear();
  65. _animations.Clear();
  66. _animationStates.Clear();
  67. _armature = null;
  68. _lastAnimationState = null;
  69. _animationConfig = null;
  70. }
  71. private void _fadeOut(AnimationConfig animationConfig)
  72. {
  73. int i = 0, l = _animationStates.Count;
  74. AnimationState animationState = null;
  75. switch (animationConfig.fadeOutMode)
  76. {
  77. case AnimationFadeOutMode.SameLayer:
  78. for (; i < l; ++i)
  79. {
  80. animationState = _animationStates[i];
  81. if (animationState.layer == animationConfig.layer)
  82. {
  83. animationState.FadeOut(animationConfig.fadeOutTime, animationConfig.pauseFadeOut);
  84. }
  85. }
  86. break;
  87. case AnimationFadeOutMode.SameGroup:
  88. for (; i < l; ++i)
  89. {
  90. animationState = _animationStates[i];
  91. if (animationState.group == animationConfig.group)
  92. {
  93. animationState.FadeOut(animationConfig.fadeOutTime, animationConfig.pauseFadeOut);
  94. }
  95. }
  96. break;
  97. case AnimationFadeOutMode.SameLayerAndGroup:
  98. for (; i < l; ++i)
  99. {
  100. animationState = _animationStates[i];
  101. if (animationState.layer == animationConfig.layer &&
  102. animationState.group == animationConfig.group
  103. )
  104. {
  105. animationState.FadeOut(animationConfig.fadeOutTime, animationConfig.pauseFadeOut);
  106. }
  107. }
  108. break;
  109. case AnimationFadeOutMode.All:
  110. for (; i < l; ++i)
  111. {
  112. animationState = _animationStates[i];
  113. animationState.FadeOut(animationConfig.fadeOutTime, animationConfig.pauseFadeOut);
  114. }
  115. break;
  116. case AnimationFadeOutMode.None:
  117. default:
  118. break;
  119. }
  120. }
  121. /**
  122. * @private
  123. */
  124. internal void _init(Armature armature)
  125. {
  126. if (_armature != null)
  127. {
  128. return;
  129. }
  130. _armature = armature;
  131. _animationConfig = BaseObject.BorrowObject<AnimationConfig>();
  132. }
  133. /**
  134. * @private
  135. */
  136. internal void _advanceTime(float passedTime)
  137. {
  138. if (!_isPlaying)
  139. {
  140. return;
  141. }
  142. if (passedTime < 0.0f)
  143. {
  144. passedTime = -passedTime;
  145. }
  146. if (_armature.inheritAnimation && _armature._parent != null) // Inherit parent animation timeScale.
  147. {
  148. passedTime *= _armature._parent._armature.animation.timeScale;
  149. }
  150. if (timeScale != 1.0f)
  151. {
  152. passedTime *= timeScale;
  153. }
  154. var animationStateCount = _animationStates.Count;
  155. if (animationStateCount == 1)
  156. {
  157. var animationState = _animationStates[0];
  158. if (animationState._fadeState > 0 && animationState._subFadeState > 0)
  159. {
  160. animationState.ReturnToPool();
  161. _animationStates.Clear();
  162. _animationStateDirty = true;
  163. _lastAnimationState = null;
  164. }
  165. else
  166. {
  167. var animationData = animationState.animationData;
  168. var cacheFrameRate = animationData.cacheFrameRate;
  169. if (_animationStateDirty && cacheFrameRate > 0.0f) // Update cachedFrameIndices.
  170. {
  171. _animationStateDirty = false;
  172. var bones = _armature.GetBones();
  173. for (int i = 0, l = bones.Count; i < l; ++i)
  174. {
  175. var bone = bones[i];
  176. bone._cachedFrameIndices = animationData.GetBoneCachedFrameIndices(bone.name);
  177. }
  178. var slots = _armature.GetSlots();
  179. for (int i = 0, l = slots.Count; i < l; ++i)
  180. {
  181. var slot = slots[i];
  182. slot._cachedFrameIndices = animationData.GetSlotCachedFrameIndices(slot.name);
  183. }
  184. }
  185. if (_timelineStateDirty)
  186. {
  187. animationState._updateTimelineStates();
  188. }
  189. animationState._advanceTime(passedTime, cacheFrameRate);
  190. }
  191. }
  192. else if (animationStateCount > 1)
  193. {
  194. for (int i = 0, r = 0; i < animationStateCount; ++i)
  195. {
  196. var animationState = _animationStates[i];
  197. if (animationState._fadeState > 0 && animationState._fadeProgress <= 0.0f)
  198. {
  199. r++;
  200. animationState.ReturnToPool();
  201. _animationStateDirty = true;
  202. if (_lastAnimationState == animationState) // Update last animation state.
  203. {
  204. _lastAnimationState = null;
  205. }
  206. }
  207. else
  208. {
  209. if (r > 0)
  210. {
  211. _animationStates[i - r] = animationState;
  212. }
  213. if (_timelineStateDirty)
  214. {
  215. animationState._updateTimelineStates();
  216. }
  217. animationState._advanceTime(passedTime, 0.0f);
  218. }
  219. if (i == animationStateCount - 1 && r > 0) // Modify animation states size.
  220. {
  221. DragonBones.ResizeList(_animationStates, animationStateCount - r, null);
  222. if (_lastAnimationState == null && _animationStates.Count > 0)
  223. {
  224. _lastAnimationState = _animationStates[_animationStates.Count - 1];
  225. }
  226. }
  227. }
  228. _cacheFrameIndex = -1;
  229. }
  230. else
  231. {
  232. _cacheFrameIndex = -1;
  233. }
  234. _timelineStateDirty = false;
  235. }
  236. /**
  237. * @language zh_CN
  238. * 清除所有动画状态。
  239. * @see DragonBones.AnimationState
  240. * @version DragonBones 4.5
  241. */
  242. public void Reset()
  243. {
  244. for (int i = 0, l = _animationStates.Count; i < l; ++i)
  245. {
  246. _animationStates[i].ReturnToPool();
  247. }
  248. _isPlaying = false;
  249. _animationStateDirty = false;
  250. _timelineStateDirty = false;
  251. _cacheFrameIndex = -1;
  252. _animationConfig.Clear();
  253. _animationStates.Clear();
  254. _lastAnimationState = null;
  255. }
  256. /**
  257. * @language zh_CN
  258. * 暂停播放动画。
  259. * @param animationName 动画状态的名称,如果未设置,则暂停所有动画状态。
  260. * @see DragonBones.AnimationState
  261. * @version DragonBones 3.0
  262. */
  263. public void Stop(string animationName = null)
  264. {
  265. if (!string.IsNullOrEmpty(animationName))
  266. {
  267. var animationState = GetState(animationName);
  268. if (animationState != null)
  269. {
  270. animationState.Stop();
  271. }
  272. }
  273. else
  274. {
  275. _isPlaying = false;
  276. }
  277. }
  278. /**
  279. * @language zh_CN
  280. * @beta
  281. * 通过动画配置来播放动画。
  282. * @param animationConfig 动画配置。
  283. * @returns 对应的动画状态。
  284. * @see DragonBones.AnimationConfig
  285. * @see DragonBones.AnimationState
  286. * @version DragonBones 5.0
  287. */
  288. public AnimationState PlayConfig(AnimationConfig animationConfig)
  289. {
  290. if (animationConfig == null)
  291. {
  292. DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
  293. return null;
  294. }
  295. var animationName = !string.IsNullOrEmpty(animationConfig.animationName) ? animationConfig.animationName : animationConfig.name;
  296. var animationData = _animations.ContainsKey(animationName) ? _animations[animationName] : null;
  297. if (animationData == null)
  298. {
  299. DragonBones.Assert(false,
  300. "Non-existent animation.\n" +
  301. "DragonBones name: " + _armature.armatureData.parent.name +
  302. " Armature name: " + _armature.name +
  303. " Animation name: " + animationName
  304. );
  305. return null;
  306. }
  307. _isPlaying = true;
  308. if (animationConfig.playTimes < 0)
  309. {
  310. animationConfig.playTimes = (int)animationData.playTimes;
  311. }
  312. if (animationConfig.fadeInTime < 0.0f || float.IsNaN(animationConfig.fadeInTime))
  313. {
  314. if (_lastAnimationState != null)
  315. {
  316. animationConfig.fadeInTime = animationData.fadeInTime;
  317. }
  318. else
  319. {
  320. animationConfig.fadeInTime = 0.0f;
  321. }
  322. }
  323. if (animationConfig.fadeOutTime < 0.0f || float.IsNaN(animationConfig.fadeOutTime))
  324. {
  325. animationConfig.fadeOutTime = animationConfig.fadeInTime;
  326. }
  327. if (animationConfig.timeScale <= -100.0f || float.IsNaN(animationConfig.timeScale)) //
  328. {
  329. animationConfig.timeScale = 1.0f / animationData.scale;
  330. }
  331. if (animationData.duration > 0.0f)
  332. {
  333. if (float.IsNaN(animationConfig.position))
  334. {
  335. animationConfig.position = 0.0f;
  336. }
  337. else if (animationConfig.position < 0.0f)
  338. {
  339. animationConfig.position %= animationData.duration;
  340. animationConfig.position = animationData.duration - animationConfig.position;
  341. }
  342. else if (animationConfig.position == animationData.duration)
  343. {
  344. animationConfig.position -= 0.000001f;
  345. }
  346. else if (animationConfig.position > animationData.duration)
  347. {
  348. animationConfig.position %= animationData.duration;
  349. }
  350. if (animationConfig.duration > 0.0f && animationConfig.position + animationConfig.duration > animationData.duration)
  351. {
  352. animationConfig.duration = animationData.duration - animationConfig.position;
  353. }
  354. if (animationConfig.duration == 0.0f)
  355. {
  356. animationConfig.playTimes = 1;
  357. }
  358. else if (animationConfig.playTimes < 0)
  359. {
  360. animationConfig.playTimes = (int)animationData.playTimes;
  361. }
  362. }
  363. else
  364. {
  365. animationConfig.playTimes = 1;
  366. animationConfig.position = 0.0f;
  367. animationConfig.duration = 0.0f;
  368. }
  369. _fadeOut(animationConfig);
  370. _lastAnimationState = BaseObject.BorrowObject<AnimationState>();
  371. _lastAnimationState._init(_armature, animationData, animationConfig);
  372. _animationStates.Add(_lastAnimationState);
  373. _animationStateDirty = true;
  374. _cacheFrameIndex = -1;
  375. if (_animationStates.Count > 1)
  376. {
  377. _animationStates.Sort(_sortAnimationState);
  378. }
  379. // Child armature play same name animation.
  380. var slots = _armature.GetSlots();
  381. for (int i = 0, l = slots.Count; i < l; ++i)
  382. {
  383. var childArmature = slots[i].childArmature;
  384. if (
  385. childArmature != null && childArmature.inheritAnimation &&
  386. childArmature.animation.HasAnimation(animationName) &&
  387. childArmature.animation.GetState(animationName) == null
  388. )
  389. {
  390. childArmature.animation.FadeIn(animationName); //
  391. }
  392. }
  393. if (animationConfig.fadeInTime <= 0.0f) // Blend animation state, update armature.
  394. {
  395. _armature.AdvanceTime(0.0f);
  396. }
  397. return _lastAnimationState;
  398. }
  399. /**
  400. * @language zh_CN
  401. * 淡入播放动画。
  402. * @param animationName 动画数据名称。
  403. * @param playTimes 播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次]
  404. * @param fadeInTime 淡入时间。 [-1: 使用动画数据默认值, [0~N]: 淡入时间] (以秒为单位)
  405. * @param layer 混合图层,图层高会优先获取混合权重。
  406. * @param group 混合组,用于动画状态编组,方便控制淡出。
  407. * @param fadeOutMode 淡出模式。
  408. * @returns 对应的动画状态。
  409. * @see DragonBones.AnimationFadeOutMode
  410. * @see DragonBones.AnimationState
  411. * @version DragonBones 4.5
  412. */
  413. public AnimationState FadeIn(
  414. string animationName, float fadeInTime = -1.0f, int playTimes = -1,
  415. int layer = 0, string group = null, AnimationFadeOutMode fadeOutMode = AnimationFadeOutMode.SameLayerAndGroup,
  416. bool additiveBlending = false, bool displayControl = true,
  417. bool pauseFadeOut = true, bool pauseFadeIn = true
  418. )
  419. {
  420. _animationConfig.Clear();
  421. _animationConfig.fadeOutMode = fadeOutMode;
  422. _animationConfig.playTimes = playTimes;
  423. _animationConfig.layer = layer;
  424. _animationConfig.fadeInTime = fadeInTime;
  425. _animationConfig.animationName = animationName;
  426. _animationConfig.group = group;
  427. return PlayConfig(_animationConfig);
  428. }
  429. /**
  430. * @language zh_CN
  431. * 播放动画。
  432. * @param animationName 动画数据名称,如果未设置,则播放默认动画,或将暂停状态切换为播放状态,或重新播放上一个正在播放的动画。
  433. * @param playTimes 播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次]
  434. * @returns 对应的动画状态。
  435. * @see DragonBones.AnimationState
  436. * @version DragonBones 3.0
  437. */
  438. public AnimationState Play(string animationName = null, int playTimes = -1)
  439. {
  440. _animationConfig.Clear();
  441. _animationConfig.playTimes = playTimes;
  442. _animationConfig.fadeInTime = 0.0f;
  443. _animationConfig.animationName = animationName;
  444. if (!string.IsNullOrEmpty(animationName))
  445. {
  446. PlayConfig(_animationConfig);
  447. }
  448. else if (_lastAnimationState == null)
  449. {
  450. var defaultAnimation = _armature.armatureData.defaultAnimation;
  451. if (defaultAnimation != null)
  452. {
  453. _animationConfig.animationName = defaultAnimation.name;
  454. PlayConfig(_animationConfig);
  455. }
  456. }
  457. else if (!_isPlaying || (!_lastAnimationState.isPlaying && !_lastAnimationState.isCompleted))
  458. {
  459. _isPlaying = true;
  460. _lastAnimationState.Play();
  461. }
  462. else
  463. {
  464. _animationConfig.animationName = _lastAnimationState.name;
  465. PlayConfig(_animationConfig);
  466. }
  467. return _lastAnimationState;
  468. }
  469. /**
  470. * @language zh_CN
  471. * 从指定时间开始播放动画。
  472. * @param animationName 动画数据的名称。
  473. * @param time 开始时间。 (以秒为单位)
  474. * @param playTimes 播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次]
  475. * @returns 对应的动画状态。
  476. * @see DragonBones.AnimationState
  477. * @version DragonBones 4.5
  478. */
  479. public AnimationState GotoAndPlayByTime(string animationName, float time = 0.0f, int playTimes = -1)
  480. {
  481. _animationConfig.Clear();
  482. _animationConfig.playTimes = playTimes;
  483. _animationConfig.position = time;
  484. _animationConfig.fadeInTime = 0.0f;
  485. _animationConfig.animationName = animationName;
  486. return PlayConfig(_animationConfig);
  487. }
  488. /**
  489. * @language zh_CN
  490. * 从指定帧开始播放动画。
  491. * @param animationName 动画数据的名称。
  492. * @param frame 帧。
  493. * @param playTimes 播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次]
  494. * @returns 对应的动画状态。
  495. * @see DragonBones.AnimationState
  496. * @version DragonBones 4.5
  497. */
  498. public AnimationState GotoAndPlayByFrame(string animationName, uint frame = 0, int playTimes = -1)
  499. {
  500. _animationConfig.Clear();
  501. _animationConfig.playTimes = playTimes;
  502. _animationConfig.fadeInTime = 0.0f;
  503. _animationConfig.animationName = animationName;
  504. if (_animations.ContainsKey(animationName))
  505. {
  506. var animationData = _animations[animationName];
  507. _animationConfig.position = animationData.duration * frame / animationData.frameCount;
  508. }
  509. return PlayConfig(_animationConfig);
  510. }
  511. /**
  512. * @language zh_CN
  513. * 从指定进度开始播放动画。
  514. * @param animationName 动画数据的名称。
  515. * @param progress 进度。 [0~1]
  516. * @param playTimes 播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次]
  517. * @returns 对应的动画状态。
  518. * @see DragonBones.AnimationState
  519. * @version DragonBones 4.5
  520. */
  521. public AnimationState GotoAndPlayByProgress(string animationName, float progress = 0.0f, int playTimes = -1)
  522. {
  523. _animationConfig.Clear();
  524. _animationConfig.playTimes = playTimes;
  525. _animationConfig.fadeInTime = 0.0f;
  526. _animationConfig.animationName = animationName;
  527. if (_animations.ContainsKey(animationName))
  528. {
  529. var animationData = _animations[animationName];
  530. _animationConfig.position = animationData.duration * (progress > 0.0f ? progress : 0.0f);
  531. }
  532. return PlayConfig(_animationConfig);
  533. }
  534. /**
  535. * @language zh_CN
  536. * 将动画停止到指定的时间。
  537. * @param animationName 动画数据的名称。
  538. * @param time 时间。 (以秒为单位)
  539. * @returns 对应的动画状态。
  540. * @see DragonBones.AnimationState
  541. * @version DragonBones 4.5
  542. */
  543. public AnimationState GotoAndStopByTime(string animationName, float time = 0.0f)
  544. {
  545. var animationState = GotoAndPlayByTime(animationName, time, 1);
  546. if (animationState != null)
  547. {
  548. animationState.Stop();
  549. }
  550. return animationState;
  551. }
  552. /**
  553. * @language zh_CN
  554. * 将动画停止到指定的帧。
  555. * @param animationName 动画数据的名称。
  556. * @param frame 帧。
  557. * @returns 对应的动画状态。
  558. * @see DragonBones.AnimationState
  559. * @version DragonBones 4.5
  560. */
  561. public AnimationState GotoAndStopByFrame(string animationName, uint frame = 0)
  562. {
  563. var animationState = GotoAndPlayByFrame(animationName, frame, 1);
  564. if (animationState != null)
  565. {
  566. animationState.Stop();
  567. }
  568. return animationState;
  569. }
  570. /**
  571. * @language zh_CN
  572. * 将动画停止到指定的进度。
  573. * @param animationName 动画数据的名称。
  574. * @param progress 进度。 [0 ~ 1]
  575. * @returns 对应的动画状态。
  576. * @see DragonBones.AnimationState
  577. * @version DragonBones 4.5
  578. */
  579. public AnimationState GotoAndStopByProgress(string animationName, float progress = 0.0f)
  580. {
  581. var animationState = GotoAndPlayByProgress(animationName, progress, 1);
  582. if (animationState != null)
  583. {
  584. animationState.Stop();
  585. }
  586. return animationState;
  587. }
  588. /**
  589. * @language zh_CN
  590. * 获取动画状态。
  591. * @param animationName 动画状态的名称。
  592. * @see DragonBones.AnimationState
  593. * @version DragonBones 3.0
  594. */
  595. public AnimationState GetState(string animationName)
  596. {
  597. for (int i = 0, l = _animationStates.Count; i < l; ++i)
  598. {
  599. var animationState = _animationStates[i];
  600. if (animationState.name == animationName)
  601. {
  602. return animationState;
  603. }
  604. }
  605. return null;
  606. }
  607. /**
  608. * @language zh_CN
  609. * 是否包含动画数据。
  610. * @param animationName 动画数据的名称。
  611. * @see DragonBones.AnimationData
  612. * @version DragonBones 3.0
  613. */
  614. public bool HasAnimation(string animationName)
  615. {
  616. return _animations.ContainsKey(animationName);
  617. }
  618. /**
  619. * @language zh_CN
  620. * 动画是否处于播放状态。
  621. * @version DragonBones 3.0
  622. */
  623. public bool isPlaying
  624. {
  625. get
  626. {
  627. if (_animationStates.Count > 1)
  628. {
  629. return _isPlaying && !isCompleted;
  630. }
  631. else if (_lastAnimationState != null)
  632. {
  633. return _isPlaying && _lastAnimationState.isPlaying;
  634. }
  635. return _isPlaying;
  636. }
  637. }
  638. /**
  639. * @language zh_CN
  640. * 所有动画状态是否均已播放完毕。
  641. * @see DragonBones.AnimationState
  642. * @version DragonBones 3.0
  643. */
  644. public bool isCompleted
  645. {
  646. get
  647. {
  648. if (_lastAnimationState != null)
  649. {
  650. if (!_lastAnimationState.isCompleted)
  651. {
  652. return false;
  653. }
  654. for (int i = 0, l = _animationStates.Count; i < l; ++i)
  655. {
  656. if (!_animationStates[i].isCompleted)
  657. {
  658. return false;
  659. }
  660. }
  661. return true;
  662. }
  663. return false;
  664. }
  665. }
  666. /**
  667. * @language zh_CN
  668. * 上一个正在播放的动画状态的名称。
  669. * @see #lastAnimationState
  670. * @version DragonBones 3.0
  671. */
  672. public string lastAnimationName
  673. {
  674. get { return _lastAnimationState != null ? _lastAnimationState.name : null; }
  675. }
  676. /**
  677. * @language zh_CN
  678. * 上一个正在播放的动画状态。
  679. * @see DragonBones.AnimationState
  680. * @version DragonBones 3.0
  681. */
  682. public AnimationState lastAnimationState
  683. {
  684. get { return _lastAnimationState; }
  685. }
  686. /**
  687. * @language zh_CN
  688. * 一个可以快速使用的动画配置实例。
  689. * @see DragonBones.AnimationConfig
  690. * @version DragonBones 5.0
  691. */
  692. public AnimationConfig animationConfig
  693. {
  694. get
  695. {
  696. _animationConfig.Clear();
  697. return _animationConfig;
  698. }
  699. }
  700. /**
  701. * @language zh_CN
  702. * 所有动画数据名称。
  703. * @see #animations
  704. * @version DragonBones 4.5
  705. */
  706. public List<string> animationNames
  707. {
  708. get { return _animationNames; }
  709. }
  710. /**
  711. * @language zh_CN
  712. * 所有的动画数据。
  713. * @see DragonBones.AnimationData
  714. * @version DragonBones 4.5
  715. */
  716. public Dictionary<string, AnimationData> animations
  717. {
  718. get { return _animations; }
  719. set
  720. {
  721. if (_animations == value)
  722. {
  723. return;
  724. }
  725. _animationNames.Clear();
  726. _animations.Clear();
  727. if (value != null)
  728. {
  729. foreach (var pair in value)
  730. {
  731. _animations[pair.Key] = pair.Value;
  732. _animationNames.Add(pair.Key);
  733. }
  734. }
  735. }
  736. }
  737. }
  738. }