Ver Fonte

优化 添加瞄准外frame触摸

woso_javan há 3 semanas atrás
pai
commit
b65f909f53

+ 36 - 7
assets/module_aliens/RoosterAliens.ts

@@ -1,4 +1,4 @@
-import { _decorator, Component, ERaycast2DType, find, Label, Node, NodeEventType, PhysicsSystem2D, Tween, tween, v2, v3, Vec2, Vec3 } from 'cc';
+import { _decorator, Component, ERaycast2DType, EventTouch, find, Label, Node, NodeEventType, PhysicsSystem2D, Tween, tween, v2, v3, Vec2, Vec3 } from 'cc';
 import { GameEvent } from './Script/Enum/GameEvent';
 import { LevelManager } from './Script/Manager/LevelMgr';
 import { GameUtil } from './Script/GameUtil';
@@ -18,6 +18,9 @@ const duration = 0.3;
 @ccclass('RoosterAliens')
 export class RoosterAliens extends Component {
 
+    private _touchStartTime: number = 0;
+    private _isTouchMoving: boolean = false;
+
     onLoad() {
         AliensAudioMgr.initilize();
         AliensAudioMgr.play(AliensAudioMgr.getMusicIdName(1), 1.0);
@@ -25,7 +28,7 @@ export class RoosterAliens extends Component {
         LevelManager.instance.initilizeModel();
         AliensGlobalInstance.instance.initUI(); //初始化u
         this.registerListener();
-        this.resetMgr(); 
+        this.resetMgr();
     }
 
     private resetMgr() {
@@ -53,13 +56,16 @@ export class RoosterAliens extends Component {
 
         btnSet.on(NodeEventType.TOUCH_END, () => this.onClickSet(), this);
         btnPoint.on(NodeEventType.TOUCH_END, () => this.onClickAim(), this);
-        btnPointFrame.on(NodeEventType.TOUCH_END, () => this.onClickResetAim(), this);
+        // btnPointFrame.on(NodeEventType.TOUCH_END, () => this.onClickResetAim(), this);
+        btnPointFrame.on(NodeEventType.TOUCH_START, this.frameTouchStart, this);
+        btnPointFrame.on(NodeEventType.TOUCH_MOVE, this.frameTouchMove, this);
+        btnPointFrame.on(NodeEventType.TOUCH_END, this.frameTouchEnd, this);
         btnShoot.on(NodeEventType.TOUCH_END, () => this.onShoot(), this);
         btnStart.on(NodeEventType.TOUCH_END, () => this.onStart(), this);
 
-        EventDispatcher.instance.on(GameEvent.EVENT_GAME_ENTER,this.onStart,this);
-        EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_HIDE_AIM,this.onClickResetAim,this);
-        EventDispatcher.instance.on(GameEvent.EVENT_GAME_BACK_HOME,this.backHome,this);
+        EventDispatcher.instance.on(GameEvent.EVENT_GAME_ENTER, this.onStart, this);
+        EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_HIDE_AIM, this.onClickResetAim, this);
+        EventDispatcher.instance.on(GameEvent.EVENT_GAME_BACK_HOME, this.backHome, this);
     }
 
     private onClickSet(): void {
@@ -87,6 +93,29 @@ export class RoosterAliens extends Component {
         EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_RESET_AIM);
     }
 
+    private frameTouchStart(event: EventTouch): void {
+        this._touchStartTime = Date.now();
+        this._isTouchMoving = false;
+    }
+
+    private frameTouchMove(event: EventTouch): void {
+        // 检查触摸时长是否超过0.3秒
+        if (Date.now() - this._touchStartTime >= 300) {
+            this._isTouchMoving = true;
+            EventDispatcher.instance.emit(GameEvent.EVENT_FRAME_TOUCH_MOVE, event);
+        }
+    }
+
+    private frameTouchEnd(event: EventTouch): void {
+        if (!this._isTouchMoving) {
+            this.onClickResetAim();
+        }
+
+        // 重置状态
+        this._touchStartTime = 0;
+        this._isTouchMoving = false;
+    }
+
     private onShoot(): void {
         AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(4), 1.0);
         EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SHOOT);
