UEBattleRole.ts 2.9 KB

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