2 using UnityEngine.EventSystems;
4 using System.Collections;
5 using System.Collections.Generic;
12 Canvas m_Canvas = null;
19 m_Canvas = GetComponent<Canvas> ();
24 public override Camera eventCamera {
26 return InputDeviceManager.instance.currentInputDevice.getEventCamera();
30 public override void Raycast( PointerEventData data, List<RaycastResult> resultAppendList )
36 Camera cam = InputDeviceManager.instance.currentInputDevice.getEventCamera();
37 Vector3 worldPos = canvas.transform.TransformPoint (
new Vector3(data.position.x, data.position.y, 0 ));
39 Vector3 screenPosition = cam.WorldToScreenPoint (worldPos);
41 Rect fullCanvas = GetComponent<RectTransform> ().rect;
43 if (data.position.x > fullCanvas.size.x || data.position.y > fullCanvas.size.y)
46 List<Graphic> sortedGraphics =
new List<Graphic> ();
48 var foundGraphics = GraphicRegistry.GetGraphicsForCanvas (canvas);
49 for (
int i = 0; i < foundGraphics.Count; ++i) {
50 Graphic graphic = foundGraphics [i];
52 if (graphic.depth == -1 || !graphic.raycastTarget)
55 Vector2 localPos = positionFromCanvasSpaceToGraphicSpace (graphic, data.position);
56 if (!graphic.rectTransform.rect.Contains (localPos))
59 sortedGraphics.Add (graphic);
62 sortedGraphics.Sort ((g1, g2) => g2.depth.CompareTo (g1.depth));
65 for (
int i = 0; i < sortedGraphics.Count; ++i) {
66 Graphic graphic = sortedGraphics [i];
67 var castResult =
new RaycastResult {
68 gameObject = graphic.gameObject,
71 screenPosition =
new Vector2( screenPosition.x, screenPosition.y ),
72 index = resultAppendList.Count,
73 depth = graphic.depth,
74 sortingLayer = canvas.sortingLayerID,
75 sortingOrder = canvas.sortingOrder
77 resultAppendList.Add( castResult );
81 public Vector2 positionFromCanvasSpaceToGraphicSpace( Graphic graphic, Vector2 pos )
84 Vector3 worldPos = GetComponent<RectTransform> ().TransformPoint (pos.x, pos.y, 0);
87 Vector3 result = graphic.rectTransform.InverseTransformPoint( worldPos );
88 return new Vector2 (result.x, result.y);