summaryrefslogtreecommitdiff
path: root/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters')
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/BaseRaycaster.cs47
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/BaseRaycaster.cs.meta13
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs53
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs.meta13
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs114
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs.meta13
6 files changed, 253 insertions, 0 deletions
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/BaseRaycaster.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/BaseRaycaster.cs
new file mode 100644
index 0000000..f9a8558
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/BaseRaycaster.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+
+namespace UnityEngine.EventSystems
+{
+ public abstract class BaseRaycaster : UIBehaviour
+ {
+ public abstract void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList);
+ public abstract Camera eventCamera { get; }
+
+ [Obsolete("Please use sortOrderPriority and renderOrderPriority", false)]
+ public virtual int priority
+ {
+ get { return 0; }
+ }
+
+ public virtual int sortOrderPriority
+ {
+ get { return int.MinValue; }
+ }
+
+ public virtual int renderOrderPriority
+ {
+ get { return int.MinValue; }
+ }
+
+ public override string ToString()
+ {
+ return "Name: " + gameObject + "\n" +
+ "eventCamera: " + eventCamera + "\n" +
+ "sortOrderPriority: " + sortOrderPriority + "\n" +
+ "renderOrderPriority: " + renderOrderPriority;
+ }
+
+ protected override void OnEnable()
+ {
+ base.OnEnable();
+ RaycasterManager.AddRaycaster(this);
+ }
+
+ protected override void OnDisable()
+ {
+ RaycasterManager.RemoveRaycasters(this);
+ base.OnDisable();
+ }
+ }
+}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/BaseRaycaster.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/BaseRaycaster.cs.meta
new file mode 100644
index 0000000..eb8b89a
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/BaseRaycaster.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 89c5c6ccaa917c94a864388cc962e706
+timeCreated: 1602119379
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
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);
+ }
+ }
+ }
+ }
+}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs.meta
new file mode 100644
index 0000000..828be37
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 055a0cdd9d5d3e0489f854f7bdf22ded
+timeCreated: 1602119377
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs
new file mode 100644
index 0000000..2b4bea3
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs
@@ -0,0 +1,114 @@
+using System.Collections.Generic;
+using UnityEngine.UI;
+
+namespace UnityEngine.EventSystems
+{
+ /// <summary>
+ /// Simple event system using physics raycasts.
+ /// </summary>
+ [AddComponentMenu("Event/Physics Raycaster")]
+ [RequireComponent(typeof(Camera))]
+ public class PhysicsRaycaster : BaseRaycaster
+ {
+ /// <summary>
+ /// Const to use for clarity when no event mask is set
+ /// </summary>
+ protected const int kNoEventMaskSet = -1;
+
+ protected Camera m_EventCamera;
+
+ /// <summary>
+ /// Layer mask used to filter events. Always combined with the camera's culling mask if a camera is used.
+ /// </summary>
+ [SerializeField]
+ protected LayerMask m_EventMask = kNoEventMaskSet;
+
+ protected PhysicsRaycaster()
+ {}
+
+ public override Camera eventCamera
+ {
+ get
+ {
+ if (m_EventCamera == null)
+ m_EventCamera = GetComponent<Camera>();
+ return m_EventCamera ?? Camera.main;
+ }
+ }
+
+
+ /// <summary>
+ /// Depth used to determine the order of event processing.
+ /// </summary>
+ public virtual int depth
+ {
+ get { return (eventCamera != null) ? (int)eventCamera.depth : 0xFFFFFF; }
+ }
+
+ /// <summary>
+ /// Event mask used to determine which objects will receive events.
+ /// </summary>
+ public int finalEventMask
+ {
+ get { return (eventCamera != null) ? eventCamera.cullingMask & m_EventMask : kNoEventMaskSet; }
+ }
+
+ /// <summary>
+ /// Layer mask used to filter events. Always combined with the camera's culling mask if a camera is used.
+ /// </summary>
+ public LayerMask eventMask
+ {
+ get { return m_EventMask; }
+ set { m_EventMask = value; }
+ }
+
+ protected void ComputeRayAndDistance(PointerEventData eventData, out Ray ray, out float distanceToClipPlane)
+ {
+ ray = eventCamera.ScreenPointToRay(eventData.position);
+ // compensate far plane distance - see MouseEvents.cs
+ float projectionDirection = ray.direction.z;
+ distanceToClipPlane = Mathf.Approximately(0.0f, projectionDirection)
+ ? Mathf.Infinity
+ : Mathf.Abs((eventCamera.farClipPlane - eventCamera.nearClipPlane) / projectionDirection);
+ }
+
+ public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
+ {
+ // Cull ray casts that are outside of the view rect. (case 636595)
+ if (eventCamera == null || !eventCamera.pixelRect.Contains(eventData.position))
+ return;
+
+ Ray ray;
+ float distanceToClipPlane;
+ ComputeRayAndDistance(eventData, out ray, out distanceToClipPlane);
+
+ if (ReflectionMethodsCache.Singleton.raycast3DAll == null)
+ return;
+
+ var hits = ReflectionMethodsCache.Singleton.raycast3DAll(ray, distanceToClipPlane, finalEventMask);
+
+ if (hits.Length > 1)
+ System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));
+
+ if (hits.Length != 0)
+ {
+ for (int b = 0, bmax = hits.Length; b < bmax; ++b)
+ {
+ var result = new RaycastResult
+ {
+ gameObject = hits[b].collider.gameObject,
+ module = this,
+ distance = hits[b].distance,
+ worldPosition = hits[b].point,
+ worldNormal = hits[b].normal,
+ screenPosition = eventData.position,
+ index = resultAppendList.Count,
+ sortingLayer = 0,
+ sortingOrder = 0
+ };
+ resultAppendList.Add(result);
+ }
+ }
+ }
+ }
+}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs.meta
new file mode 100644
index 0000000..848c302
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: b2bb18305a46ea44686ad8cdffbb3a58
+timeCreated: 1602119379
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: