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);
}
}
}
网友评论