暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RaycastResult.cs 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 SortingLayer of the hit object.
  35. /// </summary>
  36. /// <remarks>
  37. /// For UI.Graphic elements this will be the values from that graphic's Canvas
  38. /// For 3D objects this will always be 0.
  39. /// 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.
  40. /// </remarks>
  41. public int sortingLayer;
  42. /// <summary>
  43. /// The SortingOrder for the hit object.
  44. /// </summary>
  45. /// <remarks>
  46. /// For Graphic elements this will be the values from that graphics Canvas
  47. /// For 3D objects this will always be 0.
  48. /// 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.
  49. /// </remarks>
  50. public int sortingOrder;
  51. /// <summary>
  52. /// The world position of the where the raycast has hit.
  53. /// </summary>
  54. public Vector3 worldPosition;
  55. /// <summary>
  56. /// The normal at the hit location of the raycast.
  57. /// </summary>
  58. public Vector3 worldNormal;
  59. /// <summary>
  60. /// The screen position from which the raycast was generated.
  61. /// </summary>
  62. public Vector2 screenPosition;
  63. /// <summary>
  64. /// The display index from which the raycast was generated.
  65. /// </summary>
  66. public int displayIndex;
  67. /// <summary>
  68. /// Is there an associated module and a hit GameObject.
  69. /// </summary>
  70. public bool isValid
  71. {
  72. get { return module != null && gameObject != null; }
  73. }
  74. /// <summary>
  75. /// Reset the result.
  76. /// </summary>
  77. public void Clear()
  78. {
  79. gameObject = null;
  80. module = null;
  81. distance = 0;
  82. index = 0;
  83. depth = 0;
  84. sortingLayer = 0;
  85. sortingOrder = 0;
  86. worldNormal = Vector3.up;
  87. worldPosition = Vector3.zero;
  88. screenPosition = Vector3.zero;
  89. }
  90. public override string ToString()
  91. {
  92. if (!isValid)
  93. return "";
  94. return "Name: " + gameObject + "\n" +
  95. "module: " + module + "\n" +
  96. "distance: " + distance + "\n" +
  97. "index: " + index + "\n" +
  98. "depth: " + depth + "\n" +
  99. "worldNormal: " + worldNormal + "\n" +
  100. "worldPosition: " + worldPosition + "\n" +
  101. "screenPosition: " + screenPosition + "\n" +
  102. "module.sortOrderPriority: " + module.sortOrderPriority + "\n" +
  103. "module.renderOrderPriority: " + module.renderOrderPriority + "\n" +
  104. "sortingLayer: " + sortingLayer + "\n" +
  105. "sortingOrder: " + sortingOrder;
  106. }
  107. }
  108. }