import { Component, EventHandler, EventTouch, _decorator } from "cc"; import { DragSource } from "./DragSource"; import { DragSystem } from "./DragSystem"; const { ccclass, property } = _decorator; /** * 可以释放拖拽的组件 * @description 当拖拽的物体被放下时,会传递DragSource * @author 袁浩 */ @ccclass("DragTarget") export class DragTarget extends Component { @property({ tooltip: "所属分组" }) public group: string = "group"; @property({ tooltip: "当拖拽放下", type: EventHandler }) public onDrop: EventHandler[] = []; @property({ tooltip: "当拖拽中", type: EventHandler }) public onDraging: EventHandler[] = []; start() { DragSystem.addTarget(this); } onDestroy() { DragSystem.removeTarget(this); } public draging(source: DragSource, inTarget: boolean, event: EventTouch) { for (let i = 0; i < this.onDraging.length; i++) { this.onDraging[i] && this.onDraging[i].emit([source, inTarget, this, event]); } } public drop(source: DragSource, event: EventTouch) { for (let i = 0; i < this.onDrop.length; i++) { this.onDrop[i] && this.onDrop[i].emit([source, this, event]); } } }