|
@@ -1,4 +1,6 @@
|
|
|
import { _decorator, BoxCollider2D, Button, Camera, CircleCollider2D, Collider2D, Component, EventTouch, find, Input, input, Node, NodeEventType, RenderTexture, v3, Vec3 } from 'cc';
|
|
|
+import { EventDispatcher } from '../../core_tgx/easy_ui_framework/EventDispatcher';
|
|
|
+import { GameEvent } from './Enum/GameEvent';
|
|
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
@@ -28,16 +30,43 @@ export class LevelAction extends Component {
|
|
|
onLoad(): void {
|
|
|
this._cameraOriginalPos = this.camera.node.position.clone();
|
|
|
this._originalRotation = this.camera.node.eulerAngles.clone();
|
|
|
-
|
|
|
+ this.registerEvent();
|
|
|
+ }
|
|
|
+
|
|
|
+ start() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private registerEvent(){
|
|
|
// 触摸事件监听
|
|
|
input.on(Input.EventType.TOUCH_START, this._onTouchStart, this);
|
|
|
input.on(Input.EventType.TOUCH_MOVE, this._onTouchMove, this);
|
|
|
input.on(Input.EventType.TOUCH_END, this._onTouchEnd, this);
|
|
|
input.on(Input.EventType.TOUCH_CANCEL, this._onTouchEnd, this);
|
|
|
+
|
|
|
+ //事件监听
|
|
|
+ EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_AIM,this.onAimTarget,this);
|
|
|
+ EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_RESET_AIM,this.onResetAimTarget,this);
|
|
|
}
|
|
|
|
|
|
- start() {
|
|
|
+ private unRegisterEvent(){
|
|
|
+ // 触摸事件监听
|
|
|
+ input.off(Input.EventType.TOUCH_START, this._onTouchStart, this);
|
|
|
+ input.off(Input.EventType.TOUCH_MOVE, this._onTouchMove, this);
|
|
|
+ input.off(Input.EventType.TOUCH_END, this._onTouchEnd, this);
|
|
|
+ input.off(Input.EventType.TOUCH_CANCEL, this._onTouchEnd, this);
|
|
|
+
|
|
|
+ //事件监听
|
|
|
+ EventDispatcher.instance.off(GameEvent.EVENT_CAMERA_AIM,this.onAimTarget,this);
|
|
|
+ EventDispatcher.instance.off(GameEvent.EVENT_CAMERA_RESET_AIM,this.onResetAimTarget,this);
|
|
|
+ }
|
|
|
+
|
|
|
+ private onAimTarget(){
|
|
|
+ console.log(`拉近相机镜头!`);
|
|
|
+ }
|
|
|
|
|
|
+ private onResetAimTarget(){
|
|
|
+ console.log(`重置相机镜头!`);
|
|
|
}
|
|
|
|
|
|
/***************************触摸事件**********************************/
|
|
@@ -75,6 +104,7 @@ export class LevelAction extends Component {
|
|
|
/***************************触摸事件end**********************************/
|
|
|
|
|
|
onDestroy () {
|
|
|
+ this.unRegisterEvent();
|
|
|
if (this._renderTex) {
|
|
|
this._renderTex.destroy();
|
|
|
this._renderTex = null;
|