HeroDragHelper.ts 1.1 KB

12345678910111213141516171819202122232425
  1. import { _decorator, Component, Sprite, Label, SpriteFrame } from 'cc';
  2. import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
  3. import { DragSource } from '../../core/ui/drag/DragSource';
  4. import { UserHero } from '../UserHeroData';
  5. const { ccclass, property, requireComponent } = _decorator;
  6. /**
  7. * 英雄拖拽辅助组件
  8. * @author 袁浩
  9. */
  10. @ccclass('HeroDragHelper')
  11. @requireComponent(ResourceLoader)
  12. export class HeroDragHelper extends Component {
  13. @property({ tooltip: "武将图", type: Sprite })
  14. public body: Sprite;
  15. @property({ tooltip: "武将名称", type: Label })
  16. public heroName: Label;
  17. public data: UserHero;
  18. public async onDrag(dragSource: DragSource, data: UserHero) {
  19. this.heroName.string = data.client.name;
  20. this.body.spriteFrame = await this.getComponent(ResourceLoader).load(`images/general/texture/hero_img/${data.client.hero_res}/spriteFrame`, SpriteFrame);
  21. }
  22. public async onDraging(dragSource: DragSource) {
  23. dragSource.worldPosition && (this.node.worldPosition = dragSource.worldPosition.clone());
  24. }
  25. }