994e76f3-6856-41e2-a430-f2deb112d3be.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. "use strict";
  2. cc._RF.push(module, '994e7bzaFZB4qQw8t6xEtO+', 'DragonManager');
  3. // Script/Manager/DragonManager.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. exports.AnimType = void 0;
  26. var SingleClass_1 = require("./SingleClass");
  27. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  28. var AnimType;
  29. (function (AnimType) {
  30. AnimType[AnimType["Dog"] = 1] = "Dog";
  31. AnimType[AnimType["Daoju"] = 2] = "Daoju";
  32. })(AnimType = exports.AnimType || (exports.AnimType = {}));
  33. var DragonManager = /** @class */ (function (_super) {
  34. __extends(DragonManager, _super);
  35. function DragonManager() {
  36. var _this = _super !== null && _super.apply(this, arguments) || this;
  37. _this.armatureDisplay = null; //动画
  38. _this.armatureDisplayList = []; //已加载动画组
  39. _this.currentAnimName = '';
  40. return _this;
  41. // /**
  42. // *初始化骨骼动画资源
  43. // */
  44. // public initArmatureFile(skeletonData, textureData, texturePng) {
  45. // let factory = this.getFactory;
  46. // //this.armatureDisplay.getArmatureKey
  47. // //factory.parseTextureAtlasData(cc.loader.loadRes(textureData), cc.loader.loadRes(texturePng));
  48. // }
  49. // /**获取骨骼工厂 */
  50. // public get getFactory(): dragonBones.CCFactory {
  51. // return dragonBones.CCFactory.getInstance();
  52. // }
  53. /**获取动画对象 */
  54. // public buildArmature(armatureName): dragonBones.Armature {
  55. // this.armature = this.getFactory.buildArmature(armatureName);
  56. // return this.armature;
  57. // }
  58. // /**
  59. // * 播放动作
  60. // * @param action
  61. // * @param playNum 播放次数
  62. // */
  63. // public play(action: string, playNum: number = 1) {
  64. // if (this.dog_armatureDisplay)
  65. // this.dog_armatureDisplay.playAnimation(action, playNum);
  66. // }
  67. // /**
  68. // * 替换动画
  69. // */
  70. // public replaceAnim(armatureName: string) {
  71. // }
  72. // /**
  73. // * 生成骨骼动画
  74. // * @param node 当前的节点
  75. // * @param path 龙骨地址
  76. // * @param armatureName Armature名称
  77. // * @param newAnimation Animation名称
  78. // * @param completeCallback 动画播放完毕的回调
  79. // * @param playTimes 播放次数 -1是根据龙骨文件 0五险循环 >0是播放次数
  80. // */
  81. // public dragonBoneAnim(node: cc.Node, path: string, armatureName: string, newAnimation: string, completeCallback, playTimes: number = 1) {
  82. // let armatureDisplay = null;
  83. // // if (!this.dog_armatureDisplay) {
  84. // this.dog_armatureDisplay = node.getComponent(dragonBones.ArmatureDisplay);
  85. // armatureDisplay = this.dog_armatureDisplay;
  86. // // }
  87. // cc.loader.loadResDir(path, (err, assets) => {
  88. // assets.forEach(asset => {
  89. // if (asset instanceof dragonBones.DragonBonesAsset) {
  90. // armatureDisplay.dragonAsset = asset;
  91. // }
  92. // if (asset instanceof dragonBones.DragonBonesAtlasAsset) {
  93. // armatureDisplay.dragonAtlasAsset = asset;
  94. // }
  95. // });
  96. // armatureDisplay.armatureName = armatureName;
  97. // armatureDisplay.playAnimation(newAnimation, playTimes);
  98. // armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, completeCallback);
  99. // });
  100. // }
  101. // /**
  102. // * 获取当前的动画
  103. // */
  104. // public getCurrentAnim(node: cc.Node): dragonBones.ArmatureDisplay {
  105. // let armatureDisplay = node.getComponent(dragonBones.ArmatureDisplay);
  106. // armatureDisplay.removeEventListener(dragonBones.EventObject.COMPLETE);
  107. // return armatureDisplay;
  108. // }
  109. }
  110. /**
  111. * 播放龙骨动画
  112. * @param animationName 动画名称
  113. * @param completeCallback 播放回调
  114. * @param playTimes 播放次数
  115. */
  116. DragonManager.prototype.PlayDragonAnimation = function (animationName, completeCallback, playTimes) {
  117. if (completeCallback === void 0) { completeCallback = null; }
  118. if (playTimes === void 0) { playTimes = 1; }
  119. // this.armatureDisplay.armatureName = armatureName;
  120. this.removeListen();
  121. this.currentAnimName = animationName;
  122. this.armatureDisplay.playAnimation(animationName, playTimes);
  123. this.armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, completeCallback.bind(this, this.armatureDisplay.node));
  124. };
  125. /**
  126. * 生成骨骼动画
  127. * @param node 当前的节点
  128. * @param path 龙骨地址
  129. * @param armatureName Armature名称
  130. * @param newAnimation Animation名称
  131. * @param completeCallback 动画播放完毕的回调
  132. * @param playTimes 播放次数 -1是根据龙骨文件 0五险循环 >0是播放次数
  133. */
  134. DragonManager.prototype.dragonBoneAnim = function (node, path, armatureName, newAnimation, completeCallback, playTimes) {
  135. if (playTimes === void 0) { playTimes = 1; }
  136. var armatureDisplay = null;
  137. this.armatureDisplay = node.getComponent(dragonBones.ArmatureDisplay);
  138. armatureDisplay = this.armatureDisplay;
  139. cc.loader.loadResDir(path, function (err, assets) {
  140. assets.forEach(function (asset) {
  141. if (asset instanceof dragonBones.DragonBonesAsset) {
  142. armatureDisplay.dragonAsset = asset;
  143. }
  144. if (asset instanceof dragonBones.DragonBonesAtlasAsset) {
  145. armatureDisplay.dragonAtlasAsset = asset;
  146. }
  147. });
  148. armatureDisplay.armatureName = armatureName;
  149. armatureDisplay.playAnimation(newAnimation, playTimes);
  150. armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, completeCallback);
  151. });
  152. };
  153. /**
  154. * 更换龙骨皮肤
  155. */
  156. DragonManager.prototype.ChangeDragonSkin = function (skinName) {
  157. try {
  158. var skinNames = ["shou1", "shou", "pigu_"];
  159. var skinIndexArr = {
  160. "default": [0, 0, 0],
  161. "skin_one": [1, 1, 3],
  162. "skin_two": [0, 0, 1],
  163. "skin_three": [2, 2, 2],
  164. };
  165. var currentIndexArr = skinIndexArr[skinName];
  166. for (var i = 0; i < skinNames.length - 1; i++) {
  167. var bones = this.armatureDisplay.armature().getSlot(skinNames[i]);
  168. bones.displayIndex = currentIndexArr[i] - 0;
  169. // console.log('bones****', bones, ' ', currentIndexArr[i]);
  170. }
  171. var slot = this.armatureDisplay.armature().getSlot("Armature");
  172. slot.displayList[0].getSlot("pigu_").displayIndex = skinIndexArr[skinName][2];
  173. slot.displayList[0].getSlot("yan").displayIndex = (skinName == "skin_one") ? -1 : 0;
  174. // console.log('slot.armature.name:', slot);
  175. }
  176. catch (err) {
  177. }
  178. };
  179. /**删除动画完毕的监听 */
  180. DragonManager.prototype.removeListen = function () {
  181. if (this.armatureDisplay)
  182. this.armatureDisplay.removeEventListener(dragonBones.EventObject.COMPLETE);
  183. };
  184. DragonManager = __decorate([
  185. ccclass
  186. ], DragonManager);
  187. return DragonManager;
  188. }(SingleClass_1.SingleClass));
  189. exports.default = DragonManager;
  190. cc._RF.pop();