using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
namespace UnityEngine.UI
{
[AddComponentMenu("Event/Graphic Raycaster")]
[RequireComponent(typeof(Canvas))]
///
/// A derived BaseRaycaster to raycast against Graphic elements.
///
public class GraphicRaycaster : BaseRaycaster
{
protected const int kNoEventMaskSet = -1;
///
/// Type of raycasters to check against to check for canvas blocking elements.
///
public enum BlockingObjects
{
///
/// Perform no raycasts.
///
None = 0,
///
/// Perform a 2D raycast check to check for blocking 2D elements
///
TwoD = 1,
///
/// Perform a 3D raycast check to check for blocking 3D elements
///
ThreeD = 2,
///
/// Perform a 2D and a 3D raycasts to check for blocking 2D and 3D elements.
///
All = 3,
}
///
/// Priority of the raycaster based upon sort order.
///
///
/// The sortOrder priority.
///
public override int sortOrderPriority
{
get
{
// We need to return the sorting order here as distance will all be 0 for overlay.
if (canvas.renderMode == RenderMode.ScreenSpaceOverlay)
return canvas.sortingOrder;
return base.sortOrderPriority;
}
}
///
/// Priority of the raycaster based upon render order.
///
///
/// The renderOrder priority.
///
public override int renderOrderPriority
{
get
{
// We need to return the sorting order here as distance will all be 0 for overlay.
if (canvas.renderMode == RenderMode.ScreenSpaceOverlay)
return canvas.rootCanvas.renderOrder;
return base.renderOrderPriority;
}
}
[FormerlySerializedAs("ignoreReversedGraphics")]
[SerializeField]
private bool m_IgnoreReversedGraphics = true;
[FormerlySerializedAs("blockingObjects")]
[SerializeField]
private BlockingObjects m_BlockingObjects = BlockingObjects.None;
///
/// Whether Graphics facing away from the raycaster are checked for raycasts.
///
public bool ignoreReversedGraphics { get {return m_IgnoreReversedGraphics; } set { m_IgnoreReversedGraphics = value; } }
///
/// The type of objects that are checked to determine if they block graphic raycasts.
///
public BlockingObjects blockingObjects { get {return m_BlockingObjects; } set { m_BlockingObjects = value; } }
[SerializeField]
protected LayerMask m_BlockingMask = kNoEventMaskSet;
///
/// The type of objects specified through LayerMask that are checked to determine if they block graphic raycasts.
///
public LayerMask blockingMask { get { return m_BlockingMask; } set { m_BlockingMask = value; } }
private Canvas m_Canvas;
protected GraphicRaycaster()
{}
private Canvas canvas
{
get
{
if (m_Canvas != null)
return m_Canvas;
m_Canvas = GetComponent