GuideWeak.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const { ccclass, property } = cc._decorator;
  2. /**
  3. * @author 薛鸿潇
  4. */
  5. @ccclass
  6. export default class GuideWeak extends cc.Component {
  7. onLoad() {
  8. gData.guideWeakData.guideStyle = this;
  9. this.InitTouch();
  10. mk.event.register('close-panel', this.onClosePanel, this);
  11. }
  12. update(dt) {
  13. if (!gData.guideWeakData.enable) return;
  14. if (gData.guideWeakData.cur_guide_id) return;
  15. gData.guideWeakData.silent_time += dt;
  16. if (gData.guideWeakData.silent_time >= gData.guideWeakData.check_time) {
  17. gData.guideWeakData.initGuideId();
  18. gData.guideWeakData.openPanelByBtn();
  19. }
  20. }
  21. /**
  22. * 界面关闭
  23. */
  24. public onClosePanel(panel_name: string = '') {
  25. cc.log(panel_name)
  26. if (gData.guideWeakData.panel_name_config[panel_name] == gData.guideWeakData.cur_guide_id) {
  27. gData.guideWeakData.cur_guide_id = 0;
  28. }
  29. }
  30. /** 玩家的屏幕触摸操作 */
  31. private onClickCall(touch) {
  32. cc.log('弱引导计时重置');
  33. gData.guideWeakData.silent_time = 0;
  34. }
  35. ///////////////// 自定义触摸监听 /////////////////
  36. private _eventManager = cc["internal"]["eventManager"];
  37. private _touchListener: any;
  38. private InitTouch() {
  39. const EventListener = cc["EventListener"];
  40. this._touchListener = EventListener.create({
  41. event: EventListener.TOUCH_ONE_BY_ONE,
  42. swallowTouches: false,//是否吞噬touch事件
  43. owner: this.node,
  44. mask: null,
  45. onTouchBegan: this.onTouchStart.bind(this),
  46. onTouchMoved: null,
  47. onTouchEnded: this.onTouchEnded.bind(this),
  48. onTouchCancelled: null,
  49. });
  50. this._eventManager.addListener(this._touchListener, this.node);
  51. }
  52. private onTouchStart(touch: cc.Touch, event: cc.Event.EventTouch): boolean {
  53. // cc.log("touch start");
  54. //此处必须返回true(表示接触到了节点),否则TOUCH_MOVE,TOUCH_END,TOUCH_CANCEL不触发。
  55. return true;
  56. }
  57. private onTouchEnded(touch: cc.Touch, event: cc.Event.EventTouch): void {
  58. // cc.log("touch end");
  59. this.onClickCall(touch);
  60. }
  61. protected onDestroy(): void {
  62. // super.onDestroy();
  63. this._eventManager.removeListener(this._touchListener, this.node);
  64. mk.event.remove('close-panel', this.onClosePanel, this);
  65. }
  66. }