兼容其他版本hitTest的逻辑

This commit is contained in:
xu_yanfeng 2025-01-25 17:44:39 +08:00
parent 3118b86286
commit ef970e9d4c
3 changed files with 19 additions and 4 deletions

View File

@ -65,7 +65,7 @@ export class HintAdapter {
let node = new cc.Node("draw-node"); let node = new cc.Node("draw-node");
const canvas = cc.find("Canvas"); const canvas = cc.find("Canvas");
this.addDraw(scene, canvas, node); this.addDraw(scene, canvas, node);
this.draw = node.addComponent(cc.Graphics); this.draw = node.addComponent(cc.Graphics || cc.GraphicsComponent);
} }
public isDrawValid() { public isDrawValid() {
return this.draw && this.draw.isValid; return this.draw && this.draw.isValid;

View File

@ -8,8 +8,23 @@ export class HintV3 extends HintAdapter {
node.setSiblingIndex(len); node.setSiblingIndex(len);
} }
hitTest(node: any, x: number, y: number): boolean { hitTest(node: any, x: number, y: number): boolean {
let b = node._uiProps?.uiTransformComp?.hitTest({ x, y }, 0); let hitTest = null;
// hitTest = node._uiProps?.uiTransformComp?.hitTest;
const tr = node.getComponent(cc.UITransformComponent || cc.UITransform);
if (tr) {
if (tr.hitTest) {
hitTest = tr.hitTest.bind(tr);
} else if (tr.isHit) {
// TODO: 3.3.1使用的是这个接口hitTest有问题有人反馈再说修复老版本暂不花费太多精力
hitTest = tr.isHit.bind(tr);
}
}
if (hitTest) {
let b = hitTest({ x, y }, 0);
return b; return b;
} else {
return false;
}
} }
convertMousePos(event: MouseEvent, canvas: HTMLCanvasElement): { x: number; y: number } { convertMousePos(event: MouseEvent, canvas: HTMLCanvasElement): { x: number; y: number } {
const rect = canvas.getBoundingClientRect(); const rect = canvas.getBoundingClientRect();

View File

@ -89,7 +89,7 @@ export class Hint {
this.cleanSelected(); this.cleanSelected();
const nodes = this.getMouseNodes(event, canvas); const nodes = this.getMouseNodes(event, canvas);
const pickTop = toRaw(appStore().config.pickTop); const pickTop = toRaw(appStore().config.pickTop);
if (nodes.length === 1 || pickTop) { if (nodes.length === 1 || (pickTop && nodes.length)) {
const item = nodes[0]; const item = nodes[0];
this.cleanHover(); this.cleanHover();
this.setSelected(item); this.setSelected(item);