No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RaycastResult.cs 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. namespace UnityEngine.EventSystems
  2. {
  3. /// <summary>
  4. /// A hit result from a BaseRaycaster.
  5. /// </summary>
  6. public struct RaycastResult
  7. {
  8. private GameObject m_GameObject; // Game object hit by the raycast
  9. /// <summary>
  10. /// The GameObject that was hit by the raycast.
  11. /// </summary>
  12. public GameObject gameObject
  13. {
  14. get { return m_GameObject; }
  15. set { m_GameObject = value; }
  16. }
  17. /// <summary>
  18. /// BaseRaycaster that raised the hit.
  19. /// </summary>
  20. public BaseRaycaster module;
  21. /// <summary>
  22. /// Distance to the hit.
  23. /// </summary>
  24. public float distance;
  25. /// <summary>
  26. /// Hit index
  27. /// </summary>
  28. public float index;
  29. /// <summary>
  30. /// Used by raycasters where elements may have the same unit distance, but have specific ordering.
  31. /// </summary>
  32. public int depth;
  33. /// <summary>
  34. /// The sorting group ID when the hit object is influenced by a SortingGroup.
  35. /// </summary>
  36. /// <remarks>
  37. /// For UI.Graphic elements will always be 0.
  38. /// For 3D objects this will always be 0.
  39. /// 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.
  40. /// </remarks>
  41. public int sortingGroupID;
  42. /// <summary>
  43. /// The sorting group order when the hit object is influenced by a SortingGroup.
  44. /// </summary>
  45. /// <remarks>
  46. /// For UI.Graphic elements this will always be 0.
  47. /// For 3D objects this will always be 0.
  48. /// For 2D objects if a SortingOrder is influencing the same object as the hit collider then the renderers sortingGroupOrder will be used.
  49. /// </remarks>
  50. public int sortingGroupOrder;
  51. /// <summary>
  52. /// The SortingLayer of the hit object.
  53. /// </summary>
  54. /// <remarks>
  55. /// For UI.Graphic elements this will be the values from that graphic's Canvas
  56. /// For 3D objects this will always be 0.
  57. /// 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.
  58. /// </remarks>
  59. public int sortingLayer;
  60. /// <summary>
  61. /// The SortingOrder for the hit object.
  62. /// </summary>
  63. /// <remarks>
  64. /// For Graphic elements this will be the values from that graphics Canvas
  65. /// For 3D objects this will always be 0.
  66. /// 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.
  67. /// </remarks>
  68. public int sortingOrder;
  69. /// <summary>
  70. /// The world position of the where the raycast has hit.
  71. /// </summary>
  72. public Vector3 worldPosition;
  73. /// <summary>
  74. /// The normal at the hit location of the raycast.
  75. /// </summary>
  76. public Vector3 worldNormal;
  77. /// <summary>
  78. /// The screen position from which the raycast was generated.
  79. /// </summary>
  80. public Vector2 screenPosition;
  81. /// <summary>
  82. /// The display index from which the raycast was generated.
  83. /// </summary>
  84. public int displayIndex;
  85. /// <summary>
  86. /// Is there an associated module and a hit GameObject.
  87. /// </summary>
  88. public bool isValid
  89. {
  90. get { return module != null && gameObject != null; }
  91. }
  92. /// <summary>
  93. /// Reset the result.
  94. /// </summary>
  95. public void Clear()
  96. {
  97. gameObject = null;
  98. module = null;
  99. distance = 0;
  100. index = 0;
  101. depth = 0;
  102. sortingLayer = 0;
  103. sortingOrder = 0;
  104. worldNormal = Vector3.up;
  105. worldPosition = Vector3.zero;
  106. screenPosition = Vector3.zero;
  107. }
  108. public override string ToString()
  109. {
  110. if (!isValid)
  111. return "";
  112. return "Name: " + gameObject + "\n" +
  113. "module: " + module + "\n" +
  114. "distance: " + distance + "\n" +
  115. "index: " + index + "\n" +
  116. "depth: " + depth + "\n" +
  117. "worldNormal: " + worldNormal + "\n" +
  118. "worldPosition: " + worldPosition + "\n" +
  119. "screenPosition: " + screenPosition + "\n" +
  120. "module.sortOrderPriority: " + module.sortOrderPriority + "\n" +
  121. "module.renderOrderPriority: " + module.renderOrderPriority + "\n" +
  122. "sortingLayer: " + sortingLayer + "\n" +
  123. "sortingOrder: " + sortingOrder;
  124. }
  125. }
  126. }