Armature.cs 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. using System.Collections.Generic;
  2. namespace DragonBones
  3. {
  4. /**
  5. * @language zh_CN
  6. * 骨架,是骨骼动画系统的核心,由显示容器、骨骼、插槽、动画、事件系统构成。
  7. * @see DragonBones.ArmatureData
  8. * @see DragonBones.Bone
  9. * @see DragonBones.Slot
  10. * @see DragonBones.Animation
  11. * @see DragonBones.IArmatureDisplay
  12. * @version DragonBones 3.0
  13. */
  14. public class Armature : BaseObject, IAnimateble
  15. {
  16. private static int _onSortSlots(Slot a, Slot b)
  17. {
  18. return a._zOrder > b._zOrder ? 1 : -1;
  19. }
  20. /**
  21. * @language zh_CN
  22. * 子骨架是否继承父骨架的动画。 [true: 继承, false: 不继承]
  23. * @default true
  24. * @version DragonBones 4.5
  25. */
  26. public bool inheritAnimation;
  27. /**
  28. * @language zh_CN
  29. * 可以用于存储临时数据。
  30. * @version DragonBones 3.0
  31. */
  32. public object userData;
  33. private bool _delayDispose;
  34. private bool _lockDispose;
  35. /**
  36. * @private
  37. */
  38. internal bool _bonesDirty;
  39. private bool _slotsDirty;
  40. private bool _zOrderDirty;
  41. /**
  42. * @private
  43. */
  44. internal bool _flipX;
  45. /**
  46. * @private
  47. */
  48. internal bool _flipY;
  49. private readonly List<Bone> _bones = new List<Bone>();
  50. private readonly List<Slot> _slots = new List<Slot>();
  51. private readonly List<ActionData> _actions = new List<ActionData>();
  52. private readonly List<EventObject> _events = new List<EventObject>();
  53. /**
  54. * @private
  55. */
  56. internal ArmatureData _armatureData;
  57. /**
  58. * @private
  59. */
  60. internal SkinData _skinData;
  61. private Animation _animation;
  62. private IArmatureProxy _proxy;
  63. private object _display;
  64. private IEventDispatcher<EventObject> _eventManager;
  65. /**
  66. * @private
  67. */
  68. internal Slot _parent;
  69. private WorldClock _clock;
  70. /**
  71. * @private
  72. */
  73. internal TextureAtlasData _replaceTextureAtlasData;
  74. private object _replacedTexture;
  75. /**
  76. * @private
  77. */
  78. public Armature()
  79. {
  80. }
  81. /**
  82. * @private
  83. */
  84. protected override void _onClear()
  85. {
  86. foreach (var bone in _bones)
  87. {
  88. bone.ReturnToPool();
  89. }
  90. foreach (var slot in _slots)
  91. {
  92. slot.ReturnToPool();
  93. }
  94. foreach (var evt in _events)
  95. {
  96. evt.ReturnToPool();
  97. }
  98. if (_clock != null)
  99. {
  100. _clock.Remove(this);
  101. }
  102. if (_proxy != null)
  103. {
  104. _proxy._onClear();
  105. }
  106. if (_replaceTextureAtlasData != null)
  107. {
  108. _replaceTextureAtlasData.ReturnToPool();
  109. }
  110. if (_animation != null)
  111. {
  112. _animation.ReturnToPool();
  113. }
  114. inheritAnimation = true;
  115. userData = null;
  116. _delayDispose = false;
  117. _lockDispose = false;
  118. _bonesDirty = false;
  119. _slotsDirty = false;
  120. _zOrderDirty = false;
  121. _flipX = false;
  122. _flipY = false;
  123. _bones.Clear();
  124. _slots.Clear();
  125. _actions.Clear();
  126. _events.Clear();
  127. _armatureData = null;
  128. _skinData = null;
  129. _animation = null;
  130. _proxy = null;
  131. _display = null;
  132. _eventManager = null;
  133. _parent = null;
  134. _clock = null;
  135. _replaceTextureAtlasData = null;
  136. _replacedTexture = null;
  137. }
  138. private void _sortBones()
  139. {
  140. var total = _bones.Count;
  141. if (total <= 0)
  142. {
  143. return;
  144. }
  145. var sortHelper = _bones.ToArray();
  146. int index = 0;
  147. int count = 0;
  148. _bones.Clear();
  149. while (count < total)
  150. {
  151. var bone = sortHelper[index++];
  152. if (index >= total)
  153. {
  154. index = 0;
  155. }
  156. if (_bones.Contains(bone))
  157. {
  158. continue;
  159. }
  160. if (bone.parent != null && !_bones.Contains(bone.parent))
  161. {
  162. continue;
  163. }
  164. if (bone.ik != null && !_bones.Contains(bone.ik))
  165. {
  166. continue;
  167. }
  168. if (bone.ik != null && bone.ikChain > 0 && bone.ikChainIndex == bone.ikChain)
  169. {
  170. _bones.Insert(_bones.IndexOf(bone.parent) + 1, bone); // ik, parent, bone, children
  171. }
  172. else
  173. {
  174. _bones.Add(bone);
  175. }
  176. count++;
  177. }
  178. }
  179. private void _sortSlots()
  180. {
  181. _slots.Sort(_onSortSlots);
  182. }
  183. private void _doAction(ActionData value)
  184. {
  185. switch (value.type)
  186. {
  187. case ActionType.Play:
  188. _animation.PlayConfig(value.animationConfig);
  189. break;
  190. default:
  191. break;
  192. }
  193. }
  194. /**
  195. * @private
  196. */
  197. internal void _init(
  198. ArmatureData armatureData, SkinData skinData,
  199. object display, IArmatureProxy proxy, IEventDispatcher<EventObject> eventManager
  200. )
  201. {
  202. if (_armatureData != null)
  203. {
  204. return;
  205. }
  206. _armatureData = armatureData;
  207. _skinData = skinData;
  208. _animation = BaseObject.BorrowObject<Animation>();
  209. _display = display;
  210. _proxy = proxy;
  211. _eventManager = eventManager;
  212. _animation._init(this);
  213. _animation.animations = _armatureData.animations;
  214. }
  215. /**
  216. * @private
  217. */
  218. internal void _addBoneToBoneList(Bone value)
  219. {
  220. if (!_bones.Contains(value))
  221. {
  222. _bonesDirty = true;
  223. _bones.Add(value);
  224. _animation._timelineStateDirty = true;
  225. }
  226. }
  227. /**
  228. * @private
  229. */
  230. internal void _removeBoneFromBoneList(Bone value)
  231. {
  232. if (_bones.Contains(value))
  233. {
  234. _bones.Remove(value);
  235. _animation._timelineStateDirty = true;
  236. }
  237. }
  238. /**
  239. * @private
  240. */
  241. internal void _addSlotToSlotList(Slot value)
  242. {
  243. if (!_slots.Contains(value))
  244. {
  245. _slotsDirty = true;
  246. _slots.Add(value);
  247. _animation._timelineStateDirty = true;
  248. }
  249. }
  250. /**
  251. * @private
  252. */
  253. internal void _removeSlotFromSlotList(Slot value)
  254. {
  255. if (_slots.Contains(value))
  256. {
  257. _slots.Remove(value);
  258. _animation._timelineStateDirty = true;
  259. }
  260. }
  261. /**
  262. * @private
  263. */
  264. public void _sortZOrder(List<int> slotIndices)
  265. {
  266. var sortedSlots = _armatureData.sortedSlots;
  267. var isOriginal = slotIndices == null || slotIndices.Count < 1;
  268. if (_zOrderDirty || !isOriginal)
  269. {
  270. for (int i = 0, l = sortedSlots.Count; i < l; ++i)
  271. {
  272. var slotIndex = isOriginal ? i : slotIndices[i];
  273. var slotData = sortedSlots[slotIndex];
  274. if (slotData != null)
  275. {
  276. var slot = GetSlot(slotData.name);
  277. if (slot != null)
  278. {
  279. slot._setZorder(i);
  280. }
  281. }
  282. }
  283. _slotsDirty = true;
  284. _zOrderDirty = !isOriginal;
  285. }
  286. }
  287. /**
  288. * @private
  289. */
  290. internal void _bufferAction(ActionData value)
  291. {
  292. _actions.Add(value);
  293. }
  294. /**
  295. * @private
  296. */
  297. internal void _bufferEvent(EventObject value, string type)
  298. {
  299. value.type = type;
  300. value.armature = this;
  301. _events.Add(value);
  302. }
  303. /**
  304. * @language zh_CN
  305. * 释放骨架。 (回收到对象池)
  306. * @version DragonBones 3.0
  307. */
  308. public void Dispose()
  309. {
  310. if (_armatureData != null)
  311. {
  312. if (_lockDispose)
  313. {
  314. _delayDispose = true;
  315. }
  316. else
  317. {
  318. ReturnToPool();
  319. }
  320. }
  321. }
  322. /**
  323. * @language zh_CN
  324. * 更新骨架和动画。
  325. * @param passedTime 两帧之间的时间间隔。 (以秒为单位)
  326. * @see DragonBones.IAnimateble
  327. * @see DragonBones.WorldClock
  328. * @version DragonBones 3.0
  329. */
  330. public void AdvanceTime(float passedTime)
  331. {
  332. if (_armatureData == null)
  333. {
  334. DragonBones.Assert(false, "The armature has been disposed.");
  335. return;
  336. }
  337. else if (_armatureData.parent == null)
  338. {
  339. DragonBones.Assert(false, "The armature data has been disposed.");
  340. return;
  341. }
  342. // Bones and slots.
  343. if (_bonesDirty)
  344. {
  345. _bonesDirty = false;
  346. _sortBones();
  347. }
  348. if (_slotsDirty)
  349. {
  350. _slotsDirty = false;
  351. _sortSlots();
  352. }
  353. var prevCacheFrameIndex = _animation._cacheFrameIndex;
  354. // Update animations.
  355. _animation._advanceTime(passedTime);
  356. var currentCacheFrameIndex = _animation._cacheFrameIndex;
  357. int i = 0, l = 0;
  358. if (currentCacheFrameIndex < 0 || currentCacheFrameIndex != prevCacheFrameIndex)
  359. {
  360. // Update bones.
  361. for (i = 0, l = _bones.Count; i < l; ++i)
  362. {
  363. var bone = _bones[i];
  364. bone._update(currentCacheFrameIndex);
  365. }
  366. // Update slots.
  367. for (i = 0, l = _slots.Count; i < l; ++i)
  368. {
  369. _slots[i]._update(currentCacheFrameIndex);
  370. }
  371. }
  372. //
  373. if (!_lockDispose)
  374. {
  375. _lockDispose = true;
  376. // Events. (Dispatch event before action.)
  377. l = _events.Count;
  378. if (l > 0)
  379. {
  380. for (i = 0; i < l; ++i)
  381. {
  382. var eventObject = _events[i];
  383. _proxy.DispatchEvent(eventObject.type, eventObject);
  384. if (eventObject.type == EventObject.SOUND_EVENT)
  385. {
  386. _eventManager.DispatchEvent(eventObject.type, eventObject);
  387. }
  388. eventObject.ReturnToPool();
  389. }
  390. _events.Clear();
  391. }
  392. // Actions.
  393. l = _actions.Count;
  394. if (l > 0)
  395. {
  396. for (i = 0; i < l; ++i)
  397. {
  398. var action = _actions[i];
  399. if (action.slot != null)
  400. {
  401. var slot = GetSlot(action.slot.name);
  402. if (slot != null)
  403. {
  404. var childArmature = slot.childArmature;
  405. if (childArmature != null)
  406. {
  407. childArmature._doAction(action);
  408. }
  409. }
  410. }
  411. else if (action.bone != null)
  412. {
  413. for (int iA = 0, lA = _slots.Count; iA < lA; ++iA)
  414. {
  415. var childArmature = _slots[iA].childArmature;
  416. if (childArmature != null)
  417. {
  418. childArmature._doAction(action);
  419. }
  420. }
  421. }
  422. else
  423. {
  424. _doAction(action);
  425. }
  426. }
  427. _actions.Clear();
  428. }
  429. _lockDispose = false;
  430. }
  431. if (_delayDispose)
  432. {
  433. ReturnToPool();
  434. }
  435. }
  436. /**
  437. * @language zh_CN
  438. * 更新骨骼和插槽。 (当骨骼没有动画状态或动画状态播放完成时,骨骼将不在更新)
  439. * @param boneName 指定的骨骼名称,如果未设置,将更新所有骨骼。
  440. * @param updateSlotDisplay 是否更新插槽的显示对象。
  441. * @see DragonBones.Bone
  442. * @see DragonBones.Slot
  443. * @version DragonBones 3.0
  444. */
  445. public void InvalidUpdate(string boneName = null, bool updateSlotDisplay = false)
  446. {
  447. if (!string.IsNullOrEmpty(boneName))
  448. {
  449. var bone = GetBone(boneName);
  450. if (bone != null)
  451. {
  452. bone.InvalidUpdate();
  453. if (updateSlotDisplay)
  454. {
  455. for (int i = 0, l = _slots.Count; i < l; ++i)
  456. {
  457. var slot = _slots[i];
  458. if (slot.parent == bone)
  459. {
  460. slot.InvalidUpdate();
  461. }
  462. }
  463. }
  464. }
  465. }
  466. else
  467. {
  468. for (int i = 0, l = _bones.Count; i < l; ++i)
  469. {
  470. _bones[i].InvalidUpdate();
  471. }
  472. if (updateSlotDisplay)
  473. {
  474. for (int i = 0, l = _slots.Count; i < l; ++i)
  475. {
  476. _slots[i].InvalidUpdate();
  477. }
  478. }
  479. }
  480. }
  481. /**
  482. * @language zh_CN
  483. * 判断点是否在所有插槽的自定义包围盒内。
  484. * @param x 点的水平坐标。(骨架内坐标系)
  485. * @param y 点的垂直坐标。(骨架内坐标系)
  486. * @version DragonBones 5.0
  487. */
  488. public Slot ContainsPoint(float x, float y)
  489. {
  490. for (int i = 0, l = _slots.Count; i < l; ++i)
  491. {
  492. var slot = _slots[i];
  493. if (slot.ContainsPoint(x, y))
  494. {
  495. return slot;
  496. }
  497. }
  498. return null;
  499. }
  500. /**
  501. * @language zh_CN
  502. * 判断线段是否与骨架的所有插槽的自定义包围盒相交。
  503. * @param xA 线段起点的水平坐标。(骨架内坐标系)
  504. * @param yA 线段起点的垂直坐标。(骨架内坐标系)
  505. * @param xB 线段终点的水平坐标。(骨架内坐标系)
  506. * @param yB 线段终点的垂直坐标。(骨架内坐标系)
  507. * @param intersectionPointA 线段从起点到终点与包围盒相交的第一个交点。(骨架内坐标系)
  508. * @param intersectionPointB 线段从终点到起点与包围盒相交的第一个交点。(骨架内坐标系)
  509. * @param normalRadians 碰撞点处包围盒切线的法线弧度。 [x: 第一个碰撞点处切线的法线弧度, y: 第二个碰撞点处切线的法线弧度]
  510. * @returns 线段从起点到终点相交的第一个自定义包围盒的插槽。
  511. * @version DragonBones 5.0
  512. */
  513. public Slot intersectsSegment(
  514. float xA, float yA, float xB, float yB,
  515. Point intersectionPointA = null,
  516. Point intersectionPointB = null,
  517. Point normalRadians = null
  518. )
  519. {
  520. var isV = xA == xB;
  521. var dMin = 0.0f;
  522. var dMax = 0.0f;
  523. var intXA = 0.0f;
  524. var intYA = 0.0f;
  525. var intXB = 0.0f;
  526. var intYB = 0.0f;
  527. var intAN = 0.0f;
  528. var intBN = 0.0f;
  529. Slot intSlotA = null;
  530. Slot intSlotB = null;
  531. for (int i = 0, l = _slots.Count; i < l; ++i)
  532. {
  533. var slot = _slots[i];
  534. var intersectionCount = slot.IntersectsSegment(xA, yA, xB, yB, intersectionPointA, intersectionPointB, normalRadians);
  535. if (intersectionCount > 0)
  536. {
  537. if (intersectionPointA != null || intersectionPointB != null)
  538. {
  539. if (intersectionPointA != null)
  540. {
  541. var d = isV ? intersectionPointA.y - yA : intersectionPointA.x - xA;
  542. if (d < 0.0f)
  543. {
  544. d = -d;
  545. }
  546. if (intSlotA == null || d < dMin)
  547. {
  548. dMin = d;
  549. intXA = intersectionPointA.x;
  550. intYA = intersectionPointA.y;
  551. intSlotA = slot;
  552. if (normalRadians != null)
  553. {
  554. intAN = normalRadians.x;
  555. }
  556. }
  557. }
  558. if (intersectionPointB != null)
  559. {
  560. var d = intersectionPointB.x - xA;
  561. if (d < 0.0f)
  562. {
  563. d = -d;
  564. }
  565. if (intSlotB == null || d > dMax)
  566. {
  567. dMax = d;
  568. intXB = intersectionPointB.x;
  569. intYB = intersectionPointB.y;
  570. intSlotB = slot;
  571. if (normalRadians != null)
  572. {
  573. intBN = normalRadians.y;
  574. }
  575. }
  576. }
  577. }
  578. else
  579. {
  580. intSlotA = slot;
  581. break;
  582. }
  583. }
  584. }
  585. if (intSlotA != null && intersectionPointA != null)
  586. {
  587. intersectionPointA.x = intXA;
  588. intersectionPointA.y = intYA;
  589. if (normalRadians != null)
  590. {
  591. normalRadians.x = intAN;
  592. }
  593. }
  594. if (intSlotB != null && intersectionPointB != null)
  595. {
  596. intersectionPointB.x = intXB;
  597. intersectionPointB.y = intYB;
  598. if (normalRadians != null)
  599. {
  600. normalRadians.y = intBN;
  601. }
  602. }
  603. return intSlotA;
  604. }
  605. /**
  606. * @language zh_CN
  607. * 获取骨骼。
  608. * @param name 骨骼的名称。
  609. * @returns 骨骼。
  610. * @see DragonBones.Bone
  611. * @version DragonBones 3.0
  612. */
  613. public Bone GetBone(string name)
  614. {
  615. foreach (var bone in _bones)
  616. {
  617. if (bone.name == name)
  618. {
  619. return bone;
  620. }
  621. }
  622. return null;
  623. }
  624. /**
  625. * @language zh_CN
  626. * 通过显示对象获取骨骼。
  627. * @param display 显示对象。
  628. * @returns 包含这个显示对象的骨骼。
  629. * @see DragonBones.Bone
  630. * @version DragonBones 3.0
  631. */
  632. public Bone GetBoneByDisplay(object display)
  633. {
  634. var slot = GetSlotByDisplay(display);
  635. return slot != null ? slot.parent : null;
  636. }
  637. /**
  638. * @language zh_CN
  639. * 获取插槽。
  640. * @param name 插槽的名称。
  641. * @returns 插槽。
  642. * @see DragonBones.Slot
  643. * @version DragonBones 3.0
  644. */
  645. public Slot GetSlot(string name)
  646. {
  647. foreach (var slot in _slots)
  648. {
  649. if (slot.name == name)
  650. {
  651. return slot;
  652. }
  653. }
  654. return null;
  655. }
  656. /**
  657. * @language zh_CN
  658. * 通过显示对象获取插槽。
  659. * @param display 显示对象。
  660. * @returns 包含这个显示对象的插槽。
  661. * @see DragonBones.Slot
  662. * @version DragonBones 3.0
  663. */
  664. public Slot GetSlotByDisplay(object display)
  665. {
  666. if (display != null)
  667. {
  668. foreach (var slot in _slots)
  669. {
  670. if (slot.display == display)
  671. {
  672. return slot;
  673. }
  674. }
  675. }
  676. return null;
  677. }
  678. /**
  679. * @deprecated
  680. */
  681. public void AddBone(Bone value, string parentName = null)
  682. {
  683. if (value != null)
  684. {
  685. value._setArmature(this);
  686. value._setParent(!string.IsNullOrEmpty(parentName) ? GetBone(parentName) : null);
  687. }
  688. else
  689. {
  690. DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
  691. }
  692. }
  693. /**
  694. * @deprecated
  695. */
  696. public void AddSlot(Slot value, string parentName)
  697. {
  698. var bone = GetBone(parentName);
  699. if (bone != null)
  700. {
  701. value._setArmature(this);
  702. value._setParent(bone);
  703. }
  704. else
  705. {
  706. DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
  707. }
  708. }
  709. /**
  710. * @language zh_CN
  711. * 替换骨架的主贴图,根据渲染引擎的不同,提供不同的贴图类型。
  712. * @param texture 贴图。
  713. * @version DragonBones 4.5
  714. */
  715. public void ReplaceTexture(object texture)
  716. {
  717. replacedTexture = texture;
  718. }
  719. /**
  720. * @language zh_CN
  721. * 获取所有骨骼。
  722. * @see DragonBones.Bone
  723. * @version DragonBones 3.0
  724. */
  725. public List<Bone> GetBones()
  726. {
  727. return _bones;
  728. }
  729. /**
  730. * @language zh_CN
  731. * 获取所有插槽。
  732. * @see DragonBones.Slot
  733. * @version DragonBones 3.0
  734. */
  735. public List<Slot> GetSlots()
  736. {
  737. return _slots;
  738. }
  739. /**
  740. * @language zh_CN
  741. * 骨架名称。
  742. * @see DragonBones.ArmatureData#name
  743. * @version DragonBones 3.0
  744. */
  745. public string name
  746. {
  747. get { return _armatureData != null ? _armatureData.name : null; }
  748. }
  749. /**
  750. * @language zh_CN
  751. * 获取骨架数据。
  752. * @see DragonBones.ArmatureData
  753. * @version DragonBones 4.5
  754. */
  755. public ArmatureData armatureData
  756. {
  757. get { return _armatureData; }
  758. }
  759. /**
  760. * @language zh_CN
  761. * 获得动画控制器。
  762. * @see DragonBones.Animation
  763. * @version DragonBones 3.0
  764. */
  765. public Animation animation
  766. {
  767. get { return _animation; }
  768. }
  769. /**
  770. * @language zh_CN
  771. * 获取事件监听器。
  772. * @version DragonBones 3.0
  773. */
  774. public IEventDispatcher<EventObject> eventDispatcher
  775. {
  776. get { return _proxy; }
  777. }
  778. /**
  779. * @language zh_CN
  780. * 获取显示容器,插槽的显示对象都会以此显示容器为父级,根据渲染平台的不同,类型会不同,通常是 DisplayObjectContainer 类型。
  781. * @version DragonBones 3.0
  782. */
  783. public object display
  784. {
  785. get { return _display; }
  786. }
  787. /**
  788. * @language zh_CN
  789. * 获取父插槽。 (当此骨架是某个骨架的子骨架时,可以通过此属性向上查找从属关系)
  790. * @see DragonBones.Slot
  791. * @version DragonBones 4.5
  792. */
  793. public Slot parent
  794. {
  795. get { return _parent; }
  796. }
  797. /**
  798. * @language zh_CN
  799. * 动画缓存帧率,当设置的值大于 0 的时,将会开启动画缓存。
  800. * 通过将动画数据缓存在内存中来提高运行性能,会有一定的内存开销。
  801. * 帧率不宜设置的过高,通常跟动画的帧率相当且低于程序运行的帧率。
  802. * 开启动画缓存后,某些功能将会失效,比如 Bone 和 Slot 的 offset 属性等。
  803. * @see DragonBones.DragonBonesData#frameRate
  804. * @see DragonBones.ArmatureData#frameRate
  805. * @version DragonBones 4.5
  806. */
  807. public uint cacheFrameRate
  808. {
  809. get { return _armatureData.cacheFrameRate; }
  810. set
  811. {
  812. if (_armatureData.cacheFrameRate != value)
  813. {
  814. _armatureData.CacheFrames(value);
  815. // Set child armature frameRate.
  816. foreach (var slot in _slots)
  817. {
  818. var childArmature = slot.childArmature;
  819. if (childArmature != null && childArmature.cacheFrameRate == 0)
  820. {
  821. childArmature.cacheFrameRate = value;
  822. }
  823. }
  824. }
  825. }
  826. }
  827. /**
  828. * @inheritDoc
  829. */
  830. public WorldClock clock
  831. {
  832. get { return _clock; }
  833. set
  834. {
  835. if (_clock == value)
  836. {
  837. return;
  838. }
  839. var prevClock = _clock;
  840. _clock = value;
  841. if (prevClock != null)
  842. {
  843. prevClock.Remove(this);
  844. }
  845. if (_clock != null)
  846. {
  847. _clock.Add(this);
  848. }
  849. // Update childArmature clock.
  850. for (int i = 0, l = _slots.Count; i < l; ++i)
  851. {
  852. var childArmature = _slots[i].childArmature;
  853. if (childArmature != null)
  854. {
  855. childArmature.clock = _clock;
  856. }
  857. }
  858. }
  859. }
  860. /**
  861. * @language zh_CN
  862. * 替换骨架的主贴图,根据渲染引擎的不同,提供不同的贴图数据。
  863. * @version DragonBones 4.5
  864. */
  865. public object replacedTexture
  866. {
  867. get { return _replacedTexture; }
  868. set
  869. {
  870. if (_replacedTexture == value)
  871. {
  872. return;
  873. }
  874. if (_replaceTextureAtlasData != null)
  875. {
  876. _replaceTextureAtlasData.ReturnToPool();
  877. _replaceTextureAtlasData = null;
  878. }
  879. _replacedTexture = value;
  880. for (int i = 0, l = _slots.Count; i < l; ++i)
  881. {
  882. var slot = _slots[i];
  883. slot.InvalidUpdate();
  884. slot._update(-1);
  885. }
  886. }
  887. }
  888. public bool flipX
  889. {
  890. get { return _flipX; }
  891. set
  892. {
  893. if (_flipX == value)
  894. {
  895. return;
  896. }
  897. _flipX = value;
  898. // Flipping child armature.
  899. foreach (var slot in _slots)
  900. {
  901. var childArmature = slot.childArmature;
  902. if (childArmature != null)
  903. {
  904. childArmature.flipX = _flipX;
  905. }
  906. }
  907. InvalidUpdate();
  908. }
  909. }
  910. public bool flipY
  911. {
  912. get { return _flipY; }
  913. set
  914. {
  915. if (_flipY == value)
  916. {
  917. return;
  918. }
  919. _flipY = value;
  920. // Flipping child armature.
  921. foreach (var slot in _slots)
  922. {
  923. var childArmature = slot.childArmature;
  924. if (childArmature != null)
  925. {
  926. childArmature.flipY = _flipY;
  927. }
  928. }
  929. InvalidUpdate();
  930. }
  931. }
  932. }
  933. }