UEBattleRole.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { FightType } from "../../data/const/TypeConst";
  2. import ResSpine from "../../frameWork/compment/ResSpine";
  3. import { eg } from "../../frameWork/eg";
  4. import { FightTeam } from "../../shared/fight/PtlFightTest";
  5. import AssetMgr from "../../utils/AssetMgr";
  6. import { uiCommon } from "../../utils/UICommon";
  7. import UERole from "../ui/UERole";
  8. import UEBattleView from "./UEBattleView";
  9. import UESubHp from "./UESubHp";
  10. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class UEBattleRole extends UERole {
  13. public m_ResSpine: ResSpine;
  14. m_IsLoadComplete: boolean;
  15. team: FightTeam;
  16. type: FightType;
  17. posX: number;
  18. posY: number;
  19. onLoad() {
  20. this.m_ResSpine = this.node.getChildByName("spine").getComponent(ResSpine);
  21. }
  22. start() {
  23. }
  24. setRole(pos: cc.Vec3, team: FightTeam, type: FightType) {
  25. this.team = team;
  26. this.type = type;
  27. this.node.x = pos.x;
  28. this.node.y = pos.y;
  29. this.posX = pos.x;
  30. this.posY = pos.y;
  31. this.LoadRoleRes();
  32. }
  33. GetSpinePath() {
  34. let spinePath = "role/nv";
  35. // if (this.team?.fid == "10086") {
  36. // spinePath = "mon/10001";
  37. // }
  38. return spinePath;
  39. }
  40. public LoadRoleRes(cb?: Function): void {
  41. let spinePath = this.GetSpinePath();
  42. let that = this;
  43. this.m_IsLoadComplete = false;
  44. this.m_ResSpine.spSkeleton.skeletonData = null;
  45. this.m_ResSpine.setSpineData("spine", spinePath, (asset: sp.SkeletonData) => {
  46. if (asset) {
  47. }
  48. if (that.m_ResSpine && that.m_ResSpine.isValid) {
  49. that.m_ResSpine.addEventListener(that.OnEventListener.bind(that));
  50. that.m_ResSpine.AddSpineCompleteListener(that.OnCompleteListener.bind(that));
  51. }
  52. this.m_IsLoadComplete = true;
  53. cb && cb();
  54. }, false, "stand", true, 1);
  55. }
  56. ShowSubHp(element: [string, number], hpType?: string) {
  57. let hpLayer: cc.Node = UEBattleView.getInstance().GetHpLayer();
  58. let subHpNode = eg.poolManager.GetPool("subHPPool").get() || AssetMgr.instantiateUE(UESubHp).node;
  59. let pos = uiCommon.transPos(this.node, hpLayer);
  60. pos.y += this.GetHeightCenter() * Math.abs(this.node.scale);
  61. subHpNode.setPosition(pos);
  62. hpLayer.addChild(subHpNode);
  63. let subHpComp: UESubHp = subHpNode.getComponent(UESubHp);
  64. subHpComp.show(element, hpType);
  65. }
  66. /** 获取角色高度中心 */
  67. public GetHeightCenter() {
  68. let offset = this.node.getChildByName("spine").height * this.node.getChildByName("spine").scaleY * 0.7;//偏移到玩家身上的受击位置
  69. return offset;
  70. }
  71. playAni(aniName: string, loop: boolean, showLast?: boolean) {
  72. this.m_ResSpine.playAnimation(aniName, loop, showLast);
  73. }
  74. /** 监听事件帧 */
  75. OnEventListener(name: string) {
  76. // console.log("角色事件帧", name);
  77. if (name === "skill" || name === "atk") {
  78. }
  79. }
  80. OnCompleteListener(name: string) {
  81. }
  82. }