woso_javan il y a 1 mois
Parent
commit
7e57873a9e

+ 19 - 19
assets/module_aliens/Script/Components/RadarComponent.ts

@@ -1,7 +1,8 @@
-import { _decorator, Component, Node, Vec3 } from 'cc';
+import { _decorator, Camera, Component, Node, UITransform, Vec3, view } from 'cc';
 import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
 import { GameEvent } from '../Enum/GameEvent';
 import { AliensGlobalInstance } from '../AliensGlobalInstance';
+import { GameUtil } from '../GameUtil';
 const { ccclass, property } = _decorator;
 
 @ccclass('RadarComponent')
@@ -25,38 +26,37 @@ export class RadarComponent extends Component {
     private async onRadar(){
         this.node.active = true;
 
+        //获取相机
+        const camera = await this.getSceneCamera();
         //获取目标节点
         this._targetNode = await this.getTargetNode();
         
-        // 添加雷达显示逻辑
         if(this._targetNode){
-            // 计算目标节点在3D世界中的位置
-            const targetPos = this._targetNode.worldPosition;
+            const battleUI = AliensGlobalInstance.instance.battleUI;
+            const localPos = GameUtil.worldToScreenLocal(this._targetNode,battleUI,camera);
             
-            // 将3D坐标转换为2D雷达坐标 (500x500范围内)
-            const radarPos = new Vec3(
-                (targetPos.x / 10) * 250 + 250,  // 将x坐标映射到0-500范围
-                (targetPos.z / 10) * 250 + 250,  // 将z坐标映射到0-500范围
-                0
-            );
-            
-            // 限制在雷达范围内
-            radarPos.x = Math.max(0, Math.min(500, radarPos.x));
-            radarPos.y = Math.max(0, Math.min(500, radarPos.y));
-            
-            // 移动雷达指示器到目标位置
-            this.node.setPosition(Vec3.ZERO);
+            // 移动雷达指示器
+            this.node.setPosition(localPos);
         }
     }
 
-    // ... 其他代码保持不变 ...
+    private async getSceneCamera() :Promise<Camera>{
+        return new Promise<Camera>((resolve, reject) => {
+            const levelNode = AliensGlobalInstance.instance.levels.children[0];
+            if(!levelNode){return;}
+
+            const camera = levelNode.getComponentInChildren(Camera)!;
+            resolve(camera);
+        });
+    }
 
     //获取目标节点
     private  async getTargetNode():Promise<Node> {
         return new Promise<Node>((resolve, reject) => {
             const levelNode = AliensGlobalInstance.instance.levels.children[0];
             const et = levelNode.getChildByName('et');
-            resolve(et.children[Math.floor(Math.random() * et.children.length)]);
+            // resolve(et.children[Math.floor(Math.random() * et.children.length)]);
+            resolve(et.children[1]);
         });
     }
 

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

@@ -128,7 +128,7 @@ export class ScreenShotComponent extends Component {
     public saveCameraState(pos:Vec3,rotation:Vec3){
         this._originalCameraPosition = pos;
         this._originalCameraRotation = rotation;
-        console.log('保存相机最新的位置和旋转角度:',pos,',',rotation);
+        // console.log('保存相机最新的位置和旋转角度:',pos,',',rotation);
     }
 
     protected onDestroy(): void {

+ 11 - 1
assets/module_aliens/Script/GameUtil.ts

@@ -1,4 +1,5 @@
-import { Vec2, Node, v2, PolygonCollider2D, Rect, CircleCollider2D } from "cc";
+import { Vec2, Node, v2, PolygonCollider2D, Rect, CircleCollider2D, Vec3, UITransform, Camera } from "cc";
+import { AliensGlobalInstance } from "./AliensGlobalInstance";
 
 /** 游戏工具类 */
 export class GameUtil {
@@ -207,6 +208,15 @@ export class GameUtil {
         return false;
     }
 
+    /** 3D空间坐标转屏幕坐标*/
+    static worldToScreenLocal( target: Node, localNode: Node,carmera?:Camera,): Vec3 {
+        if (!target || !target.worldPosition) return;
+        const mainCamera = carmera ?? AliensGlobalInstance.instance.camera;
+        let uiPos = new Vec3();
+        mainCamera.convertToUINode(target.worldPosition.clone(), localNode, uiPos);
+        return uiPos;
+    }
+
     static delay(seconds) {
         return new Promise(resolve => setTimeout(resolve, seconds * 1000));
     }

+ 99 - 66
assets/module_aliens/rooster_aliens.scene

@@ -23,7 +23,7 @@
     "_active": true,
     "_components": [],
     "_prefab": {
-      "__id__": 153
+      "__id__": 154
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -54,7 +54,7 @@
     },
     "autoReleaseAssets": false,
     "_globals": {
-      "__id__": 154
+      "__id__": 155
     },
     "_id": "be14c61f-22d8-4bb9-b444-ad9f29740469"
   },
@@ -74,17 +74,14 @@
         "__id__": 7
       },
       {
-        "__id__": 145
+        "__id__": 146
       },
       {
-        "__id__": 147
+        "__id__": 148
       }
     ],
     "_active": true,
     "_components": [
-      {
-        "__id__": 149
-      },
       {
         "__id__": 150
       },
@@ -93,6 +90,9 @@
       },
       {
         "__id__": 152
+      },
+      {
+        "__id__": 153
       }
     ],
     "_prefab": null,
