GuideWeak.ts 2.5 KB

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