-
Creator 版本: 3.5.1
-
目标平台: ipad safri
-
之前哪个版本是正常的: 3.4.2
在chrome预览没有问题,在windows自带得edge有小范围偏移
@requireComponent(PolygonCollider2D)
export class IrregularBtn extends Button {
public onLoad() {
(this.getComponent(UITransform) as any).oldHit = this.getComponent(UITransform).hitTest.bind(this.node);
this.getComponent(UITransform).hitTest = this.polygonHitTest.bind(this.node);
}
/**
* 不规则多边形检测
* @param {触摸点} point
* @param {监听} listener
*/
private polygonHitTest(point: Vec2, listener: EventListener) {
let polygonCollider = this.getComponent(PolygonCollider2D);
if (polygonCollider) {
let v3 = new Vec3(point.x, point.y, 0);
v3 = this.getComponent(UITransform).convertToNodeSpaceAR(v3);
let v2 = new Vec2(v3.x, v3.y);
return Intersection2D.pointInPolygon(v2, polygonCollider.points);
}
return (this.getComponent(UITransform) as any).oldHit(point, listener);
}
}
在更改预览的分辨率后 chrome也会出现大范围偏移
人工置顶!
asdasdasdasd
传进来的不是屏幕坐标么,不得转换成世界坐标再做检测
屏幕坐标转世界坐标:
camera.screenPointToRay // 支持透视模式
然后计算射线与 UITransform 平面交点 // 支持 3D 旋转后的节点
该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。