@@ -279,16 +279,16 @@
         "__id__": 41
       },
       {
-        "__id__": 126
+        "__id__": 127
       }
     ],
     "_active": true,
     "_components": [
       {
-        "__id__": 143
+        "__id__": 144
       },
       {
-        "__id__": 144
+        "__id__": 145
       }
     ],
     "_prefab": null,
@@ -1691,6 +1691,9 @@
     "_components": [
       {
         "__id__": 125
+      },
+      {
+        "__id__": 126
       }
     ],
     "_prefab": null,
@@ -1757,8 +1760,8 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": -240,
-      "y": -600,
+      "x": -270,
+      "y": -626.246,
       "z": 0
     },
     "_lrot": {
@@ -2626,7 +2629,7 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 150.00000000000003,
+      "width": 100,
       "height": 250
     },
     "_anchorPoint": {
@@ -2646,12 +2649,12 @@
     },
     "_enabled": true,
     "__prefab": null,
-    "_alignFlags": 44,
+    "_alignFlags": 12,
     "_target": null,
-    "_left": -265,
-    "_right": 214.99999999999997,
+    "_left": 60,
+    "_right": 330,
     "_top": 0,
-    "_bottom": -675,
+    "_bottom": 48.75400000000002,
     "_horizontalCenter": 0,
     "_verticalCenter": 0,
     "_isAbsLeft": true,
@@ -4968,8 +4971,8 @@
     "__prefab": null,
     "_contentSize": {
       "__type__": "cc.Size",
-      "width": 100,
-      "height": 100
+      "width": 760,
+      "height": 1600
     },
     "_anchorPoint": {
       "__type__": "cc.Vec2",
@@ -4978,6 +4981,36 @@
     },
     "_id": "13P5y4zgREz60HltnUw7hr"
   },
+  {
+    "__type__": "cc.Widget",
+    "_name": "",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "node": {
+      "__id__": 41
+    },
+    "_enabled": true,
+    "__prefab": null,
+    "_alignFlags": 45,
+    "_target": null,
+    "_left": 0,
+    "_right": 0,
+    "_top": 0,
+    "_bottom": 0,
+    "_horizontalCenter": 0,
+    "_verticalCenter": 0,
+    "_isAbsLeft": true,
+    "_isAbsRight": true,
+    "_isAbsTop": true,
+    "_isAbsBottom": true,
+    "_isAbsHorizontalCenter": true,
+    "_isAbsVerticalCenter": true,
+    "_originalWidth": 100,
+    "_originalHeight": 100,
+    "_alignMode": 2,
+    "_lockFlags": 0,
+    "_id": "d5+nxbYApEhIWEjdW6vJHb"
+  },
   {
     "__type__": "cc.Node",
     "_name": "TopLeft",
@@ -4988,22 +5021,22 @@
     },
     "_children": [
       {
-        "__id__": 127
+        "__id__": 128
       },
       {
-        "__id__": 131
+        "__id__": 132
       },
       {
-        "__id__": 135
+        "__id__": 136
       }
     ],
     "_active": true,
     "_components": [
       {
-        "__id__": 141
+        "__id__": 142
       },
       {
-        "__id__": 142
+        "__id__": 143
       }
     ],
     "_prefab": null,
@@ -5042,19 +5075,19 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
-      "__id__": 126
+      "__id__": 127
     },
     "_children": [],
     "_active": true,
     "_components": [
-      {
-        "__id__": 128
-      },
       {
         "__id__": 129
       },
       {
         "__id__": 130
+      },
+      {
+        "__id__": 131
       }
     ],
     "_prefab": null,
@@ -5093,7 +5126,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 127
+      "__id__": 128
     },
     "_enabled": true,
     "__prefab": null,
@@ -5115,7 +5148,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 127
+      "__id__": 128
     },
     "_enabled": true,
     "__prefab": null,
@@ -5154,7 +5187,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 127
+      "__id__": 128
     },
     "_enabled": true,
     "__prefab": null,
