LeaderSkillShow.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { _decorator, Component, Node, sp, tween, v3 } from 'cc';
  2. import { DataSystem } from '../core/data/DataSystem';
  3. import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
  4. import { BitmapFont } from '../core/ui/BitmapFont';
  5. import { ConfigData } from '../data/ConfigData';
  6. import { Hero } from './Hero';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('LeaderSkillShow')
  9. export class LeaderSkillShow extends Component {
  10. @property({ type: ResourceLoader, tooltip: "资源加载组件" }) res: ResourceLoader;
  11. @property({ type: sp.Skeleton, tooltip: "背景特效" }) bgEffect: sp.Skeleton;
  12. @property({ type: sp.Skeleton, tooltip: "统帅特效" }) leaderEffect: sp.Skeleton;
  13. @property({ type: BitmapFont, tooltip: "艺术字" }) artlabel: BitmapFont;
  14. public showOverHandler: Function;
  15. public async setData(skillID: number, heroID: number, cb: Function) {
  16. this.showOverHandler = cb;
  17. let resName = DataSystem.getData(ConfigData)["general"][heroID]["hero_res"];
  18. let spData = await this.res.load<sp.SkeletonData>("spine/hero/" + resName, sp.SkeletonData);
  19. this.leaderEffect.skeletonData = spData;
  20. this.leaderEffect.setAnimation(0, "run", true);
  21. tween(this.leaderEffect.node).to(1, { position: v3(0, 0, 0) }).call(async () => {
  22. this.bgEffect.setAnimation(0, "animation", false);
  23. this.leaderEffect.setAnimation(0, "attack", false);
  24. let skillName = DataSystem.getData(ConfigData)["skill"][110000 + skillID]["name"];
  25. let nameArray = skillName.split("");
  26. for (let i = 0; i < nameArray.length; i++) {
  27. await this.setLabel(nameArray[i]);
  28. }
  29. this.scheduleOnce(() => {
  30. this.onShowOver();
  31. }, 0.3);
  32. }).start();
  33. }
  34. /**设置文字 */
  35. private setLabel(name: string) {
  36. return new Promise<any>(async (resolve: (data: any) => void) => {
  37. this.artlabel.string += name;
  38. this.scheduleOnce(() => {
  39. resolve(null);
  40. }, 0.15);
  41. });
  42. }
  43. /**特写结束 */
  44. private onShowOver(): void {
  45. this.showOverHandler && this.showOverHandler();
  46. this.node.destroy();
  47. }
  48. }