var reGameStates = require('GameStates'); //AI类型名称 var AI_Type = ['TestGuy', 'Visitor', 'Tycoon', 'Office', 'Oligarchs', 'Nabobess'] //动画名字 var AI_Animation_Name = ['BankRight', 'FrontRight', 'FrontLeft', 'BankLeft', 'None' ] cc.Class({ extends: cc.Component, properties: { //人物类型 AIType: { default: reGameStates.AIType.TestGuy, type: cc.Enum(reGameStates.AIType), 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, }, //是否循环 isLoop: false, }, onLoad: function () { //获取 ArmatureDisplay this._armatureDisPlay = this.node.getChildByName('dragonBones').getComponent(dragonBones.ArmatureDisplay) if (this._armatureDisPlay) { let aiTypeName = AI_Type[this.AIType]; //获取 Armatrue this._armatureDisPlay.armatureName = aiTypeName; //动态设置名字 this.RightName = aiTypeName + AI_Animation_Name[0]; this.LeftName = aiTypeName + AI_Animation_Name[1]; this.DownName = aiTypeName + AI_Animation_Name[2]; this.UpName = aiTypeName + AI_Animation_Name[3]; this._armature = this._armatureDisPlay.armature(); } else { cc.warn('this._armatureDisPlay 为空。'); } }, // 切换当前是什么游客 onSwitchTourist(_AIType) { this.AIType = _AIType; if (this._armatureDisPlay) { let aiTypeName = AI_Type[this.AIType]; //获取 Armatrue this._armatureDisPlay.armatureName = aiTypeName; //动态设置名字 this.RightName = aiTypeName + AI_Animation_Name[0]; this.LeftName = aiTypeName + AI_Animation_Name[1]; this.DownName = aiTypeName + AI_Animation_Name[2]; this.UpName = aiTypeName + AI_Animation_Name[3]; this._armature = this._armatureDisPlay.armature(); } else { cc.warn('this._armatureDisPlay 为空。'); } }, switchAnimation: function (direction) { //动画执行方式二 // cc.log('switchAnimation', direction); let loopValue = this.isLoop ? 0 : 1; switch (direction) { case reGameStates.moveType.none: // cc.log('reGameStates.moveType.none!!!!!!!!!!!!!!!'); // if (this.IdleName) this._armatureDisPlay.playAnimation(this.IdleName, 1); break; 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; } }, })