@@ -5196,7 +5229,7 @@
     "_duration": 0.1,
     "_zoomScale": 1.2,
     "_target": {
-      "__id__": 127
+      "__id__": 128
     },
     "_id": "51Zwo4GTBBT7vNI+1Aij5E"
   },
@@ -5206,19 +5239,19 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
-      "__id__": 126
+      "__id__": 127
     },
     "_children": [],
     "_active": true,
     "_components": [
-      {
-        "__id__": 132
-      },
       {
         "__id__": 133
       },
       {
         "__id__": 134
+      },
+      {
+        "__id__": 135
       }
     ],
     "_prefab": null,
@@ -5257,7 +5290,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 131
+      "__id__": 132
     },
     "_enabled": true,
     "__prefab": null,
@@ -5279,7 +5312,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 131
+      "__id__": 132
     },
     "_enabled": true,
     "__prefab": null,
@@ -5318,7 +5351,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 131
+      "__id__": 132
     },
     "_enabled": true,
     "__prefab": null,
@@ -5360,7 +5393,7 @@
     "_duration": 0.1,
     "_zoomScale": 1.2,
     "_target": {
-      "__id__": 131
+      "__id__": 132
     },
     "_id": "ec3qEoJHVABoxGd3CvrvsV"
   },
@@ -5370,20 +5403,20 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
-      "__id__": 126
+      "__id__": 127
     },
     "_children": [
       {
-        "__id__": 136
+        "__id__": 137
       }
     ],
     "_active": false,
     "_components": [
       {
-        "__id__": 139
+        "__id__": 140
       },
       {
-        "__id__": 140
+        "__id__": 141
       }
     ],
     "_prefab": null,
@@ -5422,16 +5455,16 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "_parent": {
-      "__id__": 135
+      "__id__": 136
     },
     "_children": [],
     "_active": true,
     "_components": [
       {
-        "__id__": 137
+        "__id__": 138
       },
       {
-        "__id__": 138
+        "__id__": 139
       }
     ],
     "_prefab": null,
@@ -5470,7 +5503,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 136
+      "__id__": 137
     },
     "_enabled": true,
     "__prefab": null,
@@ -5492,7 +5525,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 136
+      "__id__": 137
     },
     "_enabled": true,
     "__prefab": null,
@@ -5531,7 +5564,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 135
+      "__id__": 136
     },
     "_enabled": true,
     "__prefab": null,
@@ -5553,7 +5586,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 135
+      "__id__": 136
     },
     "_enabled": true,
     "__prefab": null,
@@ -5592,7 +5625,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 126
+      "__id__": 127
     },
     "_enabled": true,
     "__prefab": null,
@@ -5614,7 +5647,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 126
+      "__id__": 127
     },
     "_enabled": true,
     "__prefab": null,
@@ -5702,7 +5735,7 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 146
+        "__id__": 147
       }
     ],
     "_prefab": null,
@@ -5741,7 +5774,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 145
+      "__id__": 146
     },
     "_enabled": true,
     "__prefab": null,
@@ -5759,7 +5792,7 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 148
+        "__id__": 149
       }
     ],
     "_prefab": null,
@@ -5798,7 +5831,7 @@
     "_objFlags": 0,
     "__editorExtras__": {},
     "node": {
-      "__id__": 147
+      "__id__": 148
     },
     "_enabled": true,
     "__prefab": null,
@@ -5871,7 +5904,7 @@
     "_enabled": true,
     "__prefab": null,
     "_cameraComponent": {
-      "__id__": 148
+      "__id__": 149
     },
     "_alignCanvasWithScreen": true,
     "_id": "8fdCZBLJNAnL3sNZ4vacOF"
