using System;
using System.Collections.Generic;
using UnityEngine.EventSystems;
using UnityEngine.Pool;
namespace UnityEngine.UI
{
[AddComponentMenu("UI/Rect Mask 2D", 14)]
[ExecuteAlways]
[DisallowMultipleComponent]
[RequireComponent(typeof(RectTransform))]
///
/// A 2D rectangular mask that allows for clipping / masking of areas outside the mask.
///
///
/// The RectMask2D behaves in a similar way to a standard Mask component. It differs though in some of the restrictions that it has.
/// A RectMask2D:
/// *Only works in the 2D plane
/// *Requires elements on the mask to be coplanar.
/// *Does not require stencil buffer / extra draw calls
/// *Requires fewer draw calls
/// *Culls elements that are outside the mask area.
///
public class RectMask2D : UIBehaviour, IClipper, ICanvasRaycastFilter
{
[NonSerialized]
private readonly RectangularVertexClipper m_VertexClipper = new RectangularVertexClipper();
[NonSerialized]
private RectTransform m_RectTransform;
[NonSerialized]
private HashSet m_MaskableTargets = new HashSet();
[NonSerialized]
private HashSet m_ClipTargets = new HashSet();
[NonSerialized]
private bool m_ShouldRecalculateClipRects;
[NonSerialized]
private List m_Clippers = new List();
[NonSerialized]
private Rect m_LastClipRectCanvasSpace;
[NonSerialized]
private bool m_ForceClip;
[SerializeField]
private Vector4 m_Padding = new Vector4();
///
/// Padding to be applied to the masking
/// X = Left
/// Y = Bottom
/// Z = Right
/// W = Top
///
public Vector4 padding
{
get { return m_Padding; }
set
{
m_Padding = value;
MaskUtilities.Notify2DMaskStateChanged(this);
}
}
[SerializeField]
private Vector2Int m_Softness;
///
/// The softness to apply to the horizontal and vertical axis.
///
public Vector2Int softness
{
get { return m_Softness; }
set
{
m_Softness.x = Mathf.Max(0, value.x);
m_Softness.y = Mathf.Max(0, value.y);
MaskUtilities.Notify2DMaskStateChanged(this);
}
}
///
/// Returns a non-destroyed instance or a null reference.
///
[NonSerialized] private Canvas m_Canvas;
internal Canvas Canvas
{
get
{
if (m_Canvas == null)
{
var list = ListPool