40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { Input } from 'cc';
|
|
import { EventTouch } from 'cc';
|
|
import { _decorator, Component, Node } from 'cc';
|
|
import { UmUtil } from '../../../cc-common/cc-util/UmUtil';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('NodeBase')
|
|
export class NodeBase extends Component {
|
|
_isEnableTouch = false;
|
|
|
|
public enableTouch() {
|
|
if (this._isEnableTouch) return;
|
|
this._isEnableTouch = true;
|
|
this.node.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
|
|
this.node.on(Input.EventType.TOUCH_MOVE, this.onTouchMove, this);
|
|
this.node.on(Input.EventType.TOUCH_END, this.onTouchEnd, this);
|
|
this.node.on(Input.EventType.TOUCH_CANCEL, this.onTouchCancel, this, true);
|
|
}
|
|
|
|
public disableTouch() {
|
|
if (!this._isEnableTouch) return;
|
|
this._isEnableTouch = false;
|
|
|
|
this.node.off(Input.EventType.TOUCH_START, this.onTouchStart, this);
|
|
this.node.off(Input.EventType.TOUCH_MOVE, this.onTouchMove, this);
|
|
this.node.off(Input.EventType.TOUCH_END, this.onTouchEnd, this);
|
|
this.node.off(Input.EventType.TOUCH_CANCEL, this.onTouchCancel, this, true);
|
|
}
|
|
|
|
protected onTouchStart(event: EventTouch) { }
|
|
protected onTouchMove(event: EventTouch) { }
|
|
protected onTouchEnd(event: EventTouch) { }
|
|
protected onTouchCancel(event: EventTouch) { }
|
|
|
|
public delayTime(time, callback) {
|
|
UmUtil.delay(this.node, time, callback);
|
|
}
|
|
}
|
|
|