using UnityEngine; namespace Coffee.UIExtensions { /// /// Unmask Raycast Filter. /// The ray passes through the unmasked rectangle. /// [AddComponentMenu("UI/Unmask/UnmaskRaycastFilter", 2)] public class UnmaskRaycastFilter : MonoBehaviour, ICanvasRaycastFilter { //################################ // Serialize Members. //################################ [Tooltip("Target unmask component. The ray passes through the unmasked rectangle.")] [SerializeField] private Unmask m_TargetUnmask; //################################ // Public Members. //################################ /// /// Target unmask component. Ray through the unmasked rectangle. /// public Unmask targetUnmask { get { return m_TargetUnmask; } set { m_TargetUnmask = value; } } /// /// Given a point and a camera is the raycast valid. /// /// Valid. /// Screen position. /// Raycast camera. public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera) { // Skip if deactived. if (!isActiveAndEnabled || !m_TargetUnmask || !m_TargetUnmask.isActiveAndEnabled) { return true; } // check inside if (eventCamera) { return !RectTransformUtility.RectangleContainsScreenPoint((m_TargetUnmask.transform as RectTransform), sp, eventCamera); } else { return !RectTransformUtility.RectangleContainsScreenPoint((m_TargetUnmask.transform as RectTransform), sp); } } //################################ // Private Members. //################################ /// /// This function is called when the object becomes enabled and active. /// void OnEnable() { } } }