import { _decorator ,Vec2,NodeEventType,EventTouch} from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { data } from "../data/data"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('HeroCardViewComp') @ecs.register('HeroCardView', false) export class HeroCardViewComp extends CCComp { card_name:string = "hero_card"; card_type:string = "hero"; card_uid:number = 1000; /** 方向 */ private _dir: Vec2 = new Vec2(0, 0); public get dir(): Vec2 { return this._dir; } public set dir(value: Vec2) { this._dir = value; } pos_x=0; pos_y=0; protected onLoad(): void { this.node.on(NodeEventType.TOUCH_START, this.onTouchMove, this); this.node.on(NodeEventType.TOUCH_MOVE, this.onTouchMove, this); this.node.on(NodeEventType.TOUCH_END, this.onTouchEnd, this); this.node.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this); oops.message.on("destroy hero_card", this.on_destroy_node, this); } private on_destroy_node(event: string, args: any) { // if(this.ent.eid == args){ // this.reset(); // } } onTouchMove(event: EventTouch) { console.log("onTouchMove"); let delta = event.getDelta(); this.node.setPosition(this.node.position.x+delta.x,this.node.position.y+delta.y); } onTouchEnd(){ if(this.node.position.y-this.pos_y > 50){ this.use_card() }else{ this.node.setPosition(this.pos_x,this.pos_y); } console.log(ecs.query(ecs.allOf(HeroCardViewComp))) } use_card(){ oops.message.dispatchEvent("do_add_hero",this.ent) this.ent.destroy(); } /** 视图层逻辑代码分离演示 */ start() { this.pos_x=this.node.position.x; this.pos_y=this.node.position.y; } /** 全局消息逻辑处理 */ // private onHandler(event: string, args: any) { // switch (event) { // case ModuleEvent.Cmd: // break; // } // } /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ reset() { this.node.destroy(); } }