AnimationState.cs 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500
  1. /**
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2012-2017 DragonBones team and other contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  7. * this software and associated documentation files (the "Software"), to deal in
  8. * the Software without restriction, including without limitation the rights to
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10. * the Software, and to permit persons to whom the Software is furnished to do so,
  11. * subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. using System;
  24. using System.Collections.Generic;
  25. namespace DragonBones
  26. {
  27. /// <summary>
  28. /// - The animation state is generated when the animation data is played.
  29. /// </summary>
  30. /// <see cref="DragonBones.Animation"/>
  31. /// <see cref="DragonBones.AnimationData"/>
  32. /// <version>DragonBones 3.0</version>
  33. /// <language>en_US</language>
  34. /// <summary>
  35. /// - 动画状态由播放动画数据时产生。
  36. /// </summary>
  37. /// <see cref="DragonBones.Animation"/>
  38. /// <see cref="DragonBones.AnimationData"/>
  39. /// <version>DragonBones 3.0</version>
  40. /// <language>zh_CN</language>
  41. public class AnimationState : BaseObject
  42. {
  43. /// <private/>
  44. public bool actionEnabled;
  45. /// <private/>
  46. public bool additiveBlending;
  47. /// <summary>
  48. /// - Whether the animation state has control over the display object properties of the slots.
  49. /// Sometimes blend a animation state does not want it to control the display object properties of the slots,
  50. /// especially if other animation state are controlling the display object properties of the slots.
  51. /// </summary>
  52. /// <default>true</default>
  53. /// <version>DragonBones 5.0</version>
  54. /// <language>en_US</language>
  55. /// <summary>
  56. /// - 动画状态是否对插槽的显示对象属性有控制权。
  57. /// 有时混合一个动画状态并不希望其控制插槽的显示对象属性,
  58. /// 尤其是其他动画状态正在控制这些插槽的显示对象属性时。
  59. /// </summary>
  60. /// <default>true</default>
  61. /// <version>DragonBones 5.0</version>
  62. /// <language>zh_CN</language>
  63. public bool displayControl;
  64. /// <summary>
  65. /// - Whether to reset the objects without animation to the armature pose when the animation state is start to play.
  66. /// This property should usually be set to false when blend multiple animation states.
  67. /// </summary>
  68. /// <default>true</default>
  69. /// <version>DragonBones 5.1</version>
  70. /// <language>en_US</language>
  71. /// <summary>
  72. /// - 开始播放动画状态时是否将没有动画的对象重置为骨架初始值。
  73. /// 通常在混合多个动画状态时应该将该属性设置为 false。
  74. /// </summary>
  75. /// <default>true</default>
  76. /// <version>DragonBones 5.1</version>
  77. /// <language>zh_CN</language>
  78. public bool resetToPose;
  79. /// <summary>
  80. /// - The play times. [0: Loop play, [1~N]: Play N times]
  81. /// </summary>
  82. /// <version>DragonBones 3.0</version>
  83. /// <language>en_US</language>
  84. /// <summary>
  85. /// - 播放次数。 [0: 无限循环播放, [1~N]: 循环播放 N 次]
  86. /// </summary>
  87. /// <version>DragonBones 3.0</version>
  88. /// <language>zh_CN</language>
  89. public int playTimes;
  90. /// <summary>
  91. /// - The blend layer.
  92. /// High layer animation state will get the blend weight first.
  93. /// When the blend weight is assigned more than 1, the remaining animation states will no longer get the weight assigned.
  94. /// </summary>
  95. /// <readonly/>
  96. /// <version>DragonBones 5.0</version>
  97. /// <language>en_US</language>
  98. /// <summary>
  99. /// - 混合图层。
  100. /// 图层高的动画状态会优先获取混合权重。
  101. /// 当混合权重分配超过 1 时,剩余的动画状态将不再获得权重分配。
  102. /// </summary>
  103. /// <readonly/>
  104. /// <version>DragonBones 5.0</version>
  105. /// <language>zh_CN</language>
  106. public int layer;
  107. /// <summary>
  108. /// - The play speed.
  109. /// The value is an overlay relationship with {@link dragonBones.Animation#timeScale}.
  110. /// [(-N~0): Reverse play, 0: Stop play, (0~1): Slow play, 1: Normal play, (1~N): Fast play]
  111. /// </summary>
  112. /// <default>1.0</default>
  113. /// <version>DragonBones 3.0</version>
  114. /// <language>en_US</language>
  115. /// <summary>
  116. /// - 播放速度。
  117. /// 该值与 {@link dragonBones.Animation#timeScale} 是叠加关系。
  118. /// [(-N~0): 倒转播放, 0: 停止播放, (0~1): 慢速播放, 1: 正常播放, (1~N): 快速播放]
  119. /// </summary>
  120. /// <default>1.0</default>
  121. /// <version>DragonBones 3.0</version>
  122. /// <language>zh_CN</language>
  123. public float timeScale;
  124. /// <summary>
  125. /// - The blend weight.
  126. /// </summary>
  127. /// <default>1.0</default>
  128. /// <version>DragonBones 5.0</version>
  129. /// <language>en_US</language>
  130. /// <summary>
  131. /// - 混合权重。
  132. /// </summary>
  133. /// <default>1.0</default>
  134. /// <version>DragonBones 5.0</version>
  135. /// <language>zh_CN</language>
  136. public float weight;
  137. /// <summary>
  138. /// - The auto fade out time when the animation state play completed.
  139. /// [-1: Do not fade out automatically, [0~N]: The fade out time] (In seconds)
  140. /// </summary>
  141. /// <default>-1.0</default>
  142. /// <version>DragonBones 5.0</version>
  143. /// <language>en_US</language>
  144. /// <summary>
  145. /// - 动画状态播放完成后的自动淡出时间。
  146. /// [-1: 不自动淡出, [0~N]: 淡出时间] (以秒为单位)
  147. /// </summary>
  148. /// <default>-1.0</default>
  149. /// <version>DragonBones 5.0</version>
  150. /// <language>zh_CN</language>
  151. public float autoFadeOutTime;
  152. /// <private/>
  153. public float fadeTotalTime;
  154. /// <summary>
  155. /// - The name of the animation state. (Can be different from the name of the animation data)
  156. /// </summary>
  157. /// <readonly/>
  158. /// <version>DragonBones 5.0</version>
  159. /// <language>en_US</language>
  160. /// <summary>
  161. /// - 动画状态名称。 (可以不同于动画数据)
  162. /// </summary>
  163. /// <readonly/>
  164. /// <version>DragonBones 5.0</version>
  165. /// <language>zh_CN</language>
  166. public string name;
  167. /// <summary>
  168. /// - The blend group name of the animation state.
  169. /// This property is typically used to specify the substitution of multiple animation states blend.
  170. /// </summary>
  171. /// <readonly/>
  172. /// <version>DragonBones 5.0</version>
  173. /// <language>en_US</language>
  174. /// <summary>
  175. /// - 混合组名称。
  176. /// 该属性通常用来指定多个动画状态混合时的相互替换关系。
  177. /// </summary>
  178. /// <readonly/>
  179. /// <version>DragonBones 5.0</version>
  180. /// <language>zh_CN</language>
  181. public string group;
  182. private int _timelineDirty;
  183. /// <summary>
  184. /// - xx: Play Enabled, Fade Play Enabled
  185. /// </summary>
  186. /// <internal/>
  187. /// <private/>
  188. internal int _playheadState;
  189. /// <summary>
  190. /// -1: Fade in, 0: Fade complete, 1: Fade out;
  191. /// </summary>
  192. /// <internal/>
  193. /// <private/>
  194. internal int _fadeState;
  195. /// <summary>
  196. /// -1: Fade start, 0: Fading, 1: Fade complete;
  197. /// </summary>
  198. /// <internal/>
  199. /// <private/>
  200. internal int _subFadeState;
  201. /// <internal/>
  202. /// <private/>
  203. internal float _position;
  204. /// <internal/>
  205. /// <private/>
  206. internal float _duration;
  207. private float _fadeTime;
  208. private float _time;
  209. /// <internal/>
  210. /// <private/>
  211. internal float _fadeProgress;
  212. /// <internal/>
  213. /// <private/>
  214. private float _weightResult;
  215. /// <internal/>
  216. /// <private/>
  217. internal readonly BlendState _blendState = new BlendState();
  218. private readonly List<string> _boneMask = new List<string>();
  219. private readonly List<BoneTimelineState> _boneTimelines = new List<BoneTimelineState>();
  220. private readonly List<SlotTimelineState> _slotTimelines = new List<SlotTimelineState>();
  221. private readonly List<ConstraintTimelineState> _constraintTimelines = new List<ConstraintTimelineState>();
  222. private readonly List<TimelineState> _poseTimelines = new List<TimelineState>();
  223. private readonly Dictionary<string, BonePose> _bonePoses = new Dictionary<string, BonePose>();
  224. /// <internal/>
  225. /// <private/>
  226. public AnimationData _animationData;
  227. private Armature _armature;
  228. /// <internal/>
  229. /// <private/>
  230. internal ActionTimelineState _actionTimeline = null; // Initial value.
  231. private ZOrderTimelineState _zOrderTimeline = null; // Initial value.
  232. /// <internal/>
  233. /// <private/>
  234. public AnimationState _parent = null; // Initial value.
  235. /// <private/>
  236. protected override void _OnClear()
  237. {
  238. foreach (var timeline in this._boneTimelines)
  239. {
  240. timeline.ReturnToPool();
  241. }
  242. foreach (var timeline in this._slotTimelines)
  243. {
  244. timeline.ReturnToPool();
  245. }
  246. foreach (var timeline in this._constraintTimelines)
  247. {
  248. timeline.ReturnToPool();
  249. }
  250. foreach(var timeline in this._poseTimelines)
  251. {
  252. timeline.ReturnToPool();
  253. }
  254. foreach (var bonePose in this._bonePoses.Values)
  255. {
  256. bonePose.ReturnToPool();
  257. }
  258. if (this._actionTimeline != null)
  259. {
  260. this._actionTimeline.ReturnToPool();
  261. }
  262. if (this._zOrderTimeline != null)
  263. {
  264. this._zOrderTimeline.ReturnToPool();
  265. }
  266. this.actionEnabled = false;
  267. this.additiveBlending = false;
  268. this.displayControl = false;
  269. this.resetToPose = false;
  270. this.playTimes = 1;
  271. this.layer = 0;
  272. this.timeScale = 1.0f;
  273. this.weight = 1.0f;
  274. this.autoFadeOutTime = 0.0f;
  275. this.fadeTotalTime = 0.0f;
  276. this.name = string.Empty;
  277. this.group = string.Empty;
  278. this._timelineDirty = 2;
  279. this._playheadState = 0;
  280. this._fadeState = -1;
  281. this._subFadeState = -1;
  282. this._position = 0.0f;
  283. this._duration = 0.0f;
  284. this._fadeTime = 0.0f;
  285. this._time = 0.0f;
  286. this._fadeProgress = 0.0f;
  287. this._weightResult = 0.0f;
  288. this._blendState.Clear();
  289. this._boneMask.Clear();
  290. this._boneTimelines.Clear();
  291. this._slotTimelines.Clear();
  292. this._constraintTimelines.Clear();
  293. this._poseTimelines.Clear();
  294. this._bonePoses.Clear();
  295. this._animationData = null; //
  296. this._armature = null; //
  297. this._actionTimeline = null; //
  298. this._zOrderTimeline = null;
  299. this._parent = null;
  300. }
  301. private void _UpdateTimelines()
  302. {
  303. { // Update constraint timelines.
  304. foreach (var constraint in this._armature._constraints)
  305. {
  306. var timelineDatas = this._animationData.GetConstraintTimelines(constraint.name);
  307. if (timelineDatas != null)
  308. {
  309. foreach (var timelineData in timelineDatas)
  310. {
  311. switch (timelineData.type)
  312. {
  313. case TimelineType.IKConstraint:
  314. {
  315. var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
  316. timeline.constraint = constraint;
  317. timeline.Init(this._armature, this, timelineData);
  318. this._constraintTimelines.Add(timeline);
  319. break;
  320. }
  321. default:
  322. break;
  323. }
  324. }
  325. }
  326. else if (this.resetToPose)
  327. { // Pose timeline.
  328. var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
  329. timeline.constraint = constraint;
  330. timeline.Init(this._armature, this, null);
  331. this._constraintTimelines.Add(timeline);
  332. this._poseTimelines.Add(timeline);
  333. }
  334. }
  335. }
  336. }
  337. private void _UpdateBoneAndSlotTimelines()
  338. {
  339. { // Update bone timelines.
  340. Dictionary<string, List<BoneTimelineState>> boneTimelines = new Dictionary<string, List<BoneTimelineState>>();
  341. foreach (var timeline in this._boneTimelines)
  342. {
  343. // Create bone timelines map.
  344. var timelineName = timeline.bone.name;
  345. if (!(boneTimelines.ContainsKey(timelineName)))
  346. {
  347. boneTimelines[timelineName] = new List<BoneTimelineState>();
  348. }
  349. boneTimelines[timelineName].Add(timeline);
  350. }
  351. foreach (var bone in this._armature.GetBones())
  352. {
  353. var timelineName = bone.name;
  354. if (!this.ContainsBoneMask(timelineName))
  355. {
  356. continue;
  357. }
  358. var timelineDatas = this._animationData.GetBoneTimelines(timelineName);
  359. if (boneTimelines.ContainsKey(timelineName))
  360. {
  361. // Remove bone timeline from map.
  362. boneTimelines.Remove(timelineName);
  363. }
  364. else
  365. {
  366. // Create new bone timeline.
  367. var bonePose = this._bonePoses.ContainsKey(timelineName) ? this._bonePoses[timelineName] : (this._bonePoses[timelineName] = BaseObject.BorrowObject<BonePose>());
  368. if (timelineDatas != null)
  369. {
  370. foreach (var timelineData in timelineDatas)
  371. {
  372. switch (timelineData.type)
  373. {
  374. case TimelineType.BoneAll:
  375. {
  376. var timeline = BaseObject.BorrowObject<BoneAllTimelineState>();
  377. timeline.bone = bone;
  378. timeline.bonePose = bonePose;
  379. timeline.Init(this._armature, this, timelineData);
  380. this._boneTimelines.Add(timeline);
  381. break;
  382. }
  383. case TimelineType.BoneTranslate:
  384. {
  385. var timeline = BaseObject.BorrowObject<BoneTranslateTimelineState>();
  386. timeline.bone = bone;
  387. timeline.bonePose = bonePose;
  388. timeline.Init(this._armature, this, timelineData);
  389. this._boneTimelines.Add(timeline);
  390. break;
  391. }
  392. case TimelineType.BoneRotate:
  393. {
  394. var timeline = BaseObject.BorrowObject<BoneRotateTimelineState>();
  395. timeline.bone = bone;
  396. timeline.bonePose = bonePose;
  397. timeline.Init(this._armature, this, timelineData);
  398. this._boneTimelines.Add(timeline);
  399. break;
  400. }
  401. case TimelineType.BoneScale:
  402. {
  403. var timeline = BaseObject.BorrowObject<BoneScaleTimelineState>();
  404. timeline.bone = bone;
  405. timeline.bonePose = bonePose;
  406. timeline.Init(this._armature, this, timelineData);
  407. this._boneTimelines.Add(timeline);
  408. break;
  409. }
  410. default:
  411. break;
  412. }
  413. }
  414. }
  415. else if (this.resetToPose)
  416. { // Pose timeline.
  417. var timeline = BaseObject.BorrowObject<BoneAllTimelineState>();
  418. timeline.bone = bone;
  419. timeline.bonePose = bonePose;
  420. timeline.Init(this._armature, this, null);
  421. this._boneTimelines.Add(timeline);
  422. this._poseTimelines.Add(timeline);
  423. }
  424. }
  425. }
  426. foreach (var timelines in boneTimelines.Values)
  427. {
  428. // Remove bone timelines.
  429. foreach (var timeline in timelines)
  430. {
  431. this._boneTimelines.Remove(timeline);
  432. timeline.ReturnToPool();
  433. }
  434. }
  435. }
  436. { // Update slot timelines.
  437. Dictionary<string, List<SlotTimelineState>> slotTimelines = new Dictionary<string, List<SlotTimelineState>>();
  438. List<int> ffdFlags = new List<int>();
  439. foreach (var timeline in this._slotTimelines)
  440. {
  441. // Create slot timelines map.
  442. var timelineName = timeline.slot.name;
  443. if (!(slotTimelines.ContainsKey(timelineName)))
  444. {
  445. slotTimelines[timelineName] = new List<SlotTimelineState>();
  446. }
  447. slotTimelines[timelineName].Add(timeline);
  448. }
  449. foreach (var slot in this._armature.GetSlots())
  450. {
  451. var boneName = slot.parent.name;
  452. if (!this.ContainsBoneMask(boneName))
  453. {
  454. continue;
  455. }
  456. var timelineName = slot.name;
  457. var timelineDatas = this._animationData.GetSlotTimelines(timelineName);
  458. if (slotTimelines.ContainsKey(timelineName))
  459. {
  460. // Remove slot timeline from map.
  461. slotTimelines.Remove(timelineName);
  462. }
  463. else
  464. {
  465. // Create new slot timeline.
  466. var displayIndexFlag = false;
  467. var colorFlag = false;
  468. ffdFlags.Clear();
  469. if (timelineDatas != null)
  470. {
  471. foreach (var timelineData in timelineDatas)
  472. {
  473. switch (timelineData.type)
  474. {
  475. case TimelineType.SlotDisplay:
  476. {
  477. var timeline = BaseObject.BorrowObject<SlotDislayTimelineState>();
  478. timeline.slot = slot;
  479. timeline.Init(this._armature, this, timelineData);
  480. this._slotTimelines.Add(timeline);
  481. displayIndexFlag = true;
  482. break;
  483. }
  484. case TimelineType.SlotColor:
  485. {
  486. var timeline = BaseObject.BorrowObject<SlotColorTimelineState>();
  487. timeline.slot = slot;
  488. timeline.Init(this._armature, this, timelineData);
  489. this._slotTimelines.Add(timeline);
  490. colorFlag = true;
  491. break;
  492. }
  493. case TimelineType.SlotDeform:
  494. {
  495. var timeline = BaseObject.BorrowObject<DeformTimelineState>();
  496. timeline.slot = slot;
  497. timeline.Init(this._armature, this, timelineData);
  498. this._slotTimelines.Add(timeline);
  499. ffdFlags.Add((int)timeline.vertexOffset);
  500. break;
  501. }
  502. default:
  503. break;
  504. }
  505. }
  506. }
  507. if (this.resetToPose)
  508. {
  509. // Pose timeline.
  510. if (!displayIndexFlag)
  511. {
  512. var timeline = BaseObject.BorrowObject<SlotDislayTimelineState>();
  513. timeline.slot = slot;
  514. timeline.Init(this._armature, this, null);
  515. this._slotTimelines.Add(timeline);
  516. this._poseTimelines.Add(timeline);
  517. }
  518. if (!colorFlag)
  519. {
  520. var timeline = BaseObject.BorrowObject<SlotColorTimelineState>();
  521. timeline.slot = slot;
  522. timeline.Init(this._armature, this, null);
  523. this._slotTimelines.Add(timeline);
  524. this._poseTimelines.Add(timeline);
  525. }
  526. if (slot.rawDisplayDatas != null)
  527. {
  528. foreach (var displayData in slot.rawDisplayDatas)
  529. {
  530. if (displayData != null && displayData.type == DisplayType.Mesh)
  531. {
  532. var meshOffset = (displayData as MeshDisplayData).vertices.offset;
  533. if (!ffdFlags.Contains(meshOffset))
  534. {
  535. var timeline = BaseObject.BorrowObject<DeformTimelineState>();
  536. timeline.vertexOffset = meshOffset; //
  537. timeline.slot = slot;
  538. timeline.Init(this._armature, this, null);
  539. this._slotTimelines.Add(timeline);
  540. this._poseTimelines.Add(timeline);
  541. }
  542. }
  543. }
  544. }
  545. }
  546. }
  547. }
  548. foreach (var timelines in slotTimelines.Values)
  549. {
  550. // Remove slot timelines.
  551. foreach (var timeline in timelines)
  552. {
  553. this._slotTimelines.Remove(timeline);
  554. timeline.ReturnToPool();
  555. }
  556. }
  557. }
  558. // {
  559. // // Update constraint timelines.
  560. // Dictionary<string, List<ConstraintTimelineState>> constraintTimelines = new Dictionary<string, List<ConstraintTimelineState>>();
  561. // foreach (var timeline in this._constraintTimelines)
  562. // { // Create constraint timelines map.
  563. // var timelineName = timeline.constraint.name;
  564. // if (!(constraintTimelines.ContainsKey(timelineName)))
  565. // {
  566. // constraintTimelines[timelineName] = new List<ConstraintTimelineState>();
  567. // }
  568. // constraintTimelines[timelineName].Add(timeline);
  569. // }
  570. // foreach (var constraint in this._armature._constraints)
  571. // {
  572. // var timelineName = constraint.name;
  573. // var timelineDatas = this._animationData.GetConstraintTimelines(timelineName);
  574. // if (constraintTimelines.ContainsKey(timelineName))
  575. // {
  576. // // Remove constraint timeline from map.
  577. // constraintTimelines.Remove(timelineName);
  578. // }
  579. // else
  580. // {
  581. // // Create new constraint timeline.
  582. // if (timelineDatas != null)
  583. // {
  584. // foreach (var timelineData in timelineDatas)
  585. // {
  586. // switch (timelineData.type)
  587. // {
  588. // case TimelineType.IKConstraint:
  589. // {
  590. // var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
  591. // timeline.constraint = constraint;
  592. // timeline.Init(this._armature, this, timelineData);
  593. // this._constraintTimelines.Add(timeline);
  594. // break;
  595. // }
  596. // default:
  597. // break;
  598. // }
  599. // }
  600. // }
  601. // else if (this.resetToPose)
  602. // {
  603. // // Pose timeline.
  604. // var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
  605. // timeline.constraint = constraint;
  606. // timeline.Init(this._armature, this, null);
  607. // this._constraintTimelines.Add(timeline);
  608. // this._poseTimelines.Add(timeline);
  609. // }
  610. // }
  611. // }
  612. // foreach (var timelines in constraintTimelines.Values)
  613. // { // Remove constraint timelines.
  614. // foreach (var timeline in timelines)
  615. // {
  616. // this._constraintTimelines.Remove(timeline);
  617. // timeline.ReturnToPool();
  618. // }
  619. // }
  620. // }
  621. }
  622. private void _AdvanceFadeTime(float passedTime)
  623. {
  624. var isFadeOut = this._fadeState > 0;
  625. if (this._subFadeState < 0)
  626. {
  627. // Fade start event.
  628. this._subFadeState = 0;
  629. var eventType = isFadeOut ? EventObject.FADE_OUT : EventObject.FADE_IN;
  630. if (this._armature.eventDispatcher.HasDBEventListener(eventType))
  631. {
  632. var eventObject = BaseObject.BorrowObject<EventObject>();
  633. eventObject.type = eventType;
  634. eventObject.armature = this._armature;
  635. eventObject.animationState = this;
  636. this._armature._dragonBones.BufferEvent(eventObject);
  637. }
  638. }
  639. if (passedTime < 0.0f)
  640. {
  641. passedTime = -passedTime;
  642. }
  643. this._fadeTime += passedTime;
  644. if (this._fadeTime >= this.fadeTotalTime)
  645. {
  646. // Fade complete.
  647. this._subFadeState = 1;
  648. this._fadeProgress = isFadeOut ? 0.0f : 1.0f;
  649. }
  650. else if (this._fadeTime > 0.0f)
  651. {
  652. // Fading.
  653. this._fadeProgress = isFadeOut ? (1.0f - this._fadeTime / this.fadeTotalTime) : (this._fadeTime / this.fadeTotalTime);
  654. }
  655. else
  656. {
  657. // Before fade.
  658. this._fadeProgress = isFadeOut ? 1.0f : 0.0f;
  659. }
  660. if (this._subFadeState > 0)
  661. {
  662. // Fade complete event.
  663. if (!isFadeOut)
  664. {
  665. this._playheadState |= 1; // x1
  666. this._fadeState = 0;
  667. }
  668. var eventType = isFadeOut ? EventObject.FADE_OUT_COMPLETE : EventObject.FADE_IN_COMPLETE;
  669. if (this._armature.eventDispatcher.HasDBEventListener(eventType))
  670. {
  671. var eventObject = BaseObject.BorrowObject<EventObject>();
  672. eventObject.type = eventType;
  673. eventObject.armature = this._armature;
  674. eventObject.animationState = this;
  675. this._armature._dragonBones.BufferEvent(eventObject);
  676. }
  677. }
  678. }
  679. /// <internal/>
  680. /// <private/>
  681. internal void Init(Armature armature, AnimationData animationData, AnimationConfig animationConfig)
  682. {
  683. if (this._armature != null)
  684. {
  685. return;
  686. }
  687. this._armature = armature;
  688. this._animationData = animationData;
  689. this.resetToPose = animationConfig.resetToPose;
  690. this.additiveBlending = animationConfig.additiveBlending;
  691. this.displayControl = animationConfig.displayControl;
  692. this.actionEnabled = animationConfig.actionEnabled;
  693. this.layer = animationConfig.layer;
  694. this.playTimes = animationConfig.playTimes;
  695. this.timeScale = animationConfig.timeScale;
  696. this.fadeTotalTime = animationConfig.fadeInTime;
  697. this.autoFadeOutTime = animationConfig.autoFadeOutTime;
  698. this.weight = animationConfig.weight;
  699. this.name = animationConfig.name.Length > 0 ? animationConfig.name : animationConfig.animation;
  700. this.group = animationConfig.group;
  701. if (animationConfig.pauseFadeIn)
  702. {
  703. this._playheadState = 2; // 10
  704. }
  705. else
  706. {
  707. this._playheadState = 3; // 11
  708. }
  709. if (animationConfig.duration < 0.0f)
  710. {
  711. this._position = 0.0f;
  712. this._duration = this._animationData.duration;
  713. if (animationConfig.position != 0.0f)
  714. {
  715. if (this.timeScale >= 0.0f)
  716. {
  717. this._time = animationConfig.position;
  718. }
  719. else
  720. {
  721. this._time = animationConfig.position - this._duration;
  722. }
  723. }
  724. else
  725. {
  726. this._time = 0.0f;
  727. }
  728. }
  729. else
  730. {
  731. this._position = animationConfig.position;
  732. this._duration = animationConfig.duration;
  733. this._time = 0.0f;
  734. }
  735. if (this.timeScale < 0.0f && this._time == 0.0f)
  736. {
  737. this._time = -0.000001f; // Turn to end.
  738. }
  739. if (this.fadeTotalTime <= 0.0f)
  740. {
  741. this._fadeProgress = 0.999999f; // Make different.
  742. }
  743. if (animationConfig.boneMask.Count > 0)
  744. {
  745. this._boneMask.ResizeList(animationConfig.boneMask.Count);
  746. for (int i = 0, l = this._boneMask.Count; i < l; ++i)
  747. {
  748. this._boneMask[i] = animationConfig.boneMask[i];
  749. }
  750. }
  751. this._actionTimeline = BaseObject.BorrowObject<ActionTimelineState>();
  752. this._actionTimeline.Init(this._armature, this, this._animationData.actionTimeline);
  753. this._actionTimeline.currentTime = this._time;
  754. if (this._actionTimeline.currentTime < 0.0f)
  755. {
  756. this._actionTimeline.currentTime = this._duration - this._actionTimeline.currentTime;
  757. }
  758. if (this._animationData.zOrderTimeline != null)
  759. {
  760. this._zOrderTimeline = BaseObject.BorrowObject<ZOrderTimelineState>();
  761. this._zOrderTimeline.Init(this._armature, this, this._animationData.zOrderTimeline);
  762. }
  763. }
  764. /// <internal/>
  765. /// <private/>
  766. internal void AdvanceTime(float passedTime, float cacheFrameRate)
  767. {
  768. this._blendState.dirty = true;
  769. // Update fade time.
  770. if (this._fadeState != 0 || this._subFadeState != 0)
  771. {
  772. this._AdvanceFadeTime(passedTime);
  773. }
  774. // Update time.
  775. if (this._playheadState == 3)
  776. {
  777. // 11
  778. if (this.timeScale != 1.0f)
  779. {
  780. passedTime *= this.timeScale;
  781. }
  782. this._time += passedTime;
  783. }
  784. // Update timeline.
  785. if (this._timelineDirty != 0)
  786. {
  787. if (this._timelineDirty == 2)
  788. {
  789. this._UpdateTimelines();
  790. }
  791. this._timelineDirty = 0;
  792. this._UpdateBoneAndSlotTimelines();
  793. }
  794. if (this.weight == 0.0f)
  795. {
  796. return;
  797. }
  798. var isCacheEnabled = this._fadeState == 0 && cacheFrameRate > 0.0f;
  799. var isUpdateTimeline = true;
  800. var isUpdateBoneTimeline = true;
  801. var time = this._time;
  802. this._weightResult = this.weight * this._fadeProgress;
  803. if (this._parent != null)
  804. {
  805. this._weightResult *= this._parent._weightResult / this._parent._fadeProgress;
  806. }
  807. if (this._actionTimeline.playState <= 0)
  808. {
  809. // Update main timeline.
  810. this._actionTimeline.Update(time);
  811. }
  812. if (isCacheEnabled)
  813. {
  814. // Cache time internval.
  815. var internval = cacheFrameRate * 2.0f;
  816. this._actionTimeline.currentTime = (float)Math.Floor(this._actionTimeline.currentTime * internval) / internval;
  817. }
  818. if (this._zOrderTimeline != null && this._zOrderTimeline.playState <= 0)
  819. {
  820. // Update zOrder timeline.
  821. this._zOrderTimeline.Update(time);
  822. }
  823. if (isCacheEnabled)
  824. {
  825. // Update cache.
  826. var cacheFrameIndex = (int)Math.Floor(this._actionTimeline.currentTime * cacheFrameRate); // uint
  827. if (this._armature._cacheFrameIndex == cacheFrameIndex)
  828. {
  829. // Same cache.
  830. isUpdateTimeline = false;
  831. isUpdateBoneTimeline = false;
  832. }
  833. else
  834. {
  835. this._armature._cacheFrameIndex = cacheFrameIndex;
  836. if (this._animationData.cachedFrames[cacheFrameIndex])
  837. {
  838. // Cached.
  839. isUpdateBoneTimeline = false;
  840. }
  841. else
  842. {
  843. // Cache.
  844. this._animationData.cachedFrames[cacheFrameIndex] = true;
  845. }
  846. }
  847. }
  848. if (isUpdateTimeline)
  849. {
  850. if (isUpdateBoneTimeline)
  851. {
  852. for (int i = 0, l = this._boneTimelines.Count; i < l; ++i)
  853. {
  854. var timeline = this._boneTimelines[i];
  855. if (timeline.playState <= 0)
  856. {
  857. timeline.Update(time);
  858. }
  859. if (i == l - 1 || timeline.bone != this._boneTimelines[i + 1].bone)
  860. {
  861. var state = timeline.bone._blendState.Update(this._weightResult, this.layer);
  862. if (state != 0)
  863. {
  864. timeline.Blend(state);
  865. }
  866. }
  867. }
  868. }
  869. if (this.displayControl)
  870. {
  871. for (int i = 0, l = this._slotTimelines.Count; i < l; ++i)
  872. {
  873. var timeline = this._slotTimelines[i];
  874. var displayController = timeline.slot.displayController;
  875. if (
  876. displayController == null ||
  877. displayController == this.name ||
  878. displayController == this.group
  879. )
  880. {
  881. if (timeline.playState <= 0)
  882. {
  883. timeline.Update(time);
  884. }
  885. }
  886. }
  887. }
  888. for (int i = 0, l = this._constraintTimelines.Count; i < l; ++i)
  889. {
  890. var timeline = this._constraintTimelines[i];
  891. if (timeline.playState <= 0)
  892. {
  893. timeline.Update(time);
  894. }
  895. }
  896. }
  897. if (this._fadeState == 0)
  898. {
  899. if (this._subFadeState > 0)
  900. {
  901. this._subFadeState = 0;
  902. if (this._poseTimelines.Count > 0)
  903. {
  904. foreach (var timeline in this._poseTimelines)
  905. {
  906. if (timeline is BoneTimelineState)
  907. {
  908. this._boneTimelines.Remove(timeline as BoneTimelineState);
  909. }
  910. else if (timeline is SlotTimelineState)
  911. {
  912. this._slotTimelines.Remove(timeline as SlotTimelineState);
  913. }
  914. else if (timeline is ConstraintTimelineState)
  915. {
  916. this._constraintTimelines.Remove(timeline as ConstraintTimelineState);
  917. }
  918. timeline.ReturnToPool();
  919. }
  920. this._poseTimelines.Clear();
  921. }
  922. }
  923. if (this._actionTimeline.playState > 0)
  924. {
  925. if (this.autoFadeOutTime >= 0.0f)
  926. {
  927. // Auto fade out.
  928. this.FadeOut(this.autoFadeOutTime);
  929. }
  930. }
  931. }
  932. }
  933. /// <summary>
  934. /// - Continue play.
  935. /// </summary>
  936. /// <version>DragonBones 3.0</version>
  937. /// <language>en_US</language>
  938. /// <summary>
  939. /// - 继续播放。
  940. /// </summary>
  941. /// <version>DragonBones 3.0</version>
  942. /// <language>zh_CN</language>
  943. public void Play()
  944. {
  945. this._playheadState = 3; // 11
  946. }
  947. /// <summary>
  948. /// - Stop play.
  949. /// </summary>
  950. /// <version>DragonBones 3.0</version>
  951. /// <language>en_US</language>
  952. /// <summary>
  953. /// - 暂停播放。
  954. /// </summary>
  955. /// <version>DragonBones 3.0</version>
  956. /// <language>zh_CN</language>
  957. public void Stop()
  958. {
  959. this._playheadState &= 1; // 0x
  960. }
  961. /// <summary>
  962. /// - Fade out the animation state.
  963. /// </summary>
  964. /// <param name="fadeOutTime">- The fade out time. (In seconds)</param>
  965. /// <param name="pausePlayhead">- Whether to pause the animation playing when fade out.</param>
  966. /// <version>DragonBones 3.0</version>
  967. /// <language>en_US</language>
  968. /// <summary>
  969. /// - 淡出动画状态。
  970. /// </summary>
  971. /// <param name="fadeOutTime">- 淡出时间。 (以秒为单位)</param>
  972. /// <param name="pausePlayhead">- 淡出时是否暂停播放。</param>
  973. /// <version>DragonBones 3.0</version>
  974. /// <language>zh_CN</language>
  975. public void FadeOut(float fadeOutTime, bool pausePlayhead = true)
  976. {
  977. if (fadeOutTime < 0.0f)
  978. {
  979. fadeOutTime = 0.0f;
  980. }
  981. if (pausePlayhead)
  982. {
  983. this._playheadState &= 2; // x0
  984. }
  985. if (this._fadeState > 0)
  986. {
  987. if (fadeOutTime > this.fadeTotalTime - this._fadeTime)
  988. {
  989. // If the animation is already in fade out, the new fade out will be ignored.
  990. return;
  991. }
  992. }
  993. else
  994. {
  995. this._fadeState = 1;
  996. this._subFadeState = -1;
  997. if (fadeOutTime <= 0.0f || this._fadeProgress <= 0.0f)
  998. {
  999. this._fadeProgress = 0.000001f; // Modify fade progress to different value.
  1000. }
  1001. foreach (var timeline in this._boneTimelines)
  1002. {
  1003. timeline.FadeOut();
  1004. }
  1005. foreach (var timeline in this._slotTimelines)
  1006. {
  1007. timeline.FadeOut();
  1008. }
  1009. foreach (var timeline in this._constraintTimelines)
  1010. {
  1011. timeline.FadeOut();
  1012. }
  1013. }
  1014. this.displayControl = false; //
  1015. this.fadeTotalTime = this._fadeProgress > 0.000001f ? fadeOutTime / this._fadeProgress : 0.0f;
  1016. this._fadeTime = this.fadeTotalTime * (1.0f - this._fadeProgress);
  1017. }
  1018. /// <summary>
  1019. /// - Check if a specific bone mask is included.
  1020. /// </summary>
  1021. /// <param name="boneName">- The bone name.</param>
  1022. /// <version>DragonBones 3.0</version>
  1023. /// <language>en_US</language>
  1024. /// <summary>
  1025. /// - 检查是否包含特定骨骼遮罩。
  1026. /// </summary>
  1027. /// <param name="boneName">- 骨骼名称。</param>
  1028. /// <version>DragonBones 3.0</version>
  1029. /// <language>zh_CN</language>
  1030. public bool ContainsBoneMask(string boneName)
  1031. {
  1032. return this._boneMask.Count == 0 || this._boneMask.IndexOf(boneName) >= 0;
  1033. }
  1034. /// <summary>
  1035. /// - Add a specific bone mask.
  1036. /// </summary>
  1037. /// <param name="boneName">- The bone name.</param>
  1038. /// <param name="recursive">- Whether or not to add a mask to the bone's sub-bone.</param>
  1039. /// <version>DragonBones 3.0</version>
  1040. /// <language>en_US</language>
  1041. /// <summary>
  1042. /// - 添加特定的骨骼遮罩。
  1043. /// </summary>
  1044. /// <param name="boneName">- 骨骼名称。</param>
  1045. /// <param name="recursive">- 是否为该骨骼的子骨骼添加遮罩。</param>
  1046. /// <version>DragonBones 3.0</version>
  1047. /// <language>zh_CN</language>
  1048. public void AddBoneMask(string boneName, bool recursive = true)
  1049. {
  1050. var currentBone = this._armature.GetBone(boneName);
  1051. if (currentBone == null)
  1052. {
  1053. return;
  1054. }
  1055. if (this._boneMask.IndexOf(boneName) < 0)
  1056. {
  1057. // Add mixing
  1058. this._boneMask.Add(boneName);
  1059. }
  1060. if (recursive)
  1061. {
  1062. // Add recursive mixing.
  1063. foreach (var bone in this._armature.GetBones())
  1064. {
  1065. if (this._boneMask.IndexOf(bone.name) < 0 && currentBone.Contains(bone))
  1066. {
  1067. this._boneMask.Add(bone.name);
  1068. }
  1069. }
  1070. }
  1071. this._timelineDirty = 1;
  1072. }
  1073. /// <summary>
  1074. /// - Remove the mask of a specific bone.
  1075. /// </summary>
  1076. /// <param name="boneName">- The bone name.</param>
  1077. /// <param name="recursive">- Whether to remove the bone's sub-bone mask.</param>
  1078. /// <version>DragonBones 3.0</version>
  1079. /// <language>en_US</language>
  1080. /// <summary>
  1081. /// - 删除特定骨骼的遮罩。
  1082. /// </summary>
  1083. /// <param name="boneName">- 骨骼名称。</param>
  1084. /// <param name="recursive">- 是否删除该骨骼的子骨骼遮罩。</param>
  1085. /// <version>DragonBones 3.0</version>
  1086. /// <language>zh_CN</language>
  1087. public void RemoveBoneMask(string boneName, bool recursive = true)
  1088. {
  1089. if (this._boneMask.Contains(boneName))
  1090. {
  1091. this._boneMask.Remove(boneName);
  1092. }
  1093. if (recursive)
  1094. {
  1095. var currentBone = this._armature.GetBone(boneName);
  1096. if (currentBone != null)
  1097. {
  1098. var bones = this._armature.GetBones();
  1099. if (this._boneMask.Count > 0)
  1100. {
  1101. // Remove recursive mixing.
  1102. foreach (var bone in bones)
  1103. {
  1104. if (this._boneMask.Contains(bone.name) && currentBone.Contains(bone))
  1105. {
  1106. this._boneMask.Remove(bone.name);
  1107. }
  1108. }
  1109. }
  1110. else
  1111. {
  1112. // Add unrecursive mixing.
  1113. foreach (var bone in bones)
  1114. {
  1115. if (bone == currentBone)
  1116. {
  1117. continue;
  1118. }
  1119. if (!currentBone.Contains(bone))
  1120. {
  1121. this._boneMask.Add(bone.name);
  1122. }
  1123. }
  1124. }
  1125. }
  1126. }
  1127. this._timelineDirty = 1;
  1128. }
  1129. /// <summary>
  1130. /// - Remove all bone masks.
  1131. /// </summary>
  1132. /// <version>DragonBones 3.0</version>
  1133. /// <language>en_US</language>
  1134. /// <summary>
  1135. /// - 删除所有骨骼遮罩。
  1136. /// </summary>
  1137. /// <version>DragonBones 3.0</version>
  1138. /// <language>zh_CN</language>
  1139. public void RemoveAllBoneMask()
  1140. {
  1141. this._boneMask.Clear();
  1142. this._timelineDirty = 1;
  1143. }
  1144. /// <summary>
  1145. /// - Whether the animation state is fading in.
  1146. /// </summary>
  1147. /// <version>DragonBones 5.1</version>
  1148. /// <language>en_US</language>
  1149. /// <summary>
  1150. /// - 是否正在淡入。
  1151. /// </summary>
  1152. /// <version>DragonBones 5.1</version>
  1153. /// <language>zh_CN</language>
  1154. public bool isFadeIn
  1155. {
  1156. get { return this._fadeState < 0; }
  1157. }
  1158. /// <summary>
  1159. /// - Whether the animation state is fading out.
  1160. /// </summary>
  1161. /// <version>DragonBones 5.1</version>
  1162. /// <language>en_US</language>
  1163. /// <summary>
  1164. /// - 是否正在淡出。
  1165. /// </summary>
  1166. /// <version>DragonBones 5.1</version>
  1167. /// <language>zh_CN</language>
  1168. public bool isFadeOut
  1169. {
  1170. get { return this._fadeState > 0; }
  1171. }
  1172. /// <summary>
  1173. /// - Whether the animation state is fade completed.
  1174. /// </summary>
  1175. /// <version>DragonBones 5.1</version>
  1176. /// <language>en_US</language>
  1177. /// <summary>
  1178. /// - 是否淡入或淡出完毕。
  1179. /// </summary>
  1180. /// <version>DragonBones 5.1</version>
  1181. /// <language>zh_CN</language>
  1182. public bool isFadeComplete
  1183. {
  1184. get { return this._fadeState == 0; }
  1185. }
  1186. /// <summary>
  1187. /// - Whether the animation state is playing.
  1188. /// </summary>
  1189. /// <version>DragonBones 3.0</version>
  1190. /// <language>en_US</language>
  1191. /// <summary>
  1192. /// - 是否正在播放。
  1193. /// </summary>
  1194. /// <version>DragonBones 3.0</version>
  1195. /// <language>zh_CN</language>
  1196. public bool isPlaying
  1197. {
  1198. get { return (this._playheadState & 2) != 0 && this._actionTimeline.playState <= 0; }
  1199. }
  1200. /// <summary>
  1201. /// - Whether the animation state is play completed.
  1202. /// </summary>
  1203. /// <version>DragonBones 3.0</version>
  1204. /// <language>en_US</language>
  1205. /// <summary>
  1206. /// - 是否播放完毕。
  1207. /// </summary>
  1208. /// <version>DragonBones 3.0</version>
  1209. /// <language>zh_CN</language>
  1210. public bool isCompleted
  1211. {
  1212. get { return this._actionTimeline.playState > 0; }
  1213. }
  1214. /// <summary>
  1215. /// - The times has been played.
  1216. /// </summary>
  1217. /// <version>DragonBones 3.0</version>
  1218. /// <language>en_US</language>
  1219. /// <summary>
  1220. /// - 已经循环播放的次数。
  1221. /// </summary>
  1222. /// <version>DragonBones 3.0</version>
  1223. /// <language>zh_CN</language>
  1224. public int currentPlayTimes
  1225. {
  1226. get { return this._actionTimeline.currentPlayTimes; }
  1227. }
  1228. /// <summary>
  1229. /// - The total time. (In seconds)
  1230. /// </summary>
  1231. /// <version>DragonBones 3.0</version>
  1232. /// <language>en_US</language>
  1233. /// <summary>
  1234. /// - 总播放时间。 (以秒为单位)
  1235. /// </summary>
  1236. /// <version>DragonBones 3.0</version>
  1237. /// <language>zh_CN</language>
  1238. public float totalTime
  1239. {
  1240. get { return this._duration; }
  1241. }
  1242. /// <summary>
  1243. /// - The time is currently playing. (In seconds)
  1244. /// </summary>
  1245. /// <version>DragonBones 3.0</version>
  1246. /// <language>en_US</language>
  1247. /// <summary>
  1248. /// - 当前播放的时间。 (以秒为单位)
  1249. /// </summary>
  1250. /// <version>DragonBones 3.0</version>
  1251. /// <language>zh_CN</language>
  1252. public float currentTime
  1253. {
  1254. get { return this._actionTimeline.currentTime; }
  1255. set
  1256. {
  1257. var currentPlayTimes = this._actionTimeline.currentPlayTimes - (this._actionTimeline.playState > 0 ? 1 : 0);
  1258. if (value < 0.0f || this._duration < value)
  1259. {
  1260. value = (value % this._duration) + currentPlayTimes * this._duration;
  1261. if (value < 0.0f)
  1262. {
  1263. value += this._duration;
  1264. }
  1265. }
  1266. if (this.playTimes > 0 && currentPlayTimes == this.playTimes - 1 && value == this._duration)
  1267. {
  1268. value = this._duration - 0.000001f;
  1269. }
  1270. if (this._time == value)
  1271. {
  1272. return;
  1273. }
  1274. this._time = value;
  1275. this._actionTimeline.SetCurrentTime(this._time);
  1276. if (this._zOrderTimeline != null)
  1277. {
  1278. this._zOrderTimeline.playState = -1;
  1279. }
  1280. foreach (var timeline in this._boneTimelines)
  1281. {
  1282. timeline.playState = -1;
  1283. }
  1284. foreach (var timeline in this._slotTimelines)
  1285. {
  1286. timeline.playState = -1;
  1287. }
  1288. }
  1289. }
  1290. }
  1291. /// <internal/>
  1292. /// <private/>
  1293. internal class BonePose : BaseObject
  1294. {
  1295. public readonly TransformDB current = new TransformDB();
  1296. public readonly TransformDB delta = new TransformDB();
  1297. public readonly TransformDB result = new TransformDB();
  1298. protected override void _OnClear()
  1299. {
  1300. this.current.Identity();
  1301. this.delta.Identity();
  1302. this.result.Identity();
  1303. }
  1304. }
  1305. /// <internal/>
  1306. /// <private/>
  1307. internal class BlendState
  1308. {
  1309. public bool dirty;
  1310. public int layer;
  1311. public float leftWeight;
  1312. public float layerWeight;
  1313. public float blendWeight;
  1314. /// <summary>
  1315. /// -1: First blending, 0: No blending, 1: Blending.
  1316. /// </summary>
  1317. public int Update(float weight, int p_layer)
  1318. {
  1319. if (this.dirty)
  1320. {
  1321. if (this.leftWeight > 0.0f)
  1322. {
  1323. if (this.layer != p_layer)
  1324. {
  1325. if (this.layerWeight >= this.leftWeight)
  1326. {
  1327. this.leftWeight = 0.0f;
  1328. return 0;
  1329. }
  1330. else
  1331. {
  1332. this.layer = p_layer;
  1333. this.leftWeight -= this.layerWeight;
  1334. this.layerWeight = 0.0f;
  1335. }
  1336. }
  1337. }
  1338. else
  1339. {
  1340. return 0;
  1341. }
  1342. weight *= this.leftWeight;
  1343. this.layerWeight += weight;
  1344. this.blendWeight = weight;
  1345. return 2;
  1346. }
  1347. this.dirty = true;
  1348. this.layer = p_layer;
  1349. this.layerWeight = weight;
  1350. this.leftWeight = 1.0f;
  1351. this.blendWeight = weight;
  1352. return 1;
  1353. }
  1354. public void Clear()
  1355. {
  1356. this.dirty = false;
  1357. this.layer = 0;
  1358. this.leftWeight = 0.0f;
  1359. this.layerWeight = 0.0f;
  1360. this.blendWeight = 0.0f;
  1361. }
  1362. }
  1363. }