Unity 重写image的点击区域

目前看网上所说的更改image的重写区域主要是通过更改对比的阈值,这种情况只适合,含有透明区域的image
image.alphaHitTestMinimumThreshold = alpahThreshold;

最近公司需求只对标签上方的一片区域点击,但是ui切图的时候没有分成两部分,时间又比较紧张,只有自己去重写image的可点击区域了,大概思路是把屏幕坐标转化为image的ui坐标,在通过判断点的y值来取上方的可点击区域

public override bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
{

    if (sprite.name == "btn")
    {
        RectTransformUtility.ScreenPointToLocalPointInRectangle(GetComponent<RectTransform>(), screenPoint, eventCamera, out screenPoint);
        return base.IsRaycastLocationValid(screenPoint, eventCamera) && (screenPoint.y >0);
        Debug.Log(screenPoint);

    }
    else
    {
        return base.IsRaycastLocationValid(screenPoint, eventCamera);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值