Armature.cs 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  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. /// - Armature is the core of the skeleton animation system.
  29. /// </summary>
  30. /// <see cref="DragonBones.ArmatureData"/>
  31. /// <see cref="DragonBones.Bone"/>
  32. /// <see cref="DragonBones.Slot"/>
  33. /// <see cref="DragonBones.Animation"/>
  34. /// <version>DragonBones 3.0</version>
  35. /// <language>en_US</language>
  36. /// <summary>
  37. /// - 骨架是骨骼动画系统的核心。
  38. /// </summary>
  39. /// <see cref="DragonBones.ArmatureData"/>
  40. /// <see cref="DragonBones.Bone"/>
  41. /// <see cref="DragonBones.Slot"/>
  42. /// <see cref="DragonBones.Animation"/>
  43. /// <version>DragonBones 3.0</version>
  44. /// <language>zh_CN</language>
  45. public class Armature : BaseObject, IAnimatable
  46. {
  47. private static int _OnSortSlots(Slot a, Slot b)
  48. {
  49. if (a._zOrder > b._zOrder)
  50. {
  51. return 1;
  52. }
  53. else if (a._zOrder < b._zOrder)
  54. {
  55. return -1;
  56. }
  57. return 0;//fixed slots sort error
  58. }
  59. /// <summary>
  60. /// - Whether to inherit the animation control of the parent armature.
  61. /// True to try to have the child armature play an animation with the same name when the parent armature play the animation.
  62. /// </summary>
  63. /// <default>true</default>
  64. /// <version>DragonBones 4.5</version>
  65. /// <language>en_US</language>
  66. /// <summary>
  67. /// - 是否继承父骨架的动画控制。
  68. /// 如果该值为 true,当父骨架播放动画时,会尝试让子骨架播放同名动画。
  69. /// </summary>
  70. /// <default>true</default>
  71. /// <version>DragonBones 4.5</version>
  72. /// <language>zh_CN</language>
  73. public bool inheritAnimation;
  74. /// <private/>
  75. public object userData;
  76. private bool _lockUpdate;
  77. private bool _slotsDirty;
  78. private bool _zOrderDirty;
  79. private bool _flipX;
  80. private bool _flipY;
  81. /// <internal/>
  82. /// <private/>
  83. internal int _cacheFrameIndex;
  84. private readonly List<Bone> _bones = new List<Bone>();
  85. private readonly List<Slot> _slots = new List<Slot>();
  86. /// <internal/>
  87. /// <private/>
  88. internal readonly List<Constraint> _constraints = new List<Constraint>();
  89. private readonly List<EventObject> _actions = new List<EventObject>();
  90. /// <internal/>
  91. /// <private/>
  92. public ArmatureData _armatureData;
  93. private AnimationDB _animation = null; // Initial value.
  94. private IArmatureProxy _proxy = null; // Initial value.
  95. private object _display;
  96. /// <internal/>
  97. /// <private/>
  98. internal TextureAtlasData _replaceTextureAtlasData = null; // Initial value.
  99. private object _replacedTexture;
  100. /// <internal/>
  101. /// <private/>
  102. internal DragonBones _dragonBones;
  103. private WorldClock _clock = null; // Initial value.
  104. /// <internal/>
  105. /// <private/>
  106. internal Slot _parent;
  107. /// <private/>
  108. protected override void _OnClear()
  109. {
  110. if (this._clock != null)
  111. {
  112. // Remove clock first.
  113. this._clock.Remove(this);
  114. }
  115. foreach (var bone in this._bones)
  116. {
  117. bone.ReturnToPool();
  118. }
  119. foreach (var slot in this._slots)
  120. {
  121. slot.ReturnToPool();
  122. }
  123. foreach (var constraint in this._constraints)
  124. {
  125. constraint.ReturnToPool();
  126. }
  127. if (this._animation != null)
  128. {
  129. this._animation.ReturnToPool();
  130. }
  131. if (this._proxy != null)
  132. {
  133. this._proxy.DBClear();
  134. }
  135. if (this._replaceTextureAtlasData != null)
  136. {
  137. this._replaceTextureAtlasData.ReturnToPool();
  138. }
  139. this.inheritAnimation = true;
  140. this.userData = null;
  141. this._lockUpdate = false;
  142. this._slotsDirty = false;
  143. this._zOrderDirty = false;
  144. this._flipX = false;
  145. this._flipY = false;
  146. this._cacheFrameIndex = -1;
  147. this._bones.Clear();
  148. this._slots.Clear();
  149. this._constraints.Clear();
  150. this._actions.Clear();
  151. this._armatureData = null; //
  152. this._animation = null; //
  153. this._proxy = null; //
  154. this._display = null;
  155. this._replaceTextureAtlasData = null;
  156. this._replacedTexture = null;
  157. this._dragonBones = null; //
  158. this._clock = null;
  159. this._parent = null;
  160. }
  161. /// <internal/>
  162. /// <private/>
  163. internal void _SortZOrder(short[] slotIndices, int offset)
  164. {
  165. var slotDatas = this._armatureData.sortedSlots;
  166. var isOriginal = slotIndices == null;
  167. if (this._zOrderDirty || !isOriginal)
  168. {
  169. for (int i = 0, l = slotDatas.Count; i < l; ++i)
  170. {
  171. var slotIndex = isOriginal ? i : slotIndices[offset + i];
  172. if (slotIndex < 0 || slotIndex >= l)
  173. {
  174. continue;
  175. }
  176. var slotData = slotDatas[slotIndex];
  177. var slot = this.GetSlot(slotData.name);
  178. if (slot != null)
  179. {
  180. slot._SetZorder(i);
  181. }
  182. }
  183. this._slotsDirty = true;
  184. this._zOrderDirty = !isOriginal;
  185. }
  186. }
  187. /// <internal/>
  188. /// <private/>
  189. internal void _AddBone(Bone value)
  190. {
  191. if (!this._bones.Contains(value))
  192. {
  193. this._bones.Add(value);
  194. }
  195. }
  196. /// <internal/>
  197. /// <private/>
  198. internal void _AddSlot(Slot value)
  199. {
  200. if (!this._slots.Contains(value))
  201. {
  202. this._slotsDirty = true;
  203. this._slots.Add(value);
  204. }
  205. }
  206. /// <internal/>
  207. /// <private/>
  208. internal void _AddConstraint(Constraint value)
  209. {
  210. if (!this._constraints.Contains(value))
  211. {
  212. this._constraints.Add(value);
  213. }
  214. }
  215. /// <internal/>
  216. /// <private/>
  217. internal void _BufferAction(EventObject action, bool append)
  218. {
  219. if (!this._actions.Contains(action))
  220. {
  221. if (append)
  222. {
  223. this._actions.Add(action);
  224. }
  225. else
  226. {
  227. this._actions.Insert(0, action);
  228. }
  229. }
  230. }
  231. /// <summary>
  232. /// - Dispose the armature. (Return to the object pool)
  233. /// </summary>
  234. /// <example>
  235. /// TypeScript style, for reference only.
  236. /// <pre>
  237. /// removeChild(armature.display);
  238. /// armature.dispose();
  239. /// </pre>
  240. /// </example>
  241. /// <version>DragonBones 3.0</version>
  242. /// <language>en_US</language>
  243. /// <summary>
  244. /// - 释放骨架。 (回收到对象池)
  245. /// </summary>
  246. /// <example>
  247. /// TypeScript 风格,仅供参考。
  248. /// <pre>
  249. /// removeChild(armature.display);
  250. /// armature.dispose();
  251. /// </pre>
  252. /// </example>
  253. /// <version>DragonBones 3.0</version>
  254. /// <language>zh_CN</language>
  255. public void Dispose()
  256. {
  257. if (this._armatureData != null)
  258. {
  259. this._lockUpdate = true;
  260. if (this._dragonBones != null)
  261. {
  262. this._dragonBones.BufferObject(this);
  263. }
  264. }
  265. }
  266. /// <internal/>
  267. /// <private/>
  268. internal void Init(ArmatureData armatureData, IArmatureProxy proxy, object display, DragonBones dragonBones)
  269. {
  270. if (this._armatureData != null)
  271. {
  272. return;
  273. }
  274. this._armatureData = armatureData;
  275. this._animation = BaseObject.BorrowObject<AnimationDB>();
  276. this._proxy = proxy;
  277. this._display = display;
  278. this._dragonBones = dragonBones;
  279. this._proxy.DBInit(this);
  280. this._animation.Init(this);
  281. this._animation.animations = this._armatureData.animations;
  282. }
  283. /// <inheritDoc/>
  284. public void AdvanceTime(float passedTime)
  285. {
  286. if (this._lockUpdate)
  287. {
  288. return;
  289. }
  290. if (this._armatureData == null)
  291. {
  292. Helper.Assert(false, "The armature has been disposed.");
  293. return;
  294. }
  295. else if (this._armatureData.parent == null)
  296. {
  297. Helper.Assert(false, "The armature data has been disposed.\nPlease make sure dispose armature before call factory.clear().");
  298. return;
  299. }
  300. var prevCacheFrameIndex = this._cacheFrameIndex;
  301. // Update animation.
  302. this._animation.AdvanceTime(passedTime);
  303. if (this._slotsDirty)
  304. {
  305. this._slotsDirty = false;
  306. this._slots.Sort(Armature._OnSortSlots);
  307. }
  308. // Update bones and slots.
  309. if (this._cacheFrameIndex < 0 || this._cacheFrameIndex != prevCacheFrameIndex)
  310. {
  311. int i = 0, l = 0;
  312. for (i = 0, l = this._bones.Count; i < l; ++i)
  313. {
  314. this._bones[i].Update(this._cacheFrameIndex);
  315. }
  316. for (i = 0, l = this._slots.Count; i < l; ++i)
  317. {
  318. this._slots[i].Update(this._cacheFrameIndex);
  319. }
  320. }
  321. if (this._actions.Count > 0)
  322. {
  323. this._lockUpdate = true;
  324. foreach (var action in this._actions)
  325. {
  326. var actionData = action.actionData;
  327. if (actionData != null)
  328. {
  329. if (actionData.type == ActionType.Play)
  330. {
  331. if (action.slot != null)
  332. {
  333. var childArmature = action.slot.childArmature;
  334. if (childArmature != null)
  335. {
  336. childArmature.animation.FadeIn(actionData.name);
  337. }
  338. }
  339. else if (action.bone != null)
  340. {
  341. foreach (var slot in this.GetSlots())
  342. {
  343. if (slot.parent == action.bone)
  344. {
  345. var childArmature = slot.childArmature;
  346. if (childArmature != null)
  347. {
  348. childArmature.animation.FadeIn(actionData.name);
  349. }
  350. }
  351. }
  352. }
  353. else
  354. {
  355. this._animation.FadeIn(actionData.name);
  356. }
  357. }
  358. }
  359. action.ReturnToPool();
  360. }
  361. this._actions.Clear();
  362. this._lockUpdate = false;
  363. }
  364. this._proxy.DBUpdate();
  365. }
  366. /// <summary>
  367. /// - Forces a specific bone or its owning slot to update the transform or display property in the next frame.
  368. /// </summary>
  369. /// <param name="boneName">- The bone name. (If not set, all bones will be update)</param>
  370. /// <param name="updateSlot">- Whether to update the bone's slots. (Default: false)</param>
  371. /// <see cref="DragonBones.Bone.InvalidUpdate()"/>
  372. /// <see cref="DragonBones.Slot.InvalidUpdate()"/>
  373. /// <version>DragonBones 3.0</version>
  374. /// <language>en_US</language>
  375. /// <summary>
  376. /// - 强制特定骨骼或其拥有的插槽在下一帧更新变换或显示属性。
  377. /// </summary>
  378. /// <param name="boneName">- 骨骼名称。 (如果未设置,将更新所有骨骼)</param>
  379. /// <param name="updateSlot">- 是否更新骨骼的插槽。 (默认: false)</param>
  380. /// <see cref="DragonBones.Bone.InvalidUpdate()"/>
  381. /// <see cref="DragonBones.Slot.InvalidUpdate()"/>
  382. /// <version>DragonBones 3.0</version>
  383. /// <language>zh_CN</language>
  384. public void InvalidUpdate(string boneName = null, bool updateSlot = false)
  385. {
  386. if (!string.IsNullOrEmpty(boneName))
  387. {
  388. Bone bone = this.GetBone(boneName);
  389. if (bone != null)
  390. {
  391. bone.InvalidUpdate();
  392. if (updateSlot)
  393. {
  394. foreach (var slot in this._slots)
  395. {
  396. if (slot.parent == bone)
  397. {
  398. slot.InvalidUpdate();
  399. }
  400. }
  401. }
  402. }
  403. }
  404. else
  405. {
  406. foreach (var bone in this._bones)
  407. {
  408. bone.InvalidUpdate();
  409. }
  410. if (updateSlot)
  411. {
  412. foreach (var slot in this._slots)
  413. {
  414. slot.InvalidUpdate();
  415. }
  416. }
  417. }
  418. }
  419. /// <summary>
  420. /// - Check whether a specific point is inside a custom bounding box in a slot.
  421. /// The coordinate system of the point is the inner coordinate system of the armature.
  422. /// Custom bounding boxes need to be customized in Dragonbones Pro.
  423. /// </summary>
  424. /// <param name="x">- The horizontal coordinate of the point.</param>
  425. /// <param name="y">- The vertical coordinate of the point.</param>
  426. /// <version>DragonBones 5.0</version>
  427. /// <language>en_US</language>
  428. /// <summary>
  429. /// - 检查特定点是否在某个插槽的自定义边界框内。
  430. /// 点的坐标系为骨架内坐标系。
  431. /// 自定义边界框需要在 DragonBones Pro 中自定义。
  432. /// </summary>
  433. /// <param name="x">- 点的水平坐标。</param>
  434. /// <param name="y">- 点的垂直坐标。</param>
  435. /// <version>DragonBones 5.0</version>
  436. /// <language>zh_CN</language>
  437. public Slot ContainsPoint(float x, float y)
  438. {
  439. foreach (var slot in this._slots)
  440. {
  441. if (slot.ContainsPoint(x, y))
  442. {
  443. return slot;
  444. }
  445. }
  446. return null;
  447. }
  448. /// <summary>
  449. /// - Check whether a specific segment intersects a custom bounding box for a slot in the armature.
  450. /// The coordinate system of the segment and intersection is the inner coordinate system of the armature.
  451. /// Custom bounding boxes need to be customized in Dragonbones Pro.
  452. /// </summary>
  453. /// <param name="xA">- The horizontal coordinate of the beginning of the segment.</param>
  454. /// <param name="yA">- The vertical coordinate of the beginning of the segment.</param>
  455. /// <param name="xB">- The horizontal coordinate of the end point of the segment.</param>
  456. /// <param name="yB">- The vertical coordinate of the end point of the segment.</param>
  457. /// <param name="intersectionPointA">- The first intersection at which a line segment intersects the bounding box from the beginning to the end. (If not set, the intersection point will not calculated)</param>
  458. /// <param name="intersectionPointB">- The first intersection at which a line segment intersects the bounding box from the end to the beginning. (If not set, the intersection point will not calculated)</param>
  459. /// <param name="normalRadians">- The normal radians of the tangent of the intersection boundary box. [x: Normal radian of the first intersection tangent, y: Normal radian of the second intersection tangent] (If not set, the normal will not calculated)</param>
  460. /// <returns>The slot of the first custom bounding box where the segment intersects from the start point to the end point.</returns>
  461. /// <version>DragonBones 5.0</version>
  462. /// <language>en_US</language>
  463. /// <summary>
  464. /// - 检查特定线段是否与骨架的某个插槽的自定义边界框相交。
  465. /// 线段和交点的坐标系均为骨架内坐标系。
  466. /// 自定义边界框需要在 DragonBones Pro 中自定义。
  467. /// </summary>
  468. /// <param name="xA">- 线段起点的水平坐标。</param>
  469. /// <param name="yA">- 线段起点的垂直坐标。</param>
  470. /// <param name="xB">- 线段终点的水平坐标。</param>
  471. /// <param name="yB">- 线段终点的垂直坐标。</param>
  472. /// <param name="intersectionPointA">- 线段从起点到终点与边界框相交的第一个交点。 (如果未设置,则不计算交点)</param>
  473. /// <param name="intersectionPointB">- 线段从终点到起点与边界框相交的第一个交点。 (如果未设置,则不计算交点)</param>
  474. /// <param name="normalRadians">- 交点边界框切线的法线弧度。 [x: 第一个交点切线的法线弧度, y: 第二个交点切线的法线弧度] (如果未设置,则不计算法线)</param>
  475. /// <returns>线段从起点到终点相交的第一个自定义边界框的插槽。</returns>
  476. /// <version>DragonBones 5.0</version>
  477. /// <language>zh_CN</language>
  478. public Slot IntersectsSegment(float xA, float yA, float xB, float yB,
  479. Point intersectionPointA = null,
  480. Point intersectionPointB = null,
  481. Point normalRadians = null)
  482. {
  483. var isV = xA == xB;
  484. var dMin = 0.0f;
  485. var dMax = 0.0f;
  486. var intXA = 0.0f;
  487. var intYA = 0.0f;
  488. var intXB = 0.0f;
  489. var intYB = 0.0f;
  490. var intAN = 0.0f;
  491. var intBN = 0.0f;
  492. Slot intSlotA = null;
  493. Slot intSlotB = null;
  494. foreach (var slot in this._slots)
  495. {
  496. var intersectionCount = slot.IntersectsSegment(xA, yA, xB, yB, intersectionPointA, intersectionPointB, normalRadians);
  497. if (intersectionCount > 0)
  498. {
  499. if (intersectionPointA != null || intersectionPointB != null)
  500. {
  501. if (intersectionPointA != null)
  502. {
  503. var d = isV ? intersectionPointA.y - yA : intersectionPointA.x - xA;
  504. if (d < 0.0f)
  505. {
  506. d = -d;
  507. }
  508. if (intSlotA == null || d < dMin)
  509. {
  510. dMin = d;
  511. intXA = intersectionPointA.x;
  512. intYA = intersectionPointA.y;
  513. intSlotA = slot;
  514. if (normalRadians != null)
  515. {
  516. intAN = normalRadians.x;
  517. }
  518. }
  519. }
  520. if (intersectionPointB != null)
  521. {
  522. var d = intersectionPointB.x - xA;
  523. if (d < 0.0f)
  524. {
  525. d = -d;
  526. }
  527. if (intSlotB == null || d > dMax)
  528. {
  529. dMax = d;
  530. intXB = intersectionPointB.x;
  531. intYB = intersectionPointB.y;
  532. intSlotB = slot;
  533. if (normalRadians != null)
  534. {
  535. intBN = normalRadians.y;
  536. }
  537. }
  538. }
  539. }
  540. else
  541. {
  542. intSlotA = slot;
  543. break;
  544. }
  545. }
  546. }
  547. if (intSlotA != null && intersectionPointA != null)
  548. {
  549. intersectionPointA.x = intXA;
  550. intersectionPointA.y = intYA;
  551. if (normalRadians != null)
  552. {
  553. normalRadians.x = intAN;
  554. }
  555. }
  556. if (intSlotB != null && intersectionPointB != null)
  557. {
  558. intersectionPointB.x = intXB;
  559. intersectionPointB.y = intYB;
  560. if (normalRadians != null)
  561. {
  562. normalRadians.y = intBN;
  563. }
  564. }
  565. return intSlotA;
  566. }
  567. /// <summary>
  568. /// - Get a specific bone.
  569. /// </summary>
  570. /// <param name="name">- The bone name.</param>
  571. /// <see cref="DragonBones.Bone"/>
  572. /// <version>DragonBones 3.0</version>
  573. /// <language>en_US</language>
  574. /// <summary>
  575. /// - 获取特定的骨骼。
  576. /// </summary>
  577. /// <param name="name">- 骨骼名称。</param>
  578. /// <see cref="DragonBones.Bone"/>
  579. /// <version>DragonBones 3.0</version>
  580. /// <language>zh_CN</language>
  581. public Bone GetBone(string name)
  582. {
  583. foreach (var bone in this._bones)
  584. {
  585. if (bone.name == name)
  586. {
  587. return bone;
  588. }
  589. }
  590. return null;
  591. }
  592. /// <summary>
  593. /// - Get a specific bone by the display.
  594. /// </summary>
  595. /// <param name="display">- The display object.</param>
  596. /// <see cref="DragonBones.Bone"/>
  597. /// <version>DragonBones 3.0</version>
  598. /// <language>en_US</language>
  599. /// <summary>
  600. /// - 通过显示对象获取特定的骨骼。
  601. /// </summary>
  602. /// <param name="display">- 显示对象。</param>
  603. /// <see cref="DragonBones.Bone"/>
  604. /// <version>DragonBones 3.0</version>
  605. /// <language>zh_CN</language>
  606. public Bone GetBoneByDisplay(object display)
  607. {
  608. var slot = this.GetSlotByDisplay(display);
  609. return slot != null ? slot.parent : null;
  610. }
  611. /// <summary>
  612. /// - Get a specific slot.
  613. /// </summary>
  614. /// <param name="name">- The slot name.</param>
  615. /// <see cref="DragonBones.Slot"/>
  616. /// <version>DragonBones 3.0</version>
  617. /// <language>en_US</language>
  618. /// <summary>
  619. /// - 获取特定的插槽。
  620. /// </summary>
  621. /// <param name="name">- 插槽名称。</param>
  622. /// <see cref="DragonBones.Slot"/>
  623. /// <version>DragonBones 3.0</version>
  624. /// <language>zh_CN</language>
  625. public Slot GetSlot(string name)
  626. {
  627. foreach (var slot in this._slots)
  628. {
  629. if (slot.name == name)
  630. {
  631. return slot;
  632. }
  633. }
  634. return null;
  635. }
  636. /// <summary>
  637. /// - Get a specific slot by the display.
  638. /// </summary>
  639. /// <param name="display">- The display object.</param>
  640. /// <see cref="DragonBones.Slot"/>
  641. /// <version>DragonBones 3.0</version>
  642. /// <language>en_US</language>
  643. /// <summary>
  644. /// - 通过显示对象获取特定的插槽。
  645. /// </summary>
  646. /// <param name="display">- 显示对象。</param>
  647. /// <see cref="DragonBones.Slot"/>
  648. /// <version>DragonBones 3.0</version>
  649. /// <language>zh_CN</language>
  650. public Slot GetSlotByDisplay(object display)
  651. {
  652. if (display != null)
  653. {
  654. foreach (var slot in this._slots)
  655. {
  656. if (slot.display == display)
  657. {
  658. return slot;
  659. }
  660. }
  661. }
  662. return null;
  663. }
  664. /// <summary>
  665. /// - Get all bones.
  666. /// </summary>
  667. /// <see cref="DragonBones.Bone"/>
  668. /// <version>DragonBones 3.0</version>
  669. /// <language>en_US</language>
  670. /// <summary>
  671. /// - 获取所有的骨骼。
  672. /// </summary>
  673. /// <see cref="DragonBones.Bone"/>
  674. /// <version>DragonBones 3.0</version>
  675. /// <language>zh_CN</language>
  676. public List<Bone> GetBones()
  677. {
  678. return this._bones;
  679. }
  680. /// <summary>
  681. /// - Get all slots.
  682. /// </summary>
  683. /// <see cref="DragonBones.Slot"/>
  684. /// <version>DragonBones 3.0</version>
  685. /// <language>en_US</language>
  686. /// <summary>
  687. /// - 获取所有的插槽。
  688. /// </summary>
  689. /// <see cref="DragonBones.Slot"/>
  690. /// <version>DragonBones 3.0</version>
  691. /// <language>zh_CN</language>
  692. public List<Slot> GetSlots()
  693. {
  694. return this._slots;
  695. }
  696. /// <summary>
  697. /// - Whether to flip the armature horizontally.
  698. /// </summary>
  699. /// <version>DragonBones 5.5</version>
  700. /// <language>en_US</language>
  701. /// <summary>
  702. /// - 是否将骨架水平翻转。
  703. /// </summary>
  704. /// <version>DragonBones 5.5</version>
  705. /// <language>zh_CN</language>
  706. public bool flipX
  707. {
  708. get { return this._flipX; }
  709. set
  710. {
  711. if (this._flipX == value)
  712. {
  713. return;
  714. }
  715. this._flipX = value;
  716. this.InvalidUpdate();
  717. }
  718. }
  719. /// <summary>
  720. /// - Whether to flip the armature vertically.
  721. /// </summary>
  722. /// <version>DragonBones 5.5</version>
  723. /// <language>en_US</language>
  724. /// <summary>
  725. /// - 是否将骨架垂直翻转。
  726. /// </summary>
  727. /// <version>DragonBones 5.5</version>
  728. /// <language>zh_CN</language>
  729. public bool flipY
  730. {
  731. get { return this._flipY; }
  732. set
  733. {
  734. if (this._flipY == value)
  735. {
  736. return;
  737. }
  738. this._flipY = value;
  739. this.InvalidUpdate();
  740. }
  741. }
  742. /// <summary>
  743. /// - The animation cache frame rate, which turns on the animation cache when the set value is greater than 0.
  744. /// There is a certain amount of memory overhead to improve performance by caching animation data in memory.
  745. /// The frame rate should not be set too high, usually with the frame rate of the animation is similar and lower than the program running frame rate.
  746. /// When the animation cache is turned on, some features will fail, such as the offset property of bone.
  747. /// </summary>
  748. /// <example>
  749. /// TypeScript style, for reference only.
  750. /// <pre>
  751. /// armature.cacheFrameRate = 24;
  752. /// </pre>
  753. /// </example>
  754. /// <see cref="DragonBones.DragonBonesData.frameRate"/>
  755. /// <see cref="DragonBones.ArmatureData.frameRate"/>
  756. /// <version>DragonBones 4.5</version>
  757. /// <language>en_US</language>
  758. /// <summary>
  759. /// - 动画缓存帧率,当设置的值大于 0 的时,将会开启动画缓存。
  760. /// 通过将动画数据缓存在内存中来提高运行性能,会有一定的内存开销。
  761. /// 帧率不宜设置的过高,通常跟动画的帧率相当且低于程序运行的帧率。
  762. /// 开启动画缓存后,某些功能将会失效,比如骨骼的 offset 属性等。
  763. /// </summary>
  764. /// <example>
  765. /// TypeScript 风格,仅供参考。
  766. /// <pre>
  767. /// armature.cacheFrameRate = 24;
  768. /// </pre>
  769. /// </example>
  770. /// <see cref="DragonBones.DragonBonesData.frameRate"/>
  771. /// <see cref="DragonBones.ArmatureData.frameRate"/>
  772. /// <version>DragonBones 4.5</version>
  773. /// <language>zh_CN</language>
  774. public uint cacheFrameRate
  775. {
  776. get { return this._armatureData.cacheFrameRate; }
  777. set
  778. {
  779. if (this._armatureData.cacheFrameRate != value)
  780. {
  781. this._armatureData.CacheFrames(value);
  782. // Set child armature frameRate.
  783. foreach (var slot in this._slots)
  784. {
  785. var childArmature = slot.childArmature;
  786. if (childArmature != null)
  787. {
  788. childArmature.cacheFrameRate = value;
  789. }
  790. }
  791. }
  792. }
  793. }
  794. /// <summary>
  795. /// - The armature name.
  796. /// </summary>
  797. /// <version>DragonBones 3.0</version>
  798. /// <language>en_US</language>
  799. /// <summary>
  800. /// - 骨架名称。
  801. /// </summary>
  802. /// <version>DragonBones 3.0</version>
  803. /// <language>zh_CN</language>
  804. public string name
  805. {
  806. get { return this._armatureData.name; }
  807. }
  808. /// <summary>
  809. /// - The armature data.
  810. /// </summary>
  811. /// <see cref="DragonBones.ArmatureData"/>
  812. /// <version>DragonBones 4.5</version>
  813. /// <language>en_US</language>
  814. /// <summary>
  815. /// - 骨架数据。
  816. /// </summary>
  817. /// <see cref="DragonBones.ArmatureData"/>
  818. /// <version>DragonBones 4.5</version>
  819. /// <language>zh_CN</language>
  820. public ArmatureData armatureData
  821. {
  822. get { return this._armatureData; }
  823. }
  824. /// <summary>
  825. /// - The animation player.
  826. /// </summary>
  827. /// <see cref="DragonBones.Animation"/>
  828. /// <version>DragonBones 3.0</version>
  829. /// <language>en_US</language>
  830. /// <summary>
  831. /// - 动画播放器。
  832. /// </summary>
  833. /// <see cref="DragonBones.Animation"/>
  834. /// <version>DragonBones 3.0</version>
  835. /// <language>zh_CN</language>
  836. public AnimationDB animation
  837. {
  838. get { return this._animation; }
  839. }
  840. /// <pivate/>
  841. public IArmatureProxy proxy
  842. {
  843. get { return this._proxy; }
  844. }
  845. /// <summary>
  846. /// - The EventDispatcher instance of the armature.
  847. /// </summary>
  848. /// <version>DragonBones 4.5</version>
  849. /// <language>en_US</language>
  850. /// <summary>
  851. /// - 该骨架的 EventDispatcher 实例。
  852. /// </summary>
  853. /// <version>DragonBones 4.5</version>
  854. /// <language>zh_CN</language>
  855. public IEventDispatcher<EventObject> eventDispatcher
  856. {
  857. get { return this._proxy; }
  858. }
  859. /// <summary>
  860. /// - The display container.
  861. /// The display of the slot is displayed as the parent.
  862. /// Depending on the rendering engine, the type will be different, usually the DisplayObjectContainer type.
  863. /// </summary>
  864. /// <version>DragonBones 3.0</version>
  865. /// <language>en_US</language>
  866. /// <summary>
  867. /// - 显示容器实例。
  868. /// 插槽的显示对象都会以此显示容器为父级。
  869. /// 根据渲染引擎的不同,类型会不同,通常是 DisplayObjectContainer 类型。
  870. /// </summary>
  871. /// <version>DragonBones 3.0</version>
  872. /// <language>zh_CN</language>
  873. public object display
  874. {
  875. get { return this._display; }
  876. }
  877. /// <private/>
  878. public object replacedTexture
  879. {
  880. get { return this._replacedTexture; }
  881. set
  882. {
  883. if (this._replacedTexture == value)
  884. {
  885. return;
  886. }
  887. if (this._replaceTextureAtlasData != null)
  888. {
  889. this._replaceTextureAtlasData.ReturnToPool();
  890. this._replaceTextureAtlasData = null;
  891. }
  892. this._replacedTexture = value;
  893. foreach (var slot in this._slots)
  894. {
  895. slot.InvalidUpdate();
  896. slot.Update(-1);
  897. }
  898. }
  899. }
  900. /// <inheritDoc/>
  901. public WorldClock clock
  902. {
  903. get { return this._clock; }
  904. set
  905. {
  906. if (this._clock == value)
  907. {
  908. return;
  909. }
  910. if (this._clock != null)
  911. {
  912. this._clock.Remove(this);
  913. }
  914. this._clock = value;
  915. if (this._clock != null)
  916. {
  917. this._clock.Add(this);
  918. }
  919. // Update childArmature clock.
  920. foreach (var slot in this._slots)
  921. {
  922. var childArmature = slot.childArmature;
  923. if (childArmature != null)
  924. {
  925. childArmature.clock = this._clock;
  926. }
  927. }
  928. }
  929. }
  930. /// <summary>
  931. /// - Get the parent slot which the armature belongs to.
  932. /// </summary>
  933. /// <see cref="DragonBones.Slot"/>
  934. /// <version>DragonBones 4.5</version>
  935. /// <language>en_US</language>
  936. /// <summary>
  937. /// - 该骨架所属的父插槽。
  938. /// </summary>
  939. /// <see cref="DragonBones.Slot"/>
  940. /// <version>DragonBones 4.5</version>
  941. /// <language>zh_CN</language>
  942. public Slot parent
  943. {
  944. get { return this._parent; }
  945. }
  946. }
  947. }