|
@@ -4,6 +4,9 @@ import { assetManager, instantiate, Prefab, Node, UITransform, Vec3, Vec2, view
|
|
|
import { resLoader } from "db://assets/core_tgx/base/ResLoader";
|
|
|
import { StormSunderGlobalInstance } from "../StormSunderGlobalInstance";
|
|
|
import { BloodComponent } from "../Component/BloodComponent";
|
|
|
+import { PlayerInfo, PlayerInfoComponent } from "../Component/PlayerInfoComponent";
|
|
|
+import { TornadoComponent } from "../Component/TornadoComponent";
|
|
|
+import { GameUtil } from "../GameUtil";
|
|
|
|
|
|
export class Effect2DUIMgr {
|
|
|
private static _instance: Effect2DUIMgr;
|
|
@@ -20,6 +23,7 @@ export class Effect2DUIMgr {
|
|
|
|
|
|
private bloodMap: Map<Node, Node> = new Map(); // 存储节点与对应血条的映射
|
|
|
private playerInfoMap: Map<Node, Node> = new Map(); // 存储节点与玩家信息的映射
|
|
|
+
|
|
|
async showBlood(target: Node, hpPercent: number) {
|
|
|
let bloodNode = this.bloodMap.get(target) as any;
|
|
|
|
|
@@ -36,18 +40,10 @@ export class Effect2DUIMgr {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 转换 3D 坐标到屏幕坐标
|
|
|
- const targetWorldPos = target.worldPosition;
|
|
|
- const screenPos = mainCamera.worldToScreen(targetWorldPos);
|
|
|
- const uiPos = new Vec3();
|
|
|
- StormSunderGlobalInstance.instance.bloodUI.getComponent(UITransform)!.convertToNodeSpaceAR(
|
|
|
- new Vec3(screenPos.x, screenPos.y, 0),
|
|
|
- uiPos
|
|
|
- );
|
|
|
-
|
|
|
+ const uiPos = GameUtil.worldToScreenLocal(target).clone();
|
|
|
// 设置位置偏移
|
|
|
- const offsetY = 300;
|
|
|
- const offsetX = 150;
|
|
|
+ const offsetY = 200;
|
|
|
+ const offsetX = 100;
|
|
|
bloodNode.setPosition(uiPos.x + offsetX, uiPos.y + offsetY);
|
|
|
|
|
|
// 更新血量显示
|
|
@@ -57,6 +53,28 @@ export class Effect2DUIMgr {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //添加玩家预设
|
|
|
+ async addPlayerInfo(target: Node, playerInfo: PlayerInfo) {
|
|
|
+ let infoNode = this.playerInfoMap.get(target) as any;
|
|
|
+
|
|
|
+ if (!infoNode) {
|
|
|
+ const infoPrefab = await resLoader.loadAsync(resLoader.gameBundleName, "Prefabs/PlayerInfo");
|
|
|
+ infoNode = instantiate(infoPrefab);
|
|
|
+ infoNode.parent = StormSunderGlobalInstance.instance.effectUI;
|
|
|
+ this.playerInfoMap.set(target, infoNode);
|
|
|
+
|
|
|
+ const playerInfoComp = infoNode.getComponent(PlayerInfoComponent);
|
|
|
+ if (playerInfoComp) {
|
|
|
+ playerInfoComp.updateInfo(playerInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const uiPos = GameUtil.worldToScreenLocal(target).clone();
|
|
|
+ const offsetY = 250;
|
|
|
+ const offsetX = 70;
|
|
|
+ infoNode.setPosition(uiPos.x + offsetX, uiPos.y + offsetY);
|
|
|
+ }
|
|
|
+
|
|
|
// 清理血条
|
|
|
removeBlood(target: Node) {
|
|
|
const bloodNode = this.bloodMap.get(target);
|
|
@@ -65,5 +83,14 @@ export class Effect2DUIMgr {
|
|
|
this.bloodMap.delete(target);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 清理玩家信息节点
|
|
|
+ removePlayerInfo(target: Node) {
|
|
|
+ const infoNode = this.playerInfoMap.get(target);
|
|
|
+ if (infoNode) {
|
|
|
+ infoNode.destroy();
|
|
|
+ this.playerInfoMap.delete(target);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|