import { _decorator, Component, Sprite, Label, SpriteFrame } from 'cc'; import { ResourceLoader } from '../../core/resourceManager/ResourceLoader'; import { DragSource } from '../../core/ui/drag/DragSource'; import { UserHero } from '../UserHeroData'; const { ccclass, property, requireComponent } = _decorator; /** * 英雄拖拽辅助组件 * @author 袁浩 */ @ccclass('HeroDragHelper') @requireComponent(ResourceLoader) export class HeroDragHelper extends Component { @property({ tooltip: "武将图", type: Sprite }) public body: Sprite; @property({ tooltip: "武将名称", type: Label }) public heroName: Label; public data: UserHero; public async onDrag(dragSource: DragSource, data: UserHero) { this.heroName.string = data.client.name; this.body.spriteFrame = await this.getComponent(ResourceLoader).load(`images/general/texture/hero_img/${data.client.hero_res}/spriteFrame`, SpriteFrame); } public async onDraging(dragSource: DragSource) { dragSource.worldPosition && (this.node.worldPosition = dragSource.worldPosition.clone()); } }