TouchMgr.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { _decorator, Component, EventTouch, Node, Vec2, Vec3 } from 'cc';
  2. import { ModulerBase } from './ModulerBase';
  3. import { MapMgr } from './MapMgr';
  4. import { CardMgr } from './CardMgr';
  5. import { TowerMgr } from './TowerMgr';
  6. import { TowerUI } from './TowerUI';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('TouchMgr')
  9. export class TouchMgr extends ModulerBase {
  10. private _towerPos: Vec3 = null;
  11. init(): void{
  12. const cardMgr = this.getModuler(CardMgr);
  13. const mapMgr = this.getModuler(MapMgr);
  14. const towerUI = this.getModuler(TowerUI);
  15. const towerMgr = this.getModuler(TowerMgr);
  16. this.node.on(Node.EventType.TOUCH_START,(e:EventTouch)=>{
  17. const touchPos: Vec2 = e.getUILocation();
  18. const pos: Vec3 = this.getModuler(MapMgr).getCenterByPos(touchPos);
  19. //点到炮台 炮台升级的UI显示出来
  20. if(towerUI.isShow()){
  21. if(towerUI.touchIcon(touchPos)){
  22. }
  23. return;
  24. }
  25. if(cardMgr.isShow()){
  26. const data = cardMgr.touchCard(touchPos)
  27. if(data){
  28. this.getModuler(TowerMgr).creatTower(this._towerPos,data);
  29. }
  30. //把种植位置置空
  31. this._towerPos = null;
  32. return;
  33. }
  34. //判断是否点到炮台
  35. if(towerMgr.bTouchTower(touchPos)){
  36. return;
  37. }
  38. const posMap: Vec3 = mapMgr.canCreatorTower(touchPos);
  39. if(posMap){
  40. //保存下次点击要种植炮台的位置
  41. this._towerPos = posMap;
  42. //显示卡片层
  43. cardMgr.show(posMap);
  44. }
  45. })
  46. }
  47. }