@@ -5934,28 +5967,28 @@
   {
     "__type__": "cc.SceneGlobals",
     "ambient": {
-      "__id__": 155
+      "__id__": 156
     },
     "shadows": {
-      "__id__": 156
+      "__id__": 157
     },
     "_skybox": {
-      "__id__": 157
+      "__id__": 158
     },
     "fog": {
-      "__id__": 158
+      "__id__": 159
     },
     "octree": {
-      "__id__": 159
+      "__id__": 160
     },
     "skin": {
-      "__id__": 160
+      "__id__": 161
     },
     "lightProbeInfo": {
-      "__id__": 161
+      "__id__": 162
     },
     "postSettings": {
-      "__id__": 162
+      "__id__": 163
     },
     "bakedWithStationaryMainLight": false,
     "bakedWithHighpLightmap": false

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

@@ -5,7 +5,7 @@
     "__version__": "1.3.7"
   },
   "gizmos-infos": {
-    "is2D": true,
+    "is2D": false,
     "is3DIcon": false,
     "iconSize": 2,
     "gridVisible": true,
@@ -1189,24 +1189,24 @@
     },
     "773de0b0-468b-4fbb-965c-36c47d7a4c94": {
       "position": {
-        "x": 411.01934092956697,
-        "y": 820.6641897670065,
-        "z": 50.3246859691244
+        "x": 431.86215816746943,
+        "y": 812.6860704208086,
+        "z": 52.116033922381774
       },
       "rotation": {
-        "x": -0.06510690440143116,
-        "y": 0.4719321252688432,
-        "z": 0.03495962636648062,
-        "w": 0.8785322900513173
+        "x": -0.08661488124250181,
+        "y": 0.3156171372989233,
+        "z": 0.028942770208700834,
+        "w": 0.9444818690918456
       },
       "viewCenter": {
-        "x": 402.7369806244665,
-        "y": 819.1838618159672,
-        "z": 44.840202540252164
+        "x": 391.98606560893705,
+        "y": 800.4177270306443,
+        "z": -0.8857028290700697
       },
       "contentRect": {
-        "x": 105.98900899144161,
-        "y": 628.4885731435231,
+        "x": -670.4524966662218,
+        "y": -228.60821357276177,
         "width": 0,
         "height": 0
       },
@@ -1214,15 +1214,15 @@
     },
     "19323c5d-5d36-438a-86ee-8288c690e5b0": {
       "position": {
-        "x": 32.711095544459724,
-        "y": 32.711095544459724,
-        "z": 32.711095544459724
+        "x": 51.31333333333333,
+        "y": 109.21999999999997,
+        "z": 5000
       },
       "rotation": {
-        "x": -0.27984814233312133,
-        "y": 0.3647051996310009,
-        "z": 0.11591689595929512,
-        "w": 0.8804762392171493
+        "x": 0,
+        "y": 0,
+        "z": 0,
+        "w": 1
       },
       "viewCenter": {
         "x": 0,
@@ -1230,24 +1230,24 @@
         "z": 0
       },
       "contentRect": {
-        "x": 0,
-        "y": 0,
-        "width": 360,
-        "height": 760
+        "x": 180,
+        "y": 380,
+        "width": 350,
+        "height": 738.8888888888889
       },
-      "scale": 1
+      "scale": 0.9722222222222222
     },
     "9e293cde-e27b-4902-808b-e884f3e9da32": {
       "position": {
-        "x": 19.01828321567183,
-        "y": 19.01828321567183,
-        "z": 19.018283215671822
+        "x": 180,
+        "y": 380.00000000000006,
+        "z": 5000
       },
       "rotation": {
-        "x": -0.0029155834895458446,
-        "y": 0.0037996623802130465,
-        "z": 0.0012076742236009639,
-        "w": 0.999987801656441
+        "x": 0,
+        "y": 0,
+        "z": 0,
+        "w": 1
       },
       "viewCenter": {
         "x": 0,
@@ -1257,16 +1257,16 @@
       "contentRect": {
         "x": 0,
         "y": 0,
-        "width": 360,
-        "height": 760
+        "width": 350,
+        "height": 738.8888888888889
       },
-      "scale": 1
+      "scale": 0.9722222222222222
     },
     "be14c61f-22d8-4bb9-b444-ad9f29740469": {
       "position": {
-        "x": 521.1868363942143,
-        "y": 820.0746173321463,
-        "z": 3650.261607632924
+        "x": 361,
+        "y": 398.49999999999994,
+        "z": 5000
       },
       "rotation": {
         "x": 0,
@@ -1275,17 +1275,17 @@
         "w": 1
       },
       "viewCenter": {
-        "x": 62.878345440342855,
-        "y": 964.7401327016873,
-        "z": -431.29053934684
+        "x": 369.184,
+        "y": 803.2222222222223,
+        "z": 1.647
       },
       "contentRect": {
         "x": 0,
         "y": 0,
-        "width": 360,
-        "height": 760
+        "width": 712,
+        "height": 785.9612188365651
       },
-      "scale": 1
+      "scale": 0.9861495844875346
     }
   },
   "camera-uuids": [

+ 1 - 1
temp/startup.json

@@ -1 +1 @@
-{"pid":3528}
+{"pid":24204}

+ 1 - 1
temp/tsconfig.cocos.json

@@ -5,9 +5,9 @@
     "module": "ES2015",
     "strict": true,
     "types": [
+      "./temp/declarations/cc.custom-macro",
       "./temp/declarations/cc",
       "./temp/declarations/jsb",
-      "./temp/declarations/cc.custom-macro",
       "./temp/declarations/cc.env"
     ],
     "paths": {