1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
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);
}
}
}
}
}
|