import { _decorator, Component, EventTouch, Node, Vec2, Vec3 } from 'cc'; import { ModulerBase } from './ModulerBase'; import { MapMgr } from './MapMgr'; import { CardMgr } from './CardMgr'; import { TowerMgr } from './TowerMgr'; import { TowerUI } from './TowerUI'; const { ccclass, property } = _decorator; @ccclass('TouchMgr') export class TouchMgr extends ModulerBase { private _towerPos: Vec3 = null; init(): void{ const cardMgr = this.getModuler(CardMgr); const mapMgr = this.getModuler(MapMgr); const towerUI = this.getModuler(TowerUI); const towerMgr = this.getModuler(TowerMgr); this.node.on(Node.EventType.TOUCH_START,(e:EventTouch)=>{ const touchPos: Vec2 = e.getUILocation(); const pos: Vec3 = this.getModuler(MapMgr).getCenterByPos(touchPos); //点到炮台 炮台升级的UI显示出来 if(towerUI.isShow()){ if(towerUI.touchIcon(touchPos)){ } return; } if(cardMgr.isShow()){ const data = cardMgr.touchCard(touchPos) if(data){ this.getModuler(TowerMgr).creatTower(this._towerPos,data); } //把种植位置置空 this._towerPos = null; return; } //判断是否点到炮台 if(towerMgr.bTouchTower(touchPos)){ return; } const posMap: Vec3 = mapMgr.canCreatorTower(touchPos); if(posMap){ //保存下次点击要种植炮台的位置 this._towerPos = posMap; //显示卡片层 cardMgr.show(posMap); } }) } }