123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import modelDtlManager from "../../../dataManager/modelDtlManager";
- import npcHelper from "../../../dataManager/npcHelper";
- import { AssetsHelper } from "../../../framework/asset/AssetsHelper";
- import { Log, LOG_TAG } from "../../../framework/log/Log";
- import AudioManager from "../../../framework/music/AudioManager";
- import Utils from "../../../framework/utils/utils";
- import effectManager from "../../../manager/effectManager";
- import zombieActionMgr from "../../../manager/zombieActionMgr";
- import { ANI_STATE } from "../../utrl/gameEnum";
- const { ccclass, requireComponent } = cc._decorator;
- /**僵尸视图类 */
- @ccclass
- @requireComponent(sp.Skeleton)
- export default class zombieView extends cc.Component {
- /**spine视图 */
- spine: sp.Skeleton = null;
- /**视图id */
- private view_id = -1;
- /**初始化完成 */
- private inited = false;
- /**当前动画状态 */
- private cur_ani_state: ANI_STATE = null;
- /** */
- /**初始化
- * @param view_id 视图id
- */
- init(view_id: number) {
- this.view_id = view_id;
- this.spine = this.node.getComponent(sp.Skeleton);
- this.node.getChildByName('hit').getComponent(cc.ParticleSystem).stopSystem();
- this.loadSpine();
- }
- loadSpine() {
- let spinePath = this.getSpinePath()//this.view_id<=45 为普通僵尸 否则为高级僵尸
- Utils.loadSpineBunble(this.spine, spinePath, () => {
- if (this.view_id <= 45) {
- zombieActionMgr.setSkin(this.spine, this.view_id);
- }
- this.inited = true;
- this.playIdle();
- });
- }
- getSpinePath() {
- let spineName = modelDtlManager.getDataByID(this.view_id).modelname;
- if (npcHelper.isComZombie(this.view_id)) { //普通僵尸
- return 'zombie/common/zombie';
- } else if (npcHelper.isSeniorZombie(this.view_id)) { //高级僵尸
- return 'zombie/special/' + spineName;
- } else if (npcHelper.isBoss(this.view_id)) { //boss
- return 'zombie/boss/' + spineName;
- }
- }
- /**播放待机动画 */
- playIdle() {
- if (!this.inited || this.cur_ani_state == ANI_STATE.idle) {
- return;
- }
- this.cur_ani_state = ANI_STATE.idle;
- zombieActionMgr.playStandAnim(this.spine, this.view_id, true);
- }
- /**播放行走动画 */
- playWalk() {
- if (!this.inited || this.cur_ani_state == ANI_STATE.walk) {
- return;
- }
- this.cur_ani_state = ANI_STATE.walk;
- zombieActionMgr.playWallAnim(this.spine, this.view_id, true);
- Log.log(LOG_TAG.DEBUG, 'walk');
- }
- /**播放攻击动画 */
- playAttack(cb?) {
- if (!this.inited || this.cur_ani_state == ANI_STATE.close_attack) {
- return;
- }
- this.cur_ani_state = ANI_STATE.close_attack;
- zombieActionMgr.playAttackAnim(this.spine, this.view_id, false, cb);
- AudioManager.play('zombieattack');
- Log.log(LOG_TAG.DEBUG, 'zombieattack');
- }
- hitEff() {
- effectManager.playEff(this.node, 'hit', null, true);
- AudioManager.play('zombiehit');
- }
- zombieViolent() {
- if (this.cur_ani_state == ANI_STATE.idle) {
- zombieActionMgr.playStandAnim(this.spine, this.view_id, true);
- } else if (this.cur_ani_state == ANI_STATE.walk) {
- zombieActionMgr.playWallAnim(this.spine, this.view_id, true);
- } else if (this.cur_ani_state == ANI_STATE.close_attack) {
- zombieActionMgr.playAttackAnim(this.spine, this.view_id, false);
- }
- }
- getViewId() {
- return this.view_id;
- }
- }
|