BaseFactory.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. using System.Collections.Generic;
  2. namespace DragonBones
  3. {
  4. /**
  5. * @private
  6. */
  7. public class BuildArmaturePackage
  8. {
  9. public string dataName = null;
  10. public string textureAtlasName = null;
  11. public DragonBonesData data = null;
  12. public ArmatureData armature = null;
  13. public SkinData skin = null;
  14. }
  15. /**
  16. * @language zh_CN
  17. * 创建骨架的基础工厂。 (通常只需要一个全局工厂实例)
  18. * @see DragonBones.DragonBonesData
  19. * @see DragonBones.TextureAtlasData
  20. * @see DragonBones.ArmatureData
  21. * @see DragonBones.Armature
  22. * @version DragonBones 3.0
  23. */
  24. public abstract class BaseFactory
  25. {
  26. protected static readonly ObjectDataParser _defaultDataParser = new ObjectDataParser();
  27. /**
  28. * @language zh_CN
  29. * 是否开启共享搜索。
  30. * 如果开启,创建一个骨架时,可以从多个龙骨数据中寻找骨架数据,或贴图集数据中寻找贴图数据。 (通常在有共享导出的数据时开启)
  31. * @see DragonBones.DragonBonesData#autoSearch
  32. * @see DragonBones.TextureAtlasData#autoSearch
  33. * @version DragonBones 4.5
  34. */
  35. public bool autoSearch = false;
  36. /**
  37. * @private
  38. */
  39. protected DataParser _dataParser = null;
  40. /**
  41. * @private
  42. */
  43. protected readonly Dictionary<string, DragonBonesData> _dragonBonesDataMap = new Dictionary<string, DragonBonesData>();
  44. /**
  45. * @private
  46. */
  47. protected readonly Dictionary<string, List<TextureAtlasData>> _textureAtlasDataMap = new Dictionary<string, List<TextureAtlasData>>();
  48. /**
  49. * @private
  50. */
  51. public BaseFactory(DataParser dataParser = null)
  52. {
  53. _dataParser = dataParser;
  54. if (_dataParser == null)
  55. {
  56. _dataParser = _defaultDataParser;
  57. }
  58. }
  59. /**
  60. * @private
  61. */
  62. protected TextureData _getTextureData(string textureAtlasName, string textureName)
  63. {
  64. if (_textureAtlasDataMap.ContainsKey(textureAtlasName))
  65. {
  66. var textureAtlasDataList = _textureAtlasDataMap[textureAtlasName];
  67. for (int i = 0, l = textureAtlasDataList.Count; i < l; ++i)
  68. {
  69. var textureAtlasData = textureAtlasDataList[i];
  70. var textureData = textureAtlasData.GetTexture(textureName);
  71. if (textureData != null)
  72. {
  73. return textureData;
  74. }
  75. }
  76. }
  77. if (autoSearch) // Will be search all data, if the autoSearch is true.
  78. {
  79. foreach (var textureAtlasDataList in _textureAtlasDataMap.Values)
  80. {
  81. for (int i = 0, l = textureAtlasDataList.Count; i < l; ++i)
  82. {
  83. var textureAtlasData = textureAtlasDataList[i];
  84. if (textureAtlasData.autoSearch)
  85. {
  86. var textureData = textureAtlasData.GetTexture(textureName);
  87. if (textureData != null)
  88. {
  89. return textureData;
  90. }
  91. }
  92. }
  93. }
  94. }
  95. return null;
  96. }
  97. /**
  98. * @private
  99. */
  100. protected bool _fillBuildArmaturePackage(BuildArmaturePackage dataPackage, string dragonBonesName, string armatureName, string skinName, string textureAtlasName)
  101. {
  102. DragonBonesData dragonBonesData = null;
  103. ArmatureData armatureData = null;
  104. var isAvailableName = !string.IsNullOrEmpty(dragonBonesName);
  105. if (isAvailableName)
  106. {
  107. if (_dragonBonesDataMap.ContainsKey(dragonBonesName))
  108. {
  109. dragonBonesData = _dragonBonesDataMap[dragonBonesName];
  110. armatureData = dragonBonesData.GetArmature(armatureName);
  111. }
  112. }
  113. if (armatureData == null && (!isAvailableName || autoSearch)) // Will be search all data, if do not give a data name or the autoSearch is true.
  114. {
  115. foreach (var pair in _dragonBonesDataMap)
  116. {
  117. dragonBonesData = pair.Value;
  118. if (!isAvailableName || dragonBonesData.autoSearch)
  119. {
  120. armatureData = dragonBonesData.GetArmature(armatureName);
  121. if (armatureData != null)
  122. {
  123. dragonBonesName = dragonBonesData.name;
  124. break;
  125. }
  126. }
  127. }
  128. }
  129. if (armatureData != null)
  130. {
  131. dataPackage.dataName = dragonBonesName;
  132. dataPackage.textureAtlasName = textureAtlasName;
  133. dataPackage.data = dragonBonesData;
  134. dataPackage.armature = armatureData;
  135. dataPackage.skin = armatureData.GetSkin(skinName);
  136. if (dataPackage.skin == null)
  137. {
  138. dataPackage.skin = armatureData.defaultSkin;
  139. }
  140. return true;
  141. }
  142. return false;
  143. }
  144. /**
  145. * @private
  146. */
  147. protected void _buildBones(BuildArmaturePackage dataPackage, Armature armature)
  148. {
  149. var bones = dataPackage.armature.sortedBones;
  150. for (int i = 0, l = bones.Count; i < l; ++i)
  151. {
  152. var boneData = bones[i];
  153. var bone = BaseObject.BorrowObject<Bone>();
  154. bone._init(boneData);
  155. if (boneData.parent != null)
  156. {
  157. armature.AddBone(bone, boneData.parent.name);
  158. }
  159. else
  160. {
  161. armature.AddBone(bone);
  162. }
  163. if (boneData.ik != null)
  164. {
  165. bone.ikBendPositive = boneData.bendPositive;
  166. bone.ikWeight = boneData.weight;
  167. bone._setIK(armature.GetBone(boneData.ik.name), boneData.chain, boneData.chainIndex);
  168. }
  169. }
  170. }
  171. /**
  172. * @private
  173. */
  174. protected void _buildSlots(BuildArmaturePackage dataPackage, Armature armature)
  175. {
  176. var currentSkin = dataPackage.skin;
  177. var defaultSkin = dataPackage.armature.defaultSkin;
  178. var skinSlotDatas = new Dictionary<string, SkinSlotData>();
  179. foreach (var skinSlotData in defaultSkin.slots.Values)
  180. {
  181. skinSlotDatas[skinSlotData.slot.name] = skinSlotData;
  182. }
  183. if (currentSkin != defaultSkin)
  184. {
  185. foreach (var skinSlotData in currentSkin.slots.Values)
  186. {
  187. skinSlotDatas[skinSlotData.slot.name] = skinSlotData;
  188. }
  189. }
  190. var slots = dataPackage.armature.sortedSlots;
  191. for (int i = 0, l = slots.Count; i < l; ++i)
  192. {
  193. var slotData = slots[i];
  194. if (!skinSlotDatas.ContainsKey(slotData.name))
  195. {
  196. continue;
  197. }
  198. var skinSlotData = skinSlotDatas[slotData.name];
  199. var slot = _generateSlot(dataPackage, skinSlotData, armature);
  200. if (slot != null)
  201. {
  202. armature.AddSlot(slot, slotData.parent.name);
  203. slot._setDisplayIndex(slotData.displayIndex);
  204. }
  205. }
  206. }
  207. /**
  208. * @private
  209. */
  210. protected void _replaceSlotDisplay(BuildArmaturePackage dataPackage, DisplayData displayData, Slot slot, int displayIndex)
  211. {
  212. if (displayIndex < 0)
  213. {
  214. displayIndex = slot.displayIndex;
  215. }
  216. if (displayIndex >= 0)
  217. {
  218. var displayList = slot.displayList; // Copy.
  219. if (displayList.Count <= displayIndex)
  220. {
  221. DragonBones.ResizeList(displayList, displayIndex + 1, null);
  222. }
  223. if (slot._replacedDisplayDatas.Count <= displayIndex)
  224. {
  225. DragonBones.ResizeList(slot._replacedDisplayDatas, displayIndex + 1, null);
  226. }
  227. slot._replacedDisplayDatas[displayIndex] = displayData;
  228. if (displayData.type == DisplayType.Armature)
  229. {
  230. var childArmature = BuildArmature(displayData.path, dataPackage.dataName);
  231. displayList[displayIndex] = childArmature;
  232. }
  233. else
  234. {
  235. if (displayData.texture == null)
  236. {
  237. displayData.texture = _getTextureData(dataPackage.dataName, displayData.path);
  238. }
  239. var displayDatas = slot.skinSlotData.displays;
  240. if (
  241. displayData.mesh != null ||
  242. (displayIndex < displayDatas.Count && displayDatas[displayIndex].mesh != null)
  243. )
  244. {
  245. displayList[displayIndex] = slot.meshDisplay;
  246. }
  247. else
  248. {
  249. displayList[displayIndex] = slot.rawDisplay;
  250. }
  251. }
  252. slot.displayList = displayList;
  253. }
  254. }
  255. /**
  256. * @private
  257. */
  258. protected abstract TextureAtlasData _generateTextureAtlasData(TextureAtlasData textureAtlasData, object textureAtlas);
  259. /**
  260. * @private
  261. */
  262. protected abstract Armature _generateArmature(BuildArmaturePackage dataPackage);
  263. /**
  264. * @private
  265. */
  266. protected abstract Slot _generateSlot(BuildArmaturePackage dataPackage, SkinSlotData skinSlotData, Armature armature);
  267. /**
  268. * @language zh_CN
  269. * 解析并添加龙骨数据。
  270. * @param rawData 需要解析的原始数据。 (JSON)
  271. * @param name 为数据提供一个名称,以便可以通过这个名称获取数据,如果未设置,则使用数据中的名称。
  272. * @param scale 为所有骨架设置一个缩放值。
  273. * @returns DragonBonesData
  274. * @see #GetDragonBonesData()
  275. * @see #AddDragonBonesData()
  276. * @see #RemoveDragonBonesData()
  277. * @see DragonBones.DragonBonesData
  278. * @version DragonBones 4.5
  279. */
  280. public DragonBonesData ParseDragonBonesData(Dictionary<string, object> rawData, string name = null, float scale = 1.0f)
  281. {
  282. var dragonBonesData = _dataParser.ParseDragonBonesData(rawData, scale);
  283. AddDragonBonesData(dragonBonesData, name);
  284. return dragonBonesData;
  285. }
  286. /**
  287. * @language zh_CN
  288. * 解析并添加贴图集数据。
  289. * @param rawData 需要解析的原始数据。 (JSON)
  290. * @param textureAtlas 贴图。 (根据渲染引擎的不同而不同,通常是贴图或材质)
  291. * @param name 为数据指定一个名称,以便可以通过这个名称获取数据,如果未设置,则使用数据中的名称。
  292. * @param scale 为贴图集设置一个缩放值。
  293. * @returns 贴图集数据
  294. * @see #GetTextureAtlasData()
  295. * @see #AddTextureAtlasData()
  296. * @see #RemoveTextureAtlasData()
  297. * @see DragonBones.TextureAtlasData
  298. * @version DragonBones 4.5
  299. */
  300. public TextureAtlasData ParseTextureAtlasData(Dictionary<string, object> rawData, object textureAtlas, string name = null, float scale = 0.0f)
  301. {
  302. var textureAtlasData = _generateTextureAtlasData(null, null);
  303. _dataParser.ParseTextureAtlasData(rawData, textureAtlasData, scale);
  304. _generateTextureAtlasData(textureAtlasData, textureAtlas);
  305. AddTextureAtlasData(textureAtlasData, name);
  306. return textureAtlasData;
  307. }
  308. /**
  309. * @language zh_CN
  310. * 获取指定名称的龙骨数据。
  311. * @param name 数据名称。
  312. * @returns DragonBonesData
  313. * @see #ParseDragonBonesData()
  314. * @see #AddDragonBonesData()
  315. * @see #RemoveDragonBonesData()
  316. * @see DragonBones.DragonBonesData
  317. * @version DragonBones 3.0
  318. */
  319. public DragonBonesData GetDragonBonesData(string name)
  320. {
  321. return _dragonBonesDataMap.ContainsKey(name) ? _dragonBonesDataMap[name] : null;
  322. }
  323. /**
  324. * @language zh_CN
  325. * 添加龙骨数据。
  326. * @param data 龙骨数据。
  327. * @param name 为数据指定一个名称,以便可以通过这个名称获取数据,如果未设置,则使用数据中的名称。
  328. * @see #ParseDragonBonesData()
  329. * @see #GetDragonBonesData()
  330. * @see #RemoveDragonBonesData()
  331. * @see DragonBones.DragonBonesData
  332. * @version DragonBones 3.0
  333. */
  334. public void AddDragonBonesData(DragonBonesData data, string name = null)
  335. {
  336. if (data != null)
  337. {
  338. name = !string.IsNullOrEmpty(name) ? name : data.name;
  339. if (!string.IsNullOrEmpty(name))
  340. {
  341. if (!_dragonBonesDataMap.ContainsKey(name))
  342. {
  343. _dragonBonesDataMap[name] = data;
  344. }
  345. else
  346. {
  347. DragonBones.Assert(false, "Same name data. " + name);
  348. }
  349. }
  350. else
  351. {
  352. DragonBones.Assert(false, "Unnamed data.");
  353. }
  354. }
  355. else
  356. {
  357. DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
  358. }
  359. }
  360. /**
  361. * @language zh_CN
  362. * 移除龙骨数据。
  363. * @param name 数据名称。
  364. * @param disposeData 是否释放数据。
  365. * @see #ParseDragonBonesData()
  366. * @see #GetDragonBonesData()
  367. * @see #AddDragonBonesData()
  368. * @see DragonBones.DragonBonesData
  369. * @version DragonBones 3.0
  370. */
  371. virtual public void RemoveDragonBonesData(string name, bool disposeData = true)
  372. {
  373. if (_dragonBonesDataMap.ContainsKey(name))
  374. {
  375. if (disposeData)
  376. {
  377. _dragonBonesDataMap[name].ReturnToPool();
  378. }
  379. _dragonBonesDataMap.Remove(name);
  380. }
  381. }
  382. /**
  383. * @language zh_CN
  384. * 获取指定名称的贴图集数据列表。
  385. * @param textureAtlasName 数据名称。
  386. * @returns 贴图集数据列表。
  387. * @see #ParseTextureAtlasData()
  388. * @see #AddTextureAtlasData()
  389. * @see #RemoveTextureAtlasData()
  390. * @see DragonBones.textures.TextureAtlasData
  391. * @version DragonBones 3.0
  392. */
  393. public List<TextureAtlasData> GetTextureAtlasData(string textureAtlasName)
  394. {
  395. return _textureAtlasDataMap.ContainsKey(textureAtlasName) ? _textureAtlasDataMap[textureAtlasName] : null;
  396. }
  397. /**
  398. * @language zh_CN
  399. * 添加贴图集数据。
  400. * @param data 贴图集数据。
  401. * @param name 为数据指定一个名称,以便可以通过这个名称获取数据,如果未设置,则使用数据中的名称。
  402. * @see #ParseTextureAtlasData()
  403. * @see #GetTextureAtlasData()
  404. * @see #RemoveTextureAtlasData()
  405. * @see DragonBones.textures.TextureAtlasData
  406. * @version DragonBones 3.0
  407. */
  408. public void AddTextureAtlasData(TextureAtlasData data, string name = null)
  409. {
  410. if (data != null)
  411. {
  412. name = !string.IsNullOrEmpty(name) ? name : data.name;
  413. if (!string.IsNullOrEmpty(name))
  414. {
  415. var textureAtlasList = _textureAtlasDataMap.ContainsKey(name) ? _textureAtlasDataMap[name] : (_textureAtlasDataMap[name] = new List<TextureAtlasData>());
  416. if (!textureAtlasList.Contains(data))
  417. {
  418. textureAtlasList.Add(data);
  419. }
  420. }
  421. else
  422. {
  423. DragonBones.Assert(false, "Unnamed data.");
  424. }
  425. }
  426. else
  427. {
  428. DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
  429. }
  430. }
  431. /**
  432. * @language zh_CN
  433. * 移除贴图集数据。
  434. * @param name 数据名称。
  435. * @param disposeData 是否释放数据。
  436. * @see #ParseTextureAtlasData()
  437. * @see #GetTextureAtlasData()
  438. * @see #AddTextureAtlasData()
  439. * @see DragonBones.textures.TextureAtlasData
  440. * @version DragonBones 3.0
  441. */
  442. virtual public void RemoveTextureAtlasData(string name, bool disposeData = true)
  443. {
  444. if (_textureAtlasDataMap.ContainsKey(name))
  445. {
  446. if (disposeData)
  447. {
  448. foreach (var textureAtlasData in _textureAtlasDataMap[name])
  449. {
  450. textureAtlasData.ReturnToPool();
  451. }
  452. }
  453. _textureAtlasDataMap.Remove(name);
  454. }
  455. }
  456. /**
  457. * @language zh_CN
  458. * 清除所有的数据。
  459. * @param disposeData 是否释放数据。
  460. * @version DragonBones 4.5
  461. */
  462. virtual public void Clear(bool disposeData = true)
  463. {
  464. if (disposeData)
  465. {
  466. foreach (var dragonBonesData in _dragonBonesDataMap.Values)
  467. {
  468. dragonBonesData.ReturnToPool();
  469. }
  470. foreach (var textureAtlasDataList in _textureAtlasDataMap.Values)
  471. {
  472. foreach (var textureAtlasData in textureAtlasDataList)
  473. {
  474. textureAtlasData.ReturnToPool();
  475. }
  476. }
  477. }
  478. _dragonBonesDataMap.Clear();
  479. _textureAtlasDataMap.Clear();
  480. }
  481. /**
  482. * @language zh_CN
  483. * 创建一个指定名称的骨架。
  484. * @param armatureName 骨架数据名称。
  485. * @param dragonBonesName 龙骨数据名称,如果未设置,将检索所有的龙骨数据,当多个龙骨数据中包含同名的骨架数据时,可能无法创建出准确的骨架。
  486. * @param skinName 皮肤名称,如果未设置,则使用默认皮肤。
  487. * @returns 骨架
  488. * @see DragonBones.Armature
  489. * @version DragonBones 3.0
  490. */
  491. public Armature BuildArmature(string armatureName, string dragonBonesName = null, string skinName = null, string textureAtlasName = null)
  492. {
  493. var dataPackage = new BuildArmaturePackage();
  494. if (_fillBuildArmaturePackage(dataPackage, dragonBonesName, armatureName, skinName, textureAtlasName))
  495. {
  496. var armature = _generateArmature(dataPackage);
  497. _buildBones(dataPackage, armature);
  498. _buildSlots(dataPackage, armature);
  499. armature.InvalidUpdate(null, true);
  500. armature.AdvanceTime(0.0f); // Update armature pose.
  501. return armature;
  502. }
  503. DragonBones.Assert(false, "No armature data. " + armatureName + " " + dragonBonesName != null ? dragonBonesName : "");
  504. return null;
  505. }
  506. /**
  507. * @language zh_CN
  508. * 将指定骨架的动画替换成其他骨架的动画。 (通常这些骨架应该具有相同的骨架结构)
  509. * @param toArmature 指定的骨架。
  510. * @param fromArmatreName 其他骨架的名称。
  511. * @param fromSkinName 其他骨架的皮肤名称,如果未设置,则使用默认皮肤。
  512. * @param fromDragonBonesDataName 其他骨架属于的龙骨数据名称,如果未设置,则检索所有的龙骨数据。
  513. * @param ifRemoveOriginalAnimationList 是否移除原有的动画。 [true: 移除, false: 不移除]
  514. * @returns 是否替换成功。 [true: 成功, false: 不成功]
  515. * @see DragonBones.Armature
  516. * @version DragonBones 4.5
  517. */
  518. public bool CopyAnimationsToArmature(
  519. Armature toArmature, string fromArmatreName, string fromSkinName = null,
  520. string fromDragonBonesDataName = null, bool ifRemoveOriginalAnimationList = true
  521. )
  522. {
  523. var dataPackage = new BuildArmaturePackage();
  524. if (_fillBuildArmaturePackage(dataPackage, fromDragonBonesDataName, fromArmatreName, fromSkinName, null))
  525. {
  526. var fromArmatureData = dataPackage.armature;
  527. if (ifRemoveOriginalAnimationList)
  528. {
  529. toArmature.animation.animations = fromArmatureData.animations;
  530. }
  531. else
  532. {
  533. var animations = new Dictionary<string, AnimationData>();
  534. foreach (var pair in toArmature.animation.animations)
  535. {
  536. animations[pair.Key] = toArmature.animation.animations[pair.Key];
  537. }
  538. foreach (var pair in fromArmatureData.animations)
  539. {
  540. animations[pair.Key] = fromArmatureData.animations[pair.Key];
  541. }
  542. toArmature.animation.animations = animations;
  543. }
  544. if (dataPackage.skin != null)
  545. {
  546. var slots = toArmature.GetSlots();
  547. for (int i = 0, l = slots.Count; i < l; ++i)
  548. {
  549. var toSlot = slots[i];
  550. var toSlotDisplayList = toSlot.displayList;
  551. for (int iA = 0, lA = toSlotDisplayList.Count; iA < lA; ++iA)
  552. {
  553. var toDisplayObject = toSlotDisplayList[iA];
  554. if (toDisplayObject is Armature)
  555. {
  556. var displays = dataPackage.skin.GetSlot(toSlot.name).displays;
  557. if (iA < displays.Count)
  558. {
  559. var fromDisplayData = displays[iA];
  560. if (fromDisplayData.type == DisplayType.Armature)
  561. {
  562. CopyAnimationsToArmature((Armature)toDisplayObject, fromDisplayData.path, fromSkinName, fromDragonBonesDataName, ifRemoveOriginalAnimationList);
  563. }
  564. }
  565. }
  566. }
  567. }
  568. return true;
  569. }
  570. }
  571. return false;
  572. }
  573. /**
  574. * @language zh_CN
  575. * 用指定资源替换插槽的显示对象。
  576. * @param dragonBonesName 指定的龙骨数据名称。
  577. * @param armatureName 指定的骨架名称。
  578. * @param slotName 指定的插槽名称。
  579. * @param displayName 指定的显示对象名称。
  580. * @param slot 指定的插槽实例。
  581. * @param displayIndex 要替换的显示对象的索引,如果未设置,则替换当前正在显示的显示对象。
  582. * @version DragonBones 4.5
  583. */
  584. public void ReplaceSlotDisplay(string dragonBonesName, string armatureName, string slotName, string displayName, Slot slot, int displayIndex = -1)
  585. {
  586. var dataPackage = new BuildArmaturePackage();
  587. if (_fillBuildArmaturePackage(dataPackage, dragonBonesName, armatureName, null, null))
  588. {
  589. var slotDisplayDataSet = dataPackage.skin.GetSlot(slotName);
  590. if (slotDisplayDataSet != null)
  591. {
  592. foreach (var displayData in slotDisplayDataSet.displays)
  593. {
  594. if (displayData.name == displayName)
  595. {
  596. _replaceSlotDisplay(dataPackage, displayData, slot, displayIndex);
  597. break;
  598. }
  599. }
  600. }
  601. }
  602. }
  603. /**
  604. * @language zh_CN
  605. * 用指定资源列表替换插槽的显示对象列表。
  606. * @param dragonBonesName 指定的 DragonBonesData 名称。
  607. * @param armatureName 指定的骨架名称。
  608. * @param slotName 指定的插槽名称。
  609. * @param slot 指定的插槽实例。
  610. * @version DragonBones 4.5
  611. */
  612. public void ReplaceSlotDisplayList(string dragonBonesName, string armatureName, string slotName, Slot slot)
  613. {
  614. var dataPackage = new BuildArmaturePackage();
  615. if (_fillBuildArmaturePackage(dataPackage, dragonBonesName, armatureName, null, null))
  616. {
  617. var skinSlotData = dataPackage.skin.GetSlot(slotName);
  618. if (skinSlotData != null)
  619. {
  620. for (int i = 0, l = skinSlotData.displays.Count; i < l; ++i)
  621. {
  622. var displayData = skinSlotData.displays[i];
  623. _replaceSlotDisplay(dataPackage, displayData, slot, i);
  624. }
  625. }
  626. }
  627. }
  628. /**
  629. * @private
  630. */
  631. public Dictionary<string, DragonBonesData> GetAllDragonBonesData()
  632. {
  633. return _dragonBonesDataMap;
  634. }
  635. /**
  636. * @private
  637. */
  638. public Dictionary<string, List<TextureAtlasData>> GetAllTextureAtlasData()
  639. {
  640. return _textureAtlasDataMap;
  641. }
  642. }
  643. }