Files
BH3/Assets/Scripts/Assembly-CSharp/RaycastMask.cs
2025-08-13 09:26:42 +08:00

23 lines
620 B
C#

using UnityEngine;
[RequireComponent(typeof(RectTransform), typeof(Collider2D))]
public class RaycastMask : MonoBehaviour, ICanvasRaycastFilter
{
private Collider2D myCollider;
private RectTransform rectTransform;
private void Awake()
{
myCollider = GetComponent<Collider2D>();
rectTransform = GetComponent<RectTransform>();
}
public bool IsRaycastLocationValid(Vector2 screenPos, Camera eventCamera)
{
Vector3 worldPoint = Vector3.zero;
RectTransformUtility.ScreenPointToWorldPointInRectangle(rectTransform, screenPos, eventCamera, out worldPoint);
return myCollider.OverlapPoint(worldPoint);
}
}