namespace UnityEngine.EventSystems
{
///
/// A hit result from a BaseRaycaster.
///
public struct RaycastResult
{
private GameObject m_GameObject; // Game object hit by the raycast
///
/// The GameObject that was hit by the raycast.
///
public GameObject gameObject
{
get { return m_GameObject; }
set { m_GameObject = value; }
}
///
/// BaseRaycaster that raised the hit.
///
public BaseRaycaster module;
///
/// Distance to the hit.
///
public float distance;
///
/// Hit index
///
public float index;
///
/// Used by raycasters where elements may have the same unit distance, but have specific ordering.
///
public int depth;
///
/// The sorting group ID when the hit object is influenced by a SortingGroup.
///
///
/// For UI.Graphic elements will always be 0.
/// For 3D objects this will always be 0.
/// For 2D objects if a SortingOrder is influencing the same object as the hit collider then the renderers sortingGroupID will be used; otherwise SortingGroup.invalidSortingGroupID.
///
public int sortingGroupID;
///
/// The sorting group order when the hit object is influenced by a SortingGroup.
///
///
/// For UI.Graphic elements this will always be 0.
/// For 3D objects this will always be 0.
/// For 2D objects if a SortingOrder is influencing the same object as the hit collider then the renderers sortingGroupOrder will be used.
///
public int sortingGroupOrder;
///
/// The SortingLayer of the hit object.
///
///
/// For UI.Graphic elements this will be the values from that graphic's Canvas
/// For 3D objects this will always be 0.
/// For 2D objects if a 2D Renderer (Sprite, Tilemap, SpriteShape) is attached to the same object as the hit collider that sortingLayerID will be used.
///
public int sortingLayer;
///
/// The SortingOrder for the hit object.
///
///
/// For Graphic elements this will be the values from that graphics Canvas
/// For 3D objects this will always be 0.
/// For 2D objects if a 2D Renderer (Sprite, Tilemap, SpriteShape) is attached to the same object as the hit collider that sortingOrder will be used.
///
public int sortingOrder;
///
/// The world position of the where the raycast has hit.
///
public Vector3 worldPosition;
///
/// The normal at the hit location of the raycast.
///
public Vector3 worldNormal;
///
/// The screen position from which the raycast was generated.
///
public Vector2 screenPosition;
///
/// The display index from which the raycast was generated.
///
public int displayIndex;
///
/// Is there an associated module and a hit GameObject.
///
public bool isValid
{
get { return module != null && gameObject != null; }
}
///
/// Reset the result.
///
public void Clear()
{
gameObject = null;
module = null;
distance = 0;
index = 0;
depth = 0;
sortingLayer = 0;
sortingOrder = 0;
worldNormal = Vector3.up;
worldPosition = Vector3.zero;
screenPosition = Vector3.zero;
}
public override string ToString()
{
if (!isValid)
return "";
return "Name: " + gameObject + "\n" +
"module: " + module + "\n" +
"distance: " + distance + "\n" +
"index: " + index + "\n" +
"depth: " + depth + "\n" +
"worldNormal: " + worldNormal + "\n" +
"worldPosition: " + worldPosition + "\n" +
"screenPosition: " + screenPosition + "\n" +
"module.sortOrderPriority: " + module.sortOrderPriority + "\n" +
"module.renderOrderPriority: " + module.renderOrderPriority + "\n" +
"sortingLayer: " + sortingLayer + "\n" +
"sortingOrder: " + sortingOrder;
}
}
}