美文网首页unity3D技术分享UGUI
ugui不规则按钮点击检测

ugui不规则按钮点击检测

作者: 好怕怕 | 来源:发表于2019-02-28 13:29 被阅读6次
image.png
using UnityEngine;
using UnityEngine.UI;

[ExecuteInEditMode]
public class NewImage : Image
{
    private new Collider2D collider;

    protected override void Start()
    {
        var c2d = GetComponent<Collider2D>();
        if (c2d != null)
            collider = c2d;
        base.Start();
    }

    public override bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
    {
        if (!raycastTarget)
            return false;
        if (collider != null)
        {
            var worldPoint = Vector3.zero;
            var isInside = RectTransformUtility.ScreenPointToWorldPointInRectangle(
                rectTransform,
                sp,
                eventCamera,
                out worldPoint);
            if (isInside)
                isInside = collider.OverlapPoint(worldPoint);
            return isInside;
        }
        else
        {
            return base.IsRaycastLocationValid(sp, eventCamera);
        }
    }
}

相关文章

网友评论

    本文标题:ugui不规则按钮点击检测

    本文链接:https://www.haomeiwen.com/subject/jqkhyqtx.html