pinball/assets/_Game/Scripts/UI/TouchController.ts

38 lines
1.3 KiB
TypeScript

import { _decorator, Component, Input, Node } from 'cc';
import { EventManger } from '../Manager/EventManger';
import GameEvent from '../Events/GameEvent';
import { ControllerSide } from '../GamePlay/Flipper';
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);
}
}