|
|
|
|
@ -200,7 +200,7 @@ export class MapDigChestHost { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 挂宝箱到地图根(与格子锁同层),对齐格子世界坐标,避免被字块层挡住。 |
|
|
|
|
* 挂宝箱到 MapManager 根(勿挂「格子」:该节点有 Layout,多一个子节点会整图重排偏移)。 |
|
|
|
|
* @param slot 宝箱槽 |
|
|
|
|
* @param grid 格子 |
|
|
|
|
*/ |
|
|
|
|
@ -210,13 +210,13 @@ export class MapDigChestHost { |
|
|
|
|
console.warn('[MapDigChestHost] 格子节点无效,无法挂宝箱', grid.Index); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const mapRoot = this._map?.mapGridParent; |
|
|
|
|
if (!mapRoot?.isValid) { |
|
|
|
|
console.warn('[MapDigChestHost] mapGridParent 无效,无法挂宝箱', grid.Index); |
|
|
|
|
const tipLayer = this._tipLayer(); |
|
|
|
|
if (!tipLayer?.isValid) { |
|
|
|
|
console.warn('[MapDigChestHost] 宝箱挂点无效', grid.Index); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (slot.tip?.isValid) { |
|
|
|
|
this._placeTipOnMap(slot.tip, cell, mapRoot); |
|
|
|
|
this._placeTipOnMap(slot.tip, cell, tipLayer); |
|
|
|
|
this._resetTipVisual(slot.tip); |
|
|
|
|
slot.tip.active = true; |
|
|
|
|
return; |
|
|
|
|
@ -230,38 +230,52 @@ export class MapDigChestHost { |
|
|
|
|
console.warn('[MapDigChestHost] 缺少宝箱预制体', CHEST_TIP_NAME); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this._placeTipOnMap(tip, cell, mapRoot); |
|
|
|
|
this._placeTipOnMap(tip, cell, tipLayer); |
|
|
|
|
this._resetTipVisual(tip); |
|
|
|
|
tip.active = true; |
|
|
|
|
slot.tip = tip; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 宝箱 tip 层:MapManager 根下独立节点,压在「格子」之上、不受 Layout 影响。 |
|
|
|
|
*/ |
|
|
|
|
private _tipLayer(): Node | null { |
|
|
|
|
const map = this._map; |
|
|
|
|
if (!map?.node?.isValid) return null; |
|
|
|
|
let layer = map.node.getChildByName('宝箱提示层'); |
|
|
|
|
if (layer?.isValid) return layer; |
|
|
|
|
layer = new Node('宝箱提示层'); |
|
|
|
|
layer.layer = map.node.layer; |
|
|
|
|
layer.parent = map.node; |
|
|
|
|
const grids = map.mapGridParent; |
|
|
|
|
if (grids?.isValid) { |
|
|
|
|
layer.setSiblingIndex(grids.getSiblingIndex() + 1); |
|
|
|
|
} else { |
|
|
|
|
layer.setSiblingIndex(map.node.children.length - 1); |
|
|
|
|
} |
|
|
|
|
return layer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param tip 宝箱节点 |
|
|
|
|
* @param cell 格子节点 |
|
|
|
|
* @param mapRoot 地图格子父节点 |
|
|
|
|
* @param tipLayer 宝箱提示层 |
|
|
|
|
*/ |
|
|
|
|
private _placeTipOnMap(tip: Node, cell: Node, mapRoot: Node): void { |
|
|
|
|
tip.parent = mapRoot; |
|
|
|
|
tip.setSiblingIndex(mapRoot.children.length - 1); |
|
|
|
|
private _placeTipOnMap(tip: Node, cell: Node, tipLayer: Node): void { |
|
|
|
|
tip.parent = tipLayer; |
|
|
|
|
tip.setSiblingIndex(tipLayer.children.length - 1); |
|
|
|
|
cell.getWorldPosition(_tipWorld); |
|
|
|
|
const ut = mapRoot.getComponent(UITransform); |
|
|
|
|
if (ut) { |
|
|
|
|
ut.convertToNodeSpaceAR(_tipWorld, _tipLocal); |
|
|
|
|
tip.setPosition(_tipLocal); |
|
|
|
|
} else { |
|
|
|
|
tip.setWorldPosition(_tipWorld); |
|
|
|
|
} |
|
|
|
|
const ut = tipLayer.getComponent(UITransform) ?? tipLayer.addComponent(UITransform); |
|
|
|
|
ut.convertToNodeSpaceAR(_tipWorld, _tipLocal); |
|
|
|
|
tip.setPosition(_tipLocal); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** 对象池取出后复位显隐(飞入曾关 bg / 改 opacity) */ |
|
|
|
|
/** 对象池取出后复位显隐(飞入曾改 scale / opacity) */ |
|
|
|
|
private _resetTipVisual(tip: Node): void { |
|
|
|
|
tip.setScale(1, 1, 1); |
|
|
|
|
const bg = tip.getChildByName('bg'); |
|
|
|
|
if (bg?.isValid) bg.active = true; |
|
|
|
|
const box = tip.getChildByName('box'); |
|
|
|
|
if (box?.isValid) box.active = true; |
|
|
|
|
let op = tip.getComponent(UIOpacity); |
|
|
|
|
const op = tip.getComponent(UIOpacity); |
|
|
|
|
if (op) op.opacity = 255; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|