@@ -110,7 +139,7 @@ export class RoosterAliens extends Component {
 
     private backHome(): void {
         AliensGlobalInstance.instance.homeUI.active = true;
-        AliensGlobalInstance.instance.battleUI.active = false; 
+        AliensGlobalInstance.instance.battleUI.active = false;
     }
 }
 

+ 10 - 10
assets/module_aliens/Script/Components/EnemyComponent.ts

@@ -3,7 +3,7 @@ import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDis
 import { GameEvent } from '../Enum/GameEvent';
 import { GameUtil } from '../GameUtil';
 
-const { ccclass, property,executeInEditMode } = _decorator;
+const { ccclass, property, executeInEditMode } = _decorator;
 
 export enum EnemyStatus {
     LIFE,
@@ -77,12 +77,12 @@ export class EnemyComponent extends Component {
         // 检查是否是当前怪物节点被击中
         if (this.node === hitNode && this.status === EnemyStatus.LIFE) {
             this.status = EnemyStatus.DIE;
-            
+
             // 修改所有部位材质为击中材质
             this.changeMaterial();
-            
+
             this.playHitTwitch();
-            await GameUtil.delay(0.5);
+            await GameUtil.delay(0.7);
             this.rigidBody.isKinematic = false;
             this.rigidBody.isDynamic = true;
             await GameUtil.delay(0.3);
@@ -98,10 +98,10 @@ export class EnemyComponent extends Component {
             renderer.material = this.hitMaterial;
         }
         if (eyeRenderer) {
-            eyeRenderer.material = this.hitEyeMaterial; 
+            eyeRenderer.material = this.hitEyeMaterial;
         }
     }
-    
+
     // 中枪抽搐效果
     playHitTwitch() {
         // 抖动参数配置
@@ -119,19 +119,19 @@ export class EnemyComponent extends Component {
         // 创建抖动动画函数
         const createShakeTween = (node: Node, config: { times: number, duration: number }) => {
             const t = tween(node);
-            
+
             for (let i = 0; i < config.times; i++) {
                 const euler = new Vec3();
                 node.rotation.getEulerAngles(euler);
                 const shakeValue = getRandomShake();
-                
+
                 const newEuler = new Vec3(euler.x + shakeValue, euler.y + shakeValue, euler.z);
                 const newRotation = new Quat();
                 Quat.fromEuler(newRotation, newEuler.x, newEuler.y, newEuler.z);
-                
+
                 t.to(config.duration, { rotation: newRotation });
             }
-            
+
             return t;
         };
 

+ 1 - 1
assets/module_aliens/Script/Components/ScreenShotComponent.ts

@@ -67,7 +67,7 @@ export class ScreenShotComponent extends Component {
         const targetViewPos = new Vec3(
             this._targetNode.worldPosition.x,
             this._targetNode.worldPosition.y + 1, 
-            this._targetNode.worldPosition.z + 3 
+            this._targetNode.worldPosition.z + 0.7
         );
 
         camera.node.worldPosition = targetViewPos;

+ 2 - 1
assets/module_aliens/Script/Enum/GameEvent.ts

@@ -37,7 +37,8 @@ export class GameEvent {
     /** 爆头事件*/
     static readonly EVENT_CAMERA_HEADSHOT = 'EVENT_CAMERA_HEADSHOT';
 
-    /** 显示瞄准节点*/
+    /** frame 触摸事件*/
+    static readonly EVENT_FRAME_TOUCH_MOVE = 'EVENT_FRAME_TOUCH_MOVE';
 
     /** 发射射击*/
     static readonly EVENT_CAMERA_SHOOT = 'EVENT_CAMERA_SHOOT';

+ 8 - 2
assets/module_aliens/Script/LevelAction.ts

@@ -1,4 +1,4 @@
-import { _decorator, BoxCollider2D, Button, Camera, CCFloat, CircleCollider2D, Color, Component, debug, DebugView, director, EventTouch, find, geometry, Input, input, Label, math, Node, NodeEventType, PhysicsSystem, Quat, RenderTexture, Tween, tween, v3, Vec3, view } from 'cc';
+import { _decorator, BoxCollider2D, Button, Camera, CCFloat, CircleCollider2D, Color, Component, debug, DebugView, director, EventTouch, find, geometry, Input, input, Label, math, Node, NodeEventType, PhysicsSystem, Quat, RenderTexture, Tween, tween, v3, Vec2, Vec3, view } from 'cc';
 import { EventDispatcher } from '../../core_tgx/easy_ui_framework/EventDispatcher';
 import { GameEvent } from './Enum/GameEvent';
 import { LineDrawer } from './LineDrawer';
@@ -99,6 +99,7 @@ export class LevelAction extends Component {
         EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_RESET_AIM, this.onResetAimTarget, this);
         EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_SHOOT, this.onShoot, this);
         EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_SCREENSHOT_RADAR_LOCK, this.onCameraToTarget, this);
+        EventDispatcher.instance.on(GameEvent.EVENT_FRAME_TOUCH_MOVE, this.frameTouch, this);
     }
 
     private unRegisterEvent() {
@@ -264,15 +265,20 @@ export class LevelAction extends Component {
 
     /***************************触摸事件**********************************/
     private _onTouchStart(event: EventTouch) {
+        console.log('_onTouchStart');
         const radarComponent = AliensGlobalInstance.instance.renderNode.getComponent(RadarComponent)!;
         if (radarComponent) {
             radarComponent.unlockPositionUpdate();
         }
     }
 
+    private frameTouch(event: EventTouch) {
+       this._onTouchMove(event);
+    }
+
     private async _onTouchMove(event: EventTouch) {
         const delta = event.getDelta();
-
+        // console.log('_onTouchMove delta:', delta);
         // 获取当前相机旋转
         const currentRotation = new Vec3();
         this.camera.node.rotation.getEulerAngles(currentRotation);

+ 65 - 65
profiles/v2/packages/scene.json

@@ -5,7 +5,7 @@
     "__version__": "1.3.7"
   },
   "gizmos-infos": {
-    "is2D": false,
+    "is2D": true,
     "is3DIcon": false,
     "iconSize": 2,
     "gridVisible": true,
@@ -1162,31 +1162,6 @@
       },
       "scale": 0.2726269331663144
     },
-    "9e293cde-e27b-4902-808b-e884f3e9da32": {
-      "position": {
-        "x": 18.69547714116342,
-        "y": 18.695477141163416,
-        "z": 18.695477141163412
-      },
-      "rotation": {
-        "x": 0,
-        "y": 0,
-        "z": 0,
-        "w": 1
-      },
-      "viewCenter": {
-        "x": 0,
-        "y": 0,
-        "z": 0
-      },
-      "contentRect": {
-        "x": 0,
-        "y": 0,
-        "width": 910,
-        "height": 767
-      },
-      "scale": 1
-    },
     "7cef9a87-b169-4934-a57b-09eafc129e91": {
       "position": {
         "x": 0.012109347631565015,
@@ -1212,17 +1187,42 @@
       },
       "scale": 1
     },
+    "773de0b0-468b-4fbb-965c-36c47d7a4c94": {
+      "position": {
+        "x": 388.28292458659104,
+        "y": 801.5424013272149,
+        "z": -9.292243315024578
+      },
+      "rotation": {
+        "x": -0.11356746565431076,
+        "y": 0.8424965922432052,
+        "z": 0.19571416452957474,
+        "w": 0.4888741031610919
+      },
+      "viewCenter": {
+        "x": 386.12080174708495,
+        "y": 800.3193725941467,
+        "z": -8.056511080875442
+      },
+      "contentRect": {
+        "x": 0,
+        "y": 0,
+        "width": 910,
+        "height": 803
+      },
+      "scale": 1
+    },
     "19323c5d-5d36-438a-86ee-8288c690e5b0": {
       "position": {
-        "x": 369.82893642526386,
-        "y": 751.5737120963579,
-        "z": -0.5718896113230065
+        "x": 59.86583333333331,
+        "y": 127.52583333333331,
+        "z": 5000
       },
       "rotation": {
-        "x": -0.12114056972054042,
-        "y": 0.6534067333829727,
-        "z": 0.1020243030179468,
-        "w": 0.74025377049355
+        "x": 0,
+        "y": 0,
+        "z": 0,
+        "w": 1
       },
       "viewCenter": {
         "x": 0,
@@ -1230,18 +1230,18 @@
         "z": 0
       },
       "contentRect": {
-        "x": 498.5,
-        "y": 401.5,
-        "width": 997,
-        "height": 803
+        "x": 181.5,
+        "y": 383.49999999999994,
+        "width": 353,
+        "height": 745.8705234159779
       },
-      "scale": 1
+      "scale": 0.9724517906336089
     },
-    "be14c61f-22d8-4bb9-b444-ad9f29740469": {
+    "9e293cde-e27b-4902-808b-e884f3e9da32": {
       "position": {
-        "x": 815.5,
-        "y": 419.5,
-        "z": 4516.359472583968
+        "x": 937.5,
+        "y": 625,
+        "z": 5000
       },
       "rotation": {
         "x": 0,
@@ -1255,37 +1255,37 @@
         "z": 0
       },
       "contentRect": {
-        "x": 498.5,
-        "y": 401.5,
-        "width": 997,
-        "height": 803
+        "x": 0,
+        "y": 0,
+        "width": 1875,
+        "height": 1250
       },
       "scale": 1
     },
-    "773de0b0-468b-4fbb-965c-36c47d7a4c94": {
+    "be14c61f-22d8-4bb9-b444-ad9f29740469": {
       "position": {
-        "x": 394.4143581659065,
-        "y": 804.7300850803522,
-        "z": -2.9552028512709225
+        "x": 455,
+        "y": 401.5,
+        "z": 5000
       },
       "rotation": {
-        "x": -0.1085110381270196,
-        "y": 0.6718297764697909,
-        "z": 0.10044260185304525,
-        "w": 0.725797072042924
+        "x": 0,
+        "y": 0,
+        "z": 0,
+        "w": 1
       },
       "viewCenter": {
-        "x": 386.5799079406263,
-        "y": 802.3267750148132,
-        "z": -3.561137740268039
+        "x": 1059.1144884801104,
+        "y": -838.1545294454286,
+        "z": 131.66099660264535
       },
       "contentRect": {
-        "x": 498.5,
-        "y": 401.5,
-        "width": 997,
-        "height": 803
+        "x": 0,
+        "y": 0,
+        "width": 898.6674968866749,
+        "height": 793
       },
-      "scale": 1
+      "scale": 0.987546699875467
     }
   },
   "camera-uuids": [
@@ -1334,11 +1334,11 @@
     "02aebe80-4488-4c7d-9cc6-5b71a0f5351d",
     "f631c866-c36b-443f-a8c0-a895176b7610",
     "e4c2b613-d38f-42e1-9557-74a22acb2cdb",
-    "9e293cde-e27b-4902-808b-e884f3e9da32",
     "7cef9a87-b169-4934-a57b-09eafc129e91",
+    "773de0b0-468b-4fbb-965c-36c47d7a4c94",
     "19323c5d-5d36-438a-86ee-8288c690e5b0",
-    "be14c61f-22d8-4bb9-b444-ad9f29740469",
-    "773de0b0-468b-4fbb-965c-36c47d7a4c94"
+    "9e293cde-e27b-4902-808b-e884f3e9da32",
+    "be14c61f-22d8-4bb9-b444-ad9f29740469"
   ],
   "camera": {
     "color": [