AnimationState.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. using System;
  2. using System.Collections.Generic;
  3. namespace DragonBones
  4. {
  5. /**
  6. * 动画状态,播放动画时产生,可以对每个播放的动画进行更细致的控制和调节。
  7. * @see DragonBones.Animation
  8. * @see DragonBones.AnimationData
  9. * @version DragonBones 3.0
  10. */
  11. public class AnimationState : BaseObject
  12. {
  13. /**
  14. * @language zh_CN
  15. * 是否对插槽的显示对象有控制权。
  16. * @see DragonBones.Slot#displayController
  17. * @version DragonBones 3.0
  18. */
  19. public bool displayControl;
  20. /**
  21. * @language zh_CN
  22. * 是否以增加的方式混合。
  23. * @version DragonBones 3.0
  24. */
  25. public bool additiveBlending;
  26. /**
  27. * @language zh_CN
  28. * 是否能触发行为。
  29. * @version DragonBones 5.0
  30. */
  31. public bool actionEnabled;
  32. /**
  33. * @language zh_CN
  34. * 播放次数。 [0: 无限循环播放, [1~N]: 循环播放 N 次]
  35. * @version DragonBones 3.0
  36. */
  37. public uint playTimes;
  38. /**
  39. * @language zh_CN
  40. * 播放速度。 [(-N~0): 倒转播放, 0: 停止播放, (0~1): 慢速播放, 1: 正常播放, (1~N): 快速播放]
  41. * @version DragonBones 3.0
  42. */
  43. public float timeScale;
  44. /**
  45. * @language zh_CN
  46. * 混合权重。
  47. * @version DragonBones 3.0
  48. */
  49. public float weight;
  50. /**
  51. * @language zh_CN
  52. * 自动淡出时间。 [-1: 不自动淡出, [0~N]: 淡出时间] (以秒为单位)
  53. * 当设置一个大于等于 0 的值,动画状态将会在播放完成后自动淡出。
  54. * @version DragonBones 3.0
  55. */
  56. public float autoFadeOutTime;
  57. /**
  58. * @private
  59. */
  60. public float fadeTotalTime;
  61. /**
  62. * @private
  63. */
  64. internal int _playheadState;
  65. /**
  66. * @private
  67. */
  68. internal int _fadeState;
  69. /**
  70. * @private
  71. */
  72. internal int _subFadeState;
  73. /**
  74. * @private
  75. */
  76. internal int _layer;
  77. /**
  78. * @private
  79. */
  80. internal float _position;
  81. /**
  82. * @private
  83. */
  84. internal float _duration;
  85. /**
  86. * @private
  87. */
  88. private float _fadeTime;
  89. /**
  90. * @private
  91. */
  92. private float _time;
  93. /**
  94. * @private
  95. */
  96. internal float _fadeProgress;
  97. /**
  98. * @private
  99. */
  100. internal float _weightResult;
  101. /**
  102. * @private
  103. */
  104. private string _name;
  105. /**
  106. * @private
  107. */
  108. private string _group;
  109. /**
  110. * @private
  111. */
  112. private readonly List<string> _boneMask = new List<string>();
  113. /**
  114. * @private
  115. */
  116. private readonly List<BoneTimelineState> _boneTimelines = new List<BoneTimelineState>();
  117. /**
  118. * @private
  119. */
  120. private readonly List<SlotTimelineState> _slotTimelines = new List<SlotTimelineState>();
  121. /**
  122. * @private
  123. */
  124. private readonly List<FFDTimelineState> _ffdTimelines = new List<FFDTimelineState>();
  125. /**
  126. * @private
  127. */
  128. private AnimationData _animationData;
  129. /**
  130. * @private
  131. */
  132. private Armature _armature;
  133. /**
  134. * @private
  135. */
  136. internal AnimationTimelineState _timeline;
  137. /**
  138. * @private
  139. */
  140. private ZOrderTimelineState _zOrderTimeline;
  141. /**
  142. * @private
  143. */
  144. public AnimationState()
  145. {
  146. }
  147. /**
  148. * @private
  149. */
  150. override protected void _onClear()
  151. {
  152. for (int i = 0, l = _boneTimelines.Count; i < l; ++i)
  153. {
  154. _boneTimelines[i].ReturnToPool();
  155. }
  156. for (int i = 0, l = _slotTimelines.Count; i < l; ++i)
  157. {
  158. _slotTimelines[i].ReturnToPool();
  159. }
  160. for (int i = 0, l = _ffdTimelines.Count; i < l; ++i)
  161. {
  162. _ffdTimelines[i].ReturnToPool();
  163. }
  164. if (_timeline != null)
  165. {
  166. _timeline.ReturnToPool();
  167. }
  168. if (_zOrderTimeline != null)
  169. {
  170. _zOrderTimeline.ReturnToPool();
  171. }
  172. displayControl = true;
  173. additiveBlending = false;
  174. actionEnabled = false;
  175. playTimes = 1;
  176. timeScale = 1.0f;
  177. weight = 1.0f;
  178. autoFadeOutTime = -1.0f;
  179. fadeTotalTime = 0.0f;
  180. _playheadState = 0;
  181. _fadeState = -1;
  182. _subFadeState = -1;
  183. _layer = 0;
  184. _position = 0.0f;
  185. _duration = 0.0f;
  186. _fadeTime = 0.0f;
  187. _time = 0.0f;
  188. _fadeProgress = 0.0f;
  189. _weightResult = 0.0f;
  190. _name = null;
  191. _group = null;
  192. _boneMask.Clear();
  193. _boneTimelines.Clear();
  194. _slotTimelines.Clear();
  195. _ffdTimelines.Clear();
  196. _animationData = null;
  197. _armature = null;
  198. _timeline = null;
  199. _zOrderTimeline = null;
  200. }
  201. private void _advanceFadeTime(float passedTime)
  202. {
  203. var isFadeOut = _fadeState > 0;
  204. if (_subFadeState < 0) // Fade start event.
  205. {
  206. _subFadeState = 0;
  207. var eventType = isFadeOut? EventObject.FADE_OUT: EventObject.FADE_IN;
  208. if (_armature.eventDispatcher.HasEventListener(eventType))
  209. {
  210. var eventObject = BaseObject.BorrowObject<EventObject>();
  211. eventObject.animationState = this;
  212. _armature._bufferEvent(eventObject, eventType);
  213. }
  214. }
  215. if (passedTime < 0.0f)
  216. {
  217. passedTime = -passedTime;
  218. }
  219. _fadeTime += passedTime;
  220. if (_fadeTime >= fadeTotalTime) // Fade complete.
  221. {
  222. _subFadeState = 1;
  223. _fadeProgress = isFadeOut ? 0.0f : 1.0f;
  224. }
  225. else if (_fadeTime > 0.0f) // Fading.
  226. {
  227. _fadeProgress = isFadeOut ? (1.0f - _fadeTime / fadeTotalTime) : (_fadeTime / fadeTotalTime);
  228. }
  229. else // Before fade.
  230. {
  231. _fadeProgress = isFadeOut ? 1.0f : 0.0f;
  232. }
  233. if (_subFadeState > 0) // Fade complete event.
  234. {
  235. if (!isFadeOut)
  236. {
  237. _playheadState |= 1; // x1
  238. _fadeState = 0;
  239. }
  240. var eventType = isFadeOut ? EventObject.FADE_OUT_COMPLETE : EventObject.FADE_IN_COMPLETE;
  241. if (_armature.eventDispatcher.HasEventListener(eventType))
  242. {
  243. var eventObject = BaseObject.BorrowObject<EventObject>();
  244. eventObject.animationState = this;
  245. _armature._bufferEvent(eventObject, eventType);
  246. }
  247. }
  248. }
  249. /**
  250. * @private
  251. */
  252. internal void _init(Armature armature, AnimationData animationData, AnimationConfig animationConfig)
  253. {
  254. _armature = armature;
  255. _animationData = animationData;
  256. _name = !string.IsNullOrEmpty(animationConfig.name) ? animationConfig.name : animationConfig.animationName;
  257. actionEnabled = animationConfig.actionEnabled;
  258. additiveBlending = animationConfig.additiveBlending;
  259. displayControl = animationConfig.displayControl;
  260. playTimes = (uint)animationConfig.playTimes;
  261. timeScale = animationConfig.timeScale;
  262. fadeTotalTime = animationConfig.fadeInTime;
  263. autoFadeOutTime = animationConfig.autoFadeOutTime;
  264. weight = animationConfig.weight;
  265. if (animationConfig.pauseFadeIn)
  266. {
  267. _playheadState = 2; // 10
  268. }
  269. else
  270. {
  271. _playheadState = 3; // 11
  272. }
  273. _fadeState = -1;
  274. _subFadeState = -1;
  275. _layer = animationConfig.layer;
  276. _time = animationConfig.position;
  277. _group = animationConfig.group;
  278. if (animationConfig.duration < 0.0f)
  279. {
  280. _position = 0.0f;
  281. _duration = _animationData.duration;
  282. if (animationConfig.position != 0.0f)
  283. {
  284. if (timeScale >= 0.0f)
  285. {
  286. _time = animationConfig.position;
  287. }
  288. else
  289. {
  290. _time = animationConfig.position - _duration;
  291. }
  292. }
  293. else
  294. {
  295. _time = 0.0f;
  296. }
  297. }
  298. else
  299. {
  300. _position = animationConfig.position;
  301. _duration = animationConfig.duration;
  302. _time = 0.0f;
  303. }
  304. if (timeScale < 0.0f && _time == 0.0f)
  305. {
  306. _time = -0.000001f; // Can not cross last frame event.
  307. }
  308. if (fadeTotalTime <= 0.0f)
  309. {
  310. _fadeProgress = 0.999999f;
  311. }
  312. if (animationConfig.boneMask.Count > 0)
  313. {
  314. DragonBones.ResizeList(_boneMask, animationConfig.boneMask.Count, null);
  315. for (int i = 0, l = _boneMask.Count; i < l; ++i)
  316. {
  317. _boneMask[i] = animationConfig.boneMask[i];
  318. }
  319. }
  320. _timeline = BaseObject.BorrowObject<AnimationTimelineState>();
  321. _timeline._init(_armature, this, _animationData);
  322. if (_animationData.zOrderTimeline != null)
  323. {
  324. _zOrderTimeline = BaseObject.BorrowObject<ZOrderTimelineState>();
  325. _zOrderTimeline._init(_armature, this, _animationData.zOrderTimeline);
  326. }
  327. _updateTimelineStates();
  328. }
  329. /**
  330. * @private
  331. */
  332. internal void _updateTimelineStates()
  333. {
  334. var boneTimelineStates = new Dictionary<string, BoneTimelineState>();
  335. var slotTimelineStates = new Dictionary<string, SlotTimelineState>();
  336. var ffdTimelineStates = new Dictionary<string, FFDTimelineState>();
  337. for (int i = 0, l = _boneTimelines.Count; i < l; ++i) // Creat bone timelines map.
  338. {
  339. var boneTimelineState = _boneTimelines[i];
  340. boneTimelineStates[boneTimelineState.bone.name] = boneTimelineState;
  341. }
  342. var bones = _armature.GetBones();
  343. for (int i = 0, l = bones.Count; i < l; ++i)
  344. {
  345. var bone = bones[i];
  346. var boneTimelineName = bone.name;
  347. if (ContainsBoneMask(boneTimelineName))
  348. {
  349. var boneTimelineData = _animationData.GetBoneTimeline(boneTimelineName);
  350. if (boneTimelineData != null)
  351. {
  352. if (boneTimelineStates.ContainsKey(boneTimelineName)) // Remove bone timeline from map.
  353. {
  354. boneTimelineStates.Remove(boneTimelineName);
  355. }
  356. else // Create new bone timeline.
  357. {
  358. var boneTimelineState = BaseObject.BorrowObject<BoneTimelineState>();
  359. boneTimelineState.bone = bone;
  360. boneTimelineState._init(_armature, this, boneTimelineData);
  361. _boneTimelines.Add(boneTimelineState);
  362. }
  363. }
  364. }
  365. }
  366. foreach (var boneTimelineState in boneTimelineStates.Values) // Remove bone timelines.
  367. {
  368. boneTimelineState.bone.InvalidUpdate(); //
  369. _boneTimelines.Remove(boneTimelineState);
  370. boneTimelineState.ReturnToPool();
  371. }
  372. for (int i = 0, l = _slotTimelines.Count; i < l; ++i) // Creat slot timelines map.
  373. {
  374. var slotTimelineState = _slotTimelines[i];
  375. slotTimelineStates[slotTimelineState.slot.name] = slotTimelineState;
  376. }
  377. for (int i = 0, l = _ffdTimelines.Count; i < l; ++i) // Creat ffd timelines map.
  378. {
  379. var ffdTimelineState = _ffdTimelines[i];
  380. var display = ffdTimelineState._timelineData.display;
  381. var meshName = display.inheritAnimation ? display.mesh.name : display.name;
  382. ffdTimelineStates[meshName] = ffdTimelineState;
  383. }
  384. var slots = _armature.GetSlots();
  385. for (int i = 0, l = slots.Count; i < l; ++i)
  386. {
  387. var slot = slots[i];
  388. var slotTimelineName = slot.name;
  389. var parentTimelineName = slot.parent.name;
  390. var resetFFDVertices = false;
  391. if (ContainsBoneMask(parentTimelineName))
  392. {
  393. var slotTimelineData = _animationData.GetSlotTimeline(slotTimelineName);
  394. if (slotTimelineData != null)
  395. {
  396. if (slotTimelineStates.ContainsKey(slotTimelineName)) // Remove slot timeline from map.
  397. {
  398. slotTimelineStates.Remove(slotTimelineName);
  399. }
  400. else // Create new slot timeline.
  401. {
  402. var slotTimelineState = BaseObject.BorrowObject<SlotTimelineState>();
  403. slotTimelineState.slot = slot;
  404. slotTimelineState._init(_armature, this, slotTimelineData);
  405. _slotTimelines.Add(slotTimelineState);
  406. }
  407. }
  408. var ffdTimelineDatas = _animationData.GetFFDTimeline(_armature._skinData.name, slotTimelineName);
  409. if (ffdTimelineDatas != null)
  410. {
  411. foreach (var pair in ffdTimelineDatas)
  412. {
  413. if (ffdTimelineStates.ContainsKey(pair.Key)) // Remove ffd timeline from map.
  414. {
  415. ffdTimelineStates.Remove(pair.Key);
  416. }
  417. else // Create new ffd timeline.
  418. {
  419. var ffdTimelineState = BaseObject.BorrowObject<FFDTimelineState>();
  420. ffdTimelineState.slot = slot;
  421. ffdTimelineState._init(_armature, this, pair.Value);
  422. _ffdTimelines.Add(ffdTimelineState);
  423. }
  424. }
  425. }
  426. else
  427. {
  428. resetFFDVertices = true;
  429. }
  430. }
  431. else
  432. {
  433. resetFFDVertices = true;
  434. }
  435. if (resetFFDVertices)
  436. {
  437. for (int iA = 0, lA = slot._ffdVertices.Count; iA < lA; ++iA)
  438. {
  439. slot._ffdVertices[iA] = 0.0f;
  440. }
  441. slot._meshDirty = true;
  442. }
  443. }
  444. foreach (var slotTimelineState in slotTimelineStates.Values) // Remove slot timelines.
  445. {
  446. _slotTimelines.Remove(slotTimelineState);
  447. slotTimelineState.ReturnToPool();
  448. }
  449. foreach (var ffdTimelineState in ffdTimelineStates.Values)// Remove ffd timelines.
  450. {
  451. _ffdTimelines.Remove(ffdTimelineState);
  452. ffdTimelineState.ReturnToPool();
  453. }
  454. }
  455. /**
  456. * @private
  457. */
  458. internal void _advanceTime(float passedTime, float cacheFrameRate)
  459. {
  460. // Update fade time.
  461. if (_fadeState != 0 || _subFadeState != 0)
  462. {
  463. _advanceFadeTime(passedTime);
  464. }
  465. // Update time.
  466. if (timeScale != 1.0f)
  467. {
  468. passedTime *= timeScale;
  469. }
  470. if (passedTime != 0.0f && _playheadState == 3) // 11
  471. {
  472. _time += passedTime;
  473. }
  474. // weight.
  475. _weightResult = weight * _fadeProgress;
  476. if (_weightResult != 0.0f)
  477. {
  478. var isCacheEnabled = _fadeState == 0 && cacheFrameRate > 0.0f;
  479. var isUpdatesTimeline = true;
  480. var isUpdatesBoneTimeline = true;
  481. var time = _time;
  482. // Update main timeline.
  483. _timeline.Update(time);
  484. // Cache time internval.
  485. if (isCacheEnabled)
  486. {
  487. _timeline._currentTime = (float)Math.Floor(_timeline._currentTime * cacheFrameRate) / cacheFrameRate;
  488. }
  489. // Update zOrder timeline.
  490. if (_zOrderTimeline != null)
  491. {
  492. _zOrderTimeline.Update(time);
  493. }
  494. // Update cache.
  495. if (isCacheEnabled)
  496. {
  497. var cacheFrameIndex = (int)Math.Floor(_timeline._currentTime * cacheFrameRate); // uint
  498. if (_armature.animation._cacheFrameIndex == cacheFrameIndex) // Same cache.
  499. {
  500. isUpdatesTimeline = false;
  501. isUpdatesBoneTimeline = false;
  502. }
  503. else
  504. {
  505. _armature.animation._cacheFrameIndex = cacheFrameIndex;
  506. if (_animationData.cachedFrames[cacheFrameIndex]) // Cached.
  507. {
  508. isUpdatesBoneTimeline = false;
  509. }
  510. else // Cache.
  511. {
  512. _animationData.cachedFrames[cacheFrameIndex] = true;
  513. }
  514. }
  515. }
  516. // Update timelines.
  517. if (isUpdatesTimeline)
  518. {
  519. if (isUpdatesBoneTimeline)
  520. {
  521. for (int i = 0, l = _boneTimelines.Count; i < l; ++i)
  522. {
  523. _boneTimelines[i].Update(time);
  524. }
  525. }
  526. for (int i = 0, l = _slotTimelines.Count; i < l; ++i)
  527. {
  528. _slotTimelines[i].Update(time);
  529. }
  530. for (int i = 0, l = _ffdTimelines.Count; i < l; ++i)
  531. {
  532. _ffdTimelines[i].Update(time);
  533. }
  534. }
  535. }
  536. if (_fadeState == 0)
  537. {
  538. if (_subFadeState > 0)
  539. {
  540. _subFadeState = 0;
  541. }
  542. // Auto fade out.
  543. if (autoFadeOutTime >= 0.0f)
  544. {
  545. if (_timeline._playState > 0)
  546. {
  547. FadeOut(autoFadeOutTime);
  548. }
  549. }
  550. }
  551. }
  552. /**
  553. * @private
  554. */
  555. internal bool _isDisabled(Slot slot)
  556. {
  557. if (
  558. displayControl &&
  559. (
  560. string.IsNullOrEmpty(slot.displayController) ||
  561. slot.displayController == _name ||
  562. slot.displayController == _group
  563. )
  564. )
  565. {
  566. return false;
  567. }
  568. return true;
  569. }
  570. /**
  571. * @language zh_CN
  572. * 继续播放。
  573. * @version DragonBones 3.0
  574. */
  575. public void Play()
  576. {
  577. _playheadState = 3; // 11
  578. }
  579. /**
  580. * @language zh_CN
  581. * 暂停播放。
  582. * @version DragonBones 3.0
  583. */
  584. public void Stop()
  585. {
  586. _playheadState &= 1; // 0x
  587. }
  588. /**
  589. * @language zh_CN
  590. * 淡出动画。
  591. * @param fadeOutTime 淡出时间。 (以秒为单位)
  592. * @param pausePlayhead 淡出时是否暂停动画。
  593. * @version DragonBones 3.0
  594. */
  595. public void FadeOut(float fadeOutTime, bool pausePlayhead = true)
  596. {
  597. if (fadeOutTime < 0.0f || float.IsNaN(fadeOutTime))
  598. {
  599. fadeOutTime = 0.0f;
  600. }
  601. if (pausePlayhead)
  602. {
  603. _playheadState &= 2; // x0
  604. }
  605. if (_fadeState > 0)
  606. {
  607. if (fadeOutTime > fadeOutTime - _fadeTime)
  608. {
  609. // If the animation is already in fade out, the new fade out will be ignored.
  610. return;
  611. }
  612. }
  613. else
  614. {
  615. _fadeState = 1;
  616. _subFadeState = -1;
  617. if (fadeOutTime <= 0.0f || _fadeProgress <= 0.0f)
  618. {
  619. _fadeProgress = 0.000001f; // Modify _fadeProgress to different value.
  620. }
  621. foreach (var boneTimelineState in _boneTimelines)
  622. {
  623. boneTimelineState.FadeOut();
  624. }
  625. for (int i = 0, l = _slotTimelines.Count; i < l; ++i)
  626. {
  627. _slotTimelines[i].FadeOut();
  628. }
  629. for (int i = 0, l = _ffdTimelines.Count; i < l; ++i)
  630. {
  631. _ffdTimelines[i].FadeOut();
  632. }
  633. }
  634. displayControl = false; //
  635. fadeTotalTime = _fadeProgress > 0.000001f ? fadeOutTime / _fadeProgress : 0.0f;
  636. _fadeTime = fadeTotalTime * (1.0f - _fadeProgress);
  637. }
  638. /**
  639. * @language zh_CN
  640. * 是否包含骨骼遮罩。
  641. * @param name 指定的骨骼名称。
  642. * @version DragonBones 3.0
  643. */
  644. public bool ContainsBoneMask(string name)
  645. {
  646. return _boneMask.Count == 0 || _boneMask.Contains(name);
  647. }
  648. /**
  649. * @language zh_CN
  650. * 添加骨骼遮罩。
  651. * @param boneName 指定的骨骼名称。
  652. * @param recursive 是否为该骨骼的子骨骼添加遮罩。
  653. * @version DragonBones 3.0
  654. */
  655. public void AddBoneMask(string name, bool recursive = true)
  656. {
  657. var currentBone = _armature.GetBone(name);
  658. if (currentBone == null)
  659. {
  660. return;
  661. }
  662. if (!_boneMask.Contains(name)) // Add mixing
  663. {
  664. _boneMask.Add(name);
  665. }
  666. if (recursive)
  667. {
  668. var bones = _armature.GetBones();
  669. for (int i = 0, l = bones.Count; i < l; ++i)
  670. {
  671. var bone = bones[i];
  672. if (!_boneMask.Contains(bone.name) && currentBone.Contains(bone)) // Add recursive mixing.
  673. {
  674. _boneMask.Add(bone.name);
  675. }
  676. }
  677. }
  678. _updateTimelineStates();
  679. }
  680. /**
  681. * @language zh_CN
  682. * 删除骨骼遮罩。
  683. * @param boneName 指定的骨骼名称。
  684. * @param recursive 是否删除该骨骼的子骨骼遮罩。
  685. * @version DragonBones 3.0
  686. */
  687. public void RemoveBoneMask(string name, bool recursive = true)
  688. {
  689. if (_boneMask.Contains(name)) // Remove mixing.
  690. {
  691. _boneMask.Remove(name);
  692. }
  693. if (recursive)
  694. {
  695. var currentBone = _armature.GetBone(name);
  696. if (currentBone != null)
  697. {
  698. var bones = _armature.GetBones();
  699. if (_boneMask.Count > 0)
  700. {
  701. for (int i = 0, l = bones.Count; i < l; ++i)
  702. {
  703. var bone = bones[i];
  704. if (_boneMask.Contains(bone.name) && currentBone.Contains(bone)) // Remove recursive mixing.
  705. {
  706. _boneMask.Remove(bone.name);
  707. }
  708. }
  709. }
  710. else
  711. {
  712. for (int i = 0, l = bones.Count; i < l; ++i)
  713. {
  714. var bone = bones[i];
  715. if (!currentBone.Contains(bone)) // Add unrecursive mixing.
  716. {
  717. _boneMask.Add(bone.name);
  718. }
  719. }
  720. }
  721. }
  722. }
  723. _updateTimelineStates();
  724. }
  725. /**
  726. * @language zh_CN
  727. * 删除所有骨骼遮罩。
  728. * @version DragonBones 3.0
  729. */
  730. public void RemoveAllBoneMask()
  731. {
  732. _boneMask.Clear();
  733. _updateTimelineStates();
  734. }
  735. /**
  736. * @language zh_CN
  737. * 混合图层。
  738. * @version DragonBones 3.0
  739. */
  740. public int layer
  741. {
  742. get { return _layer; }
  743. }
  744. /**
  745. * @language zh_CN
  746. * 混合组。
  747. * @version DragonBones 3.0
  748. */
  749. public string group
  750. {
  751. get { return _group; }
  752. }
  753. /**
  754. * @language zh_CN
  755. * 动画名称。
  756. * @see DragonBones.AnimationData#name
  757. * @version DragonBones 3.0
  758. */
  759. public string name
  760. {
  761. get { return _name; }
  762. }
  763. /**
  764. * @language zh_CN
  765. * 动画数据。
  766. * @see DragonBones.AnimationData
  767. * @version DragonBones 3.0
  768. */
  769. public AnimationData animationData
  770. {
  771. get { return _animationData; }
  772. }
  773. /**
  774. * @language zh_CN
  775. * 是否播放完毕。
  776. * @version DragonBones 3.0
  777. */
  778. public bool isCompleted
  779. {
  780. get { return _timeline._playState > 0; }
  781. }
  782. /**
  783. * @language zh_CN
  784. * 是否正在播放。
  785. * @version DragonBones 3.0
  786. */
  787. public bool isPlaying
  788. {
  789. get { return (_playheadState & 2) != 0 && _timeline._playState <= 0; } // 1x
  790. }
  791. /**
  792. * @language zh_CN
  793. * 当前播放次数。
  794. * @version DragonBones 3.0
  795. */
  796. public uint currentPlayTimes
  797. {
  798. get { return _timeline._currentPlayTimes; }
  799. }
  800. /**
  801. * @language zh_CN
  802. * 动画的总时间。 (以秒为单位)
  803. * @version DragonBones 3.0
  804. */
  805. public float totalTime
  806. {
  807. get { return _duration; }
  808. }
  809. /**
  810. * @language zh_CN
  811. * 动画当前播放的时间。 (以秒为单位)
  812. * @version DragonBones 3.0
  813. */
  814. public float currentTime
  815. {
  816. get { return _timeline._currentTime; }
  817. set
  818. {
  819. if (value < 0.0f || float.IsNaN(value))
  820. {
  821. value = 0.0f;
  822. }
  823. var currentPlayTimes = _timeline._currentPlayTimes - (_timeline._playState > 0 ? 1 : 0);
  824. value = (value % _duration) + currentPlayTimes * _duration;
  825. if (_time == value)
  826. {
  827. return;
  828. }
  829. _time = value;
  830. _timeline.setCurrentTime(_time);
  831. if (_zOrderTimeline != null)
  832. {
  833. _zOrderTimeline._playState = -1;
  834. }
  835. foreach (var boneTimelineState in _boneTimelines)
  836. {
  837. boneTimelineState._playState = -1;
  838. }
  839. foreach (var slotTimelineState in _slotTimelines)
  840. {
  841. slotTimelineState._playState = -1;
  842. }
  843. foreach (var ffdTimelineState in _ffdTimelines)
  844. {
  845. ffdTimelineState._playState = -1;
  846. }
  847. }
  848. }
  849. }
  850. }