summaryrefslogtreecommitdiff
path: root/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-08 09:50:33 +0800
committerchai <chaifix@163.com>2020-10-08 09:50:33 +0800
commit00dae1bd426d892dff73a50f1c505afd1ac00a90 (patch)
tree5d75f8495406f5b8dd01595e3dd9216887996a34 /Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs
+init
Diffstat (limited to 'Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs')
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs53
1 files changed, 53 insertions, 0 deletions
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs
new file mode 100644
index 0000000..783cf95
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs
@@ -0,0 +1,53 @@
+using System.Collections.Generic;
+using UnityEngine.UI;
+
+namespace UnityEngine.EventSystems
+{
+ /// <summary>
+ /// Simple event system using physics raycasts.
+ /// </summary>
+ [AddComponentMenu("Event/Physics 2D Raycaster")]
+ [RequireComponent(typeof(Camera))]
+ public class Physics2DRaycaster : PhysicsRaycaster
+ {
+ protected Physics2DRaycaster()
+ {}
+
+ public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
+ {
+ if (eventCamera == null)
+ return;
+
+ Ray ray;
+ float distanceToClipPlane;
+ ComputeRayAndDistance(eventData, out ray, out distanceToClipPlane);
+
+ if (ReflectionMethodsCache.Singleton.getRayIntersectionAll == null)
+ return;
+
+ var hits = ReflectionMethodsCache.Singleton.getRayIntersectionAll(ray, distanceToClipPlane, finalEventMask);
+
+ if (hits.Length != 0)
+ {
+ for (int b = 0, bmax = hits.Length; b < bmax; ++b)
+ {
+ var sr = hits[b].collider.gameObject.GetComponent<SpriteRenderer>();
+
+ var result = new RaycastResult
+ {
+ gameObject = hits[b].collider.gameObject,
+ module = this,
+ distance = Vector3.Distance(eventCamera.transform.position, hits[b].point),
+ worldPosition = hits[b].point,
+ worldNormal = hits[b].normal,
+ screenPosition = eventData.position,
+ index = resultAppendList.Count,
+ sortingLayer = sr != null ? sr.sortingLayerID : 0,
+ sortingOrder = sr != null ? sr.sortingOrder : 0
+ };
+ resultAppendList.Add(result);
+ }
+ }
+ }
+ }
+}