var reGameStates = require('GameStates'); // Rube:-1,//农夫 // Lumberjack:-1,//伐木工 // Miner:-1,//矿工 // CarrayGay:-1,//搬运工 //AI类型名称 var AI_Type = ['Rube', 'Lumberjack', 'Miner', 'CarryGay', ] //动画名字 var AI_Animation_Name = ["BankRight", "FrontRight", "FrontLeft", "BankLeft", "WorkLeft", "WorkRight", ] //切换状态时候名字带的后缀 var AI_Worker_EndStatus = [ '_Idle', '_Carry', '_CargoCarry_Empty', '_CargoCarry', '_CargoCarry_Raw', ] //新动作 var AI_Worker_Animation_Name = [ "empty_walk_front", "empty_walk_back", "hatchet_walk_front", "hatchet_walk_back", "hatchet_cut_front", "pickaxe_walk_back", "pickaxe_walk_front", "poke_front", "empty_idle_front", "empty_idle_back", ] //骨架 var AI_Worker_Armature_Name = [ "WithoutTricycl", "WithTricycle", ] var AI_Worker_Animation_Name_Sanlun = [ "bag_front", "bag_back", "box_front", "box_back", ] cc.Class({ extends: cc.Component, properties: { //人物类型 AI_Worker_Type: { default: reGameStates.AI_Worker_Type.Rube, type: cc.Enum(reGameStates.AI_Worker_Type), serializable: true, }, AI_Animation_Type: { default: reGameStates.AI_Animation_Type.None, type: cc.Enum(reGameStates.AI_Animation_Type), serializable: true, }, RightName: { default: '', visible: false, serializable: false, }, DownName: { default: '', visible: false, serializable: false, }, LeftName: { default: '', visible: false, serializable: false, }, UpName: { default: '', visible: false, serializable: false, }, IdleName: { default: '', visible: false, serializable: false, }, workerLeftName: { default: '', visible: false, serializable: false, }, workerRightName: { default: '', visible: false, serializable: false, }, //是否循环 isLoop: false, aiTypeName: { default: '', visible: false, serializable: false, }, count: 0, armatureCount: 0, currentAnimationName: null, }, onLoad: function () { //获取 ArmatureDisplay this._armatureDisPlay = this.node.getComponent(dragonBones.ArmatureDisplay) console.log('this._armatureDisPlay:', this._armatureDisPlay); // if (this._armatureDisPlay) { // // cc.log('_animationType11111==',AI_Type[this.AI_Worker_Type]); // this.aiTypeName = AI_Type[this.AI_Worker_Type]; // //获取 Armatrue // this._armatureDisPlay.armatureName = this.aiTypeName; // this.onSwitchWorkerState(this.AI_Animation_Type); // this._armature = this._armatureDisPlay.armature(); // } else { // cc.warn('this._armatureDisPlay 为空。'); // } }, onSwitchFromButton() { if (this.count < this.currentAnimationName.length) this.count++; else this.count = 0; // this._armatureDisPlay.armatureName = AI_Worker_Animation_Name[this.count]; this._armatureDisPlay.playAnimation(this.currentAnimationName[this.count], 0); }, //切换骨架 onSwitchArmature() { if (this.armatureCount < AI_Worker_Armature_Name.length) this.armatureCount++; else this.armatureCount = 0; //设置当前骨架名称 this._armatureDisPlay.armatureName = AI_Worker_Armature_Name[this.armatureCount]; if (this.armatureCount == 0) this.currentAnimationName = AI_Worker_Animation_Name; else this.currentAnimationName = AI_Worker_Animation_Name_Sanlun; //重置动画下标 this.count = 0; //调用一下动画 this.onSwitchFromButton(); }, onSwitchFromDirection() { this.node.scaleX *= -1; }, // 切换当前是什么工人 onSwitchWorker(_workerType) { this.AI_Worker_Type = _workerType; if (this._armatureDisPlay) { // cc.log('_animationType',AI_Type[this.AI_Worker_Type]); this.aiTypeName = AI_Type[this.AI_Worker_Type]; //获取 Armatrue this._armatureDisPlay.armatureName = this.aiTypeName; this.onSwitchWorkerState(this.AI_Animation_Type); this._armature = this._armatureDisPlay.armature(); } else { cc.warn('this._armatureDisPlay 为空。'); } }, //切换工作状态 onSwitchWorkerState(_animationType) { // cc.log('onSwitchWorkerState ==',_animationType); // Idle: -1,//站立 // Carry: -1,//运输 // CargoCarryEmpty:-1,//空的货物运输 // CargoCarry: -1,//货物运输,有车 // CargoCarryRaw: -1,//载货原料 let _AddName = ''; switch (_animationType) { case reGameStates.AI_Animation_Type.Idle: //设置站立 _AddName = AI_Worker_EndStatus[0]; break; case reGameStates.AI_Animation_Type.Carry: //动态设置名字 _AddName = AI_Worker_EndStatus[1]; break; case reGameStates.AI_Animation_Type.CargoCarryEmpty: _AddName = AI_Worker_EndStatus[2]; break; case reGameStates.AI_Animation_Type.CargoCarry: _AddName = AI_Worker_EndStatus[3]; break; case reGameStates.AI_Animation_Type.CargoCarryRaw: _AddName = AI_Worker_EndStatus[4]; break; } //动态设置名字 this.RightName = this.aiTypeName + AI_Animation_Name[0] + _AddName; this.LeftName = this.aiTypeName + AI_Animation_Name[1] + _AddName; this.DownName = this.aiTypeName + AI_Animation_Name[2] + _AddName; this.UpName = this.aiTypeName + AI_Animation_Name[3] + _AddName; this.workerLeftName = this.aiTypeName + AI_Animation_Name[4]; this.workerRightName = this.aiTypeName + AI_Animation_Name[5]; }, switchAnimation: function (direction) { //动画执行方式二 // cc.log('switchAnimation', direction); let loopValue = this.isLoop ? 0 : 1; switch (direction) { case reGameStates.moveType.moveUp: if (this.UpName) this._armatureDisPlay.playAnimation(this.UpName, loopValue); break; case reGameStates.moveType.moveRight: if (this.RightName) this._armatureDisPlay.playAnimation(this.RightName, loopValue); break; case reGameStates.moveType.moveDown: if (this.DownName) this._armatureDisPlay.playAnimation(this.DownName, loopValue); break; case reGameStates.moveType.moveLeft: if (this.LeftName) this._armatureDisPlay.playAnimation(this.LeftName, loopValue); break; } }, //工作动画 playWorkerAnimation(isLeft) { if (isLeft) { this._armatureDisPlay.playAnimation(this.workerLeftName, 0); // cc.log(11111); } else { this._armatureDisPlay.playAnimation(this.workerRightName, 0); // cc.log(22222); } }, })