123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- "use strict";
- cc._RF.push(module, '994e7bzaFZB4qQw8t6xEtO+', 'DragonManager');
- // Script/Manager/DragonManager.ts
- "use strict";
- var __extends = (this && this.__extends) || (function () {
- var extendStatics = function (d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
- return extendStatics(d, b);
- };
- return function (d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- })();
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- 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;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.AnimType = void 0;
- var SingleClass_1 = require("./SingleClass");
- var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
- var AnimType;
- (function (AnimType) {
- AnimType[AnimType["Dog"] = 1] = "Dog";
- AnimType[AnimType["Daoju"] = 2] = "Daoju";
- })(AnimType = exports.AnimType || (exports.AnimType = {}));
- var DragonManager = /** @class */ (function (_super) {
- __extends(DragonManager, _super);
- function DragonManager() {
- var _this = _super !== null && _super.apply(this, arguments) || this;
- _this.armatureDisplay = null; //动画
- _this.armatureDisplayList = []; //已加载动画组
- _this.currentAnimName = '';
- return _this;
- // /**
- // *初始化骨骼动画资源
- // */
- // public initArmatureFile(skeletonData, textureData, texturePng) {
- // let factory = this.getFactory;
- // //this.armatureDisplay.getArmatureKey
- // //factory.parseTextureAtlasData(cc.loader.loadRes(textureData), cc.loader.loadRes(texturePng));
- // }
- // /**获取骨骼工厂 */
- // public get getFactory(): dragonBones.CCFactory {
- // return dragonBones.CCFactory.getInstance();
- // }
- /**获取动画对象 */
- // public buildArmature(armatureName): dragonBones.Armature {
- // this.armature = this.getFactory.buildArmature(armatureName);
- // return this.armature;
- // }
- // /**
- // * 播放动作
- // * @param action
- // * @param playNum 播放次数
- // */
- // public play(action: string, playNum: number = 1) {
- // if (this.dog_armatureDisplay)
- // this.dog_armatureDisplay.playAnimation(action, playNum);
- // }
- // /**
- // * 替换动画
- // */
- // public replaceAnim(armatureName: string) {
- // }
- // /**
- // * 生成骨骼动画
- // * @param node 当前的节点
- // * @param path 龙骨地址
- // * @param armatureName Armature名称
- // * @param newAnimation Animation名称
- // * @param completeCallback 动画播放完毕的回调
- // * @param playTimes 播放次数 -1是根据龙骨文件 0五险循环 >0是播放次数
- // */
- // public dragonBoneAnim(node: cc.Node, path: string, armatureName: string, newAnimation: string, completeCallback, playTimes: number = 1) {
- // let armatureDisplay = null;
- // // if (!this.dog_armatureDisplay) {
- // this.dog_armatureDisplay = node.getComponent(dragonBones.ArmatureDisplay);
- // armatureDisplay = this.dog_armatureDisplay;
- // // }
- // cc.loader.loadResDir(path, (err, assets) => {
- // assets.forEach(asset => {
- // if (asset instanceof dragonBones.DragonBonesAsset) {
- // armatureDisplay.dragonAsset = asset;
- // }
- // if (asset instanceof dragonBones.DragonBonesAtlasAsset) {
- // armatureDisplay.dragonAtlasAsset = asset;
- // }
- // });
- // armatureDisplay.armatureName = armatureName;
- // armatureDisplay.playAnimation(newAnimation, playTimes);
- // armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, completeCallback);
- // });
- // }
- // /**
- // * 获取当前的动画
- // */
- // public getCurrentAnim(node: cc.Node): dragonBones.ArmatureDisplay {
- // let armatureDisplay = node.getComponent(dragonBones.ArmatureDisplay);
- // armatureDisplay.removeEventListener(dragonBones.EventObject.COMPLETE);
- // return armatureDisplay;
- // }
- }
- /**
- * 播放龙骨动画
- * @param animationName 动画名称
- * @param completeCallback 播放回调
- * @param playTimes 播放次数
- */
- DragonManager.prototype.PlayDragonAnimation = function (animationName, completeCallback, playTimes) {
- if (completeCallback === void 0) { completeCallback = null; }
- if (playTimes === void 0) { playTimes = 1; }
- // this.armatureDisplay.armatureName = armatureName;
- this.removeListen();
- this.currentAnimName = animationName;
- this.armatureDisplay.playAnimation(animationName, playTimes);
- this.armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, completeCallback.bind(this, this.armatureDisplay.node));
- };
- /**
- * 生成骨骼动画
- * @param node 当前的节点
- * @param path 龙骨地址
- * @param armatureName Armature名称
- * @param newAnimation Animation名称
- * @param completeCallback 动画播放完毕的回调
- * @param playTimes 播放次数 -1是根据龙骨文件 0五险循环 >0是播放次数
- */
- DragonManager.prototype.dragonBoneAnim = function (node, path, armatureName, newAnimation, completeCallback, playTimes) {
- if (playTimes === void 0) { playTimes = 1; }
- var armatureDisplay = null;
- this.armatureDisplay = node.getComponent(dragonBones.ArmatureDisplay);
- armatureDisplay = this.armatureDisplay;
- cc.loader.loadResDir(path, function (err, assets) {
- assets.forEach(function (asset) {
- if (asset instanceof dragonBones.DragonBonesAsset) {
- armatureDisplay.dragonAsset = asset;
- }
- if (asset instanceof dragonBones.DragonBonesAtlasAsset) {
- armatureDisplay.dragonAtlasAsset = asset;
- }
- });
- armatureDisplay.armatureName = armatureName;
- armatureDisplay.playAnimation(newAnimation, playTimes);
- armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, completeCallback);
- });
- };
- /**
- * 更换龙骨皮肤
- */
- DragonManager.prototype.ChangeDragonSkin = function (skinName) {
- try {
- var skinNames = ["shou1", "shou", "pigu_"];
- var skinIndexArr = {
- "default": [0, 0, 0],
- "skin_one": [1, 1, 3],
- "skin_two": [0, 0, 1],
- "skin_three": [2, 2, 2],
- };
- var currentIndexArr = skinIndexArr[skinName];
- for (var i = 0; i < skinNames.length - 1; i++) {
- var bones = this.armatureDisplay.armature().getSlot(skinNames[i]);
- bones.displayIndex = currentIndexArr[i] - 0;
- // console.log('bones****', bones, ' ', currentIndexArr[i]);
- }
- var slot = this.armatureDisplay.armature().getSlot("Armature");
- slot.displayList[0].getSlot("pigu_").displayIndex = skinIndexArr[skinName][2];
- slot.displayList[0].getSlot("yan").displayIndex = (skinName == "skin_one") ? -1 : 0;
- // console.log('slot.armature.name:', slot);
- }
- catch (err) {
- }
- };
- /**删除动画完毕的监听 */
- DragonManager.prototype.removeListen = function () {
- if (this.armatureDisplay)
- this.armatureDisplay.removeEventListener(dragonBones.EventObject.COMPLETE);
- };
- DragonManager = __decorate([
- ccclass
- ], DragonManager);
- return DragonManager;
- }(SingleClass_1.SingleClass));
- exports.default = DragonManager;
- cc._RF.pop();
|