2024-03-28 20:35:44 -07:00
|
|
|
import { _decorator, Component, Input, Node } from 'cc';
|
|
|
|
import { EventManger } from '../Manager/EventManger';
|
|
|
|
import GameEvent from '../Events/GameEvent';
|
2024-04-05 01:09:19 -07:00
|
|
|
import ControllerSide from '../Enum/ControllerSide';
|
2024-03-28 20:35:44 -07:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
@ccclass('TouchController')
|
|
|
|
export class TouchController extends Component {
|
|
|
|
@property({ type: Node, visible: true })
|
|
|
|
private _left: Node;
|
|
|
|
@property({ type: Node, visible: true })
|
|
|
|
private _right: Node;
|
|
|
|
|
|
|
|
protected onLoad(): void {
|
|
|
|
this._left.on(Input.EventType.TOUCH_START, this.onLeftTouchStart, this);
|
|
|
|
this._left.on(Input.EventType.TOUCH_END, this.onLeftTouchEnd, this);
|
|
|
|
|
|
|
|
this._right.on(Input.EventType.TOUCH_START, this.onRightTouchStart, this);
|
|
|
|
this._right.on(Input.EventType.TOUCH_END, this.onRightTouchEnd, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private onLeftTouchStart() {
|
|
|
|
EventManger.instance.emit(GameEvent.ControlTouchStart, ControllerSide.Left);
|
|
|
|
}
|
|
|
|
|
|
|
|
private onLeftTouchEnd() {
|
|
|
|
EventManger.instance.emit(GameEvent.ControlTouchEnd, ControllerSide.Left);
|
|
|
|
}
|
|
|
|
|
|
|
|
private onRightTouchStart() {
|
|
|
|
EventManger.instance.emit(GameEvent.ControlTouchStart, ControllerSide.Right);
|
|
|
|
}
|
|
|
|
|
|
|
|
private onRightTouchEnd() {
|
|
|
|
EventManger.instance.emit(GameEvent.ControlTouchEnd, ControllerSide.Right);
|
|
|
|
}
|
|
|
|
}
|