zombieView.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import modelDtlManager from "../../../dataManager/modelDtlManager";
  2. import npcHelper from "../../../dataManager/npcHelper";
  3. import { AssetsHelper } from "../../../framework/asset/AssetsHelper";
  4. import { Log, LOG_TAG } from "../../../framework/log/Log";
  5. import AudioManager from "../../../framework/music/AudioManager";
  6. import Utils from "../../../framework/utils/utils";
  7. import effectManager from "../../../manager/effectManager";
  8. import zombieActionMgr from "../../../manager/zombieActionMgr";
  9. import { ANI_STATE } from "../../utrl/gameEnum";
  10. const { ccclass, requireComponent } = cc._decorator;
  11. /**僵尸视图类 */
  12. @ccclass
  13. @requireComponent(sp.Skeleton)
  14. export default class zombieView extends cc.Component {
  15. /**spine视图 */
  16. spine: sp.Skeleton = null;
  17. /**视图id */
  18. private view_id = -1;
  19. /**初始化完成 */
  20. private inited = false;
  21. /**当前动画状态 */
  22. private cur_ani_state: ANI_STATE = null;
  23. /** */
  24. /**初始化
  25. * @param view_id 视图id
  26. */
  27. init(view_id: number) {
  28. this.view_id = view_id;
  29. this.spine = this.node.getComponent(sp.Skeleton);
  30. this.node.getChildByName('hit').getComponent(cc.ParticleSystem).stopSystem();
  31. this.loadSpine();
  32. }
  33. loadSpine() {
  34. let spinePath = this.getSpinePath()//this.view_id<=45 为普通僵尸 否则为高级僵尸
  35. Utils.loadSpineBunble(this.spine, spinePath, () => {
  36. if (this.view_id <= 45) {
  37. zombieActionMgr.setSkin(this.spine, this.view_id);
  38. }
  39. this.inited = true;
  40. this.playIdle();
  41. });
  42. }
  43. getSpinePath() {
  44. let spineName = modelDtlManager.getDataByID(this.view_id).modelname;
  45. if (npcHelper.isComZombie(this.view_id)) { //普通僵尸
  46. return 'zombie/common/zombie';
  47. } else if (npcHelper.isSeniorZombie(this.view_id)) { //高级僵尸
  48. return 'zombie/special/' + spineName;
  49. } else if (npcHelper.isBoss(this.view_id)) { //boss
  50. return 'zombie/boss/' + spineName;
  51. }
  52. }
  53. /**播放待机动画 */
  54. playIdle() {
  55. if (!this.inited || this.cur_ani_state == ANI_STATE.idle) {
  56. return;
  57. }
  58. this.cur_ani_state = ANI_STATE.idle;
  59. zombieActionMgr.playStandAnim(this.spine, this.view_id, true);
  60. }
  61. /**播放行走动画 */
  62. playWalk() {
  63. if (!this.inited || this.cur_ani_state == ANI_STATE.walk) {
  64. return;
  65. }
  66. this.cur_ani_state = ANI_STATE.walk;
  67. zombieActionMgr.playWallAnim(this.spine, this.view_id, true);
  68. Log.log(LOG_TAG.DEBUG, 'walk');
  69. }
  70. /**播放攻击动画 */
  71. playAttack(cb?) {
  72. if (!this.inited || this.cur_ani_state == ANI_STATE.close_attack) {
  73. return;
  74. }
  75. this.cur_ani_state = ANI_STATE.close_attack;
  76. zombieActionMgr.playAttackAnim(this.spine, this.view_id, false, cb);
  77. AudioManager.play('zombieattack');
  78. Log.log(LOG_TAG.DEBUG, 'zombieattack');
  79. }
  80. hitEff() {
  81. effectManager.playEff(this.node, 'hit', null, true);
  82. AudioManager.play('zombiehit');
  83. }
  84. zombieViolent() {
  85. if (this.cur_ani_state == ANI_STATE.idle) {
  86. zombieActionMgr.playStandAnim(this.spine, this.view_id, true);
  87. } else if (this.cur_ani_state == ANI_STATE.walk) {
  88. zombieActionMgr.playWallAnim(this.spine, this.view_id, true);
  89. } else if (this.cur_ani_state == ANI_STATE.close_attack) {
  90. zombieActionMgr.playAttackAnim(this.spine, this.view_id, false);
  91. }
  92. }
  93. getViewId() {
  94. return this.view_id;
  95. }
  96. }