protected override void OnCanvasGroupChanged() { base.OnCanvasGroupChanged(); if (!Application.isPlaying) { return; } if (_useRaycast) { var block = GetComponentInParent <CanvasGroup>().blocksRaycasts; raycastTarget = block; if (!block) { _unregistered = true; GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); } else { if (_unregistered) { GraphicRegistry.RegisterGraphicForCanvas(canvas, this); } } } }
private void PreformGraphics(PvrBasePoint pointer, List <Graphic> results) { Vector2 screenPos = eventCamera.WorldToScreenPoint(pointer.ray.GetPoint(pointer.maxPointDistance)); var graphics = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < graphics.Count; i++) { Graphic g = graphics[i]; Debug.Log(g.gameObject.name); if (g.depth == -1 || !g.raycastTarget) { continue; } if (!RectTransformUtility.RectangleContainsScreenPoint(g.rectTransform, screenPos, eventCamera)) { continue; } if (g.Raycast(screenPos, eventCamera)) { sortedGraphics.Add(g); // Debug.Log(g.gameObject.name); } sortedGraphics.Sort((g1, g2) => g1.depth.CompareTo(g.depth)); foreach (var s in sortedGraphics) { results.Add(s); } sortedGraphics.Clear(); } }
private void GraphicRaycast(Canvas canvas, Ray ray, List <Graphic> results) { var foundGraphics = GraphicRegistry.GetGraphicsForCanvas(canvas); s_SortedGraphics.Clear(); for (int i = 0; i < foundGraphics.Count; ++i) { Graphic graphic = foundGraphics[i]; // -1 means it hasn't been processed by the canvas, which means it isn't actually drawn if (graphic.depth == -1 || !graphic.raycastTarget) { continue; } Vector3 worldPos; if (RayIntersectsRectTransform(graphic.rectTransform, ray, out worldPos)) { var screenPos = eventCamera.WorldToScreenPoint(worldPos); // mask/image intersection - See Unity docs on eventAlphaThreshold for when this does anything if (graphic.Raycast(screenPos, eventCamera)) { s_SortedGraphics.Add(graphic); } } } s_SortedGraphics.Sort((g1, g2) => g2.depth.CompareTo(g1.depth)); results.AddRange(s_SortedGraphics); }
//////////////////////////////////////////////////////////////////////// // Private Methods //////////////////////////////////////////////////////////////////////// private void Raycast( Ray ray, List <RaycastResult> resultAppendList, float maxDistance, int layerMask) { // Potentially reduce the maximum hit distance based on whether // any 2D or 3D blocking objects have been intersected. float distance = this.eventCamera.farClipPlane - this.eventCamera.nearClipPlane; if (this.blockingObjects == BlockingObjects.ThreeD || this.blockingObjects == BlockingObjects.All) { RaycastHit hit; if (Physics.Raycast(ray, out hit, distance, this.m_BlockingMask)) { maxDistance = Mathf.Min(hit.distance, maxDistance); } } if (this.blockingObjects == BlockingObjects.TwoD || this.blockingObjects == BlockingObjects.All) { RaycastHit2D hit = Physics2D.GetRayIntersection( ray, distance, this.m_BlockingMask); if (hit.collider != null) { maxDistance = Mathf.Min( hit.fraction * distance, maxDistance); } } // Retrieve the list of graphics associated with the canvas. IList <Graphic> graphics = GraphicRegistry.GetGraphicsForCanvas(this.Canvas); // Iterate through each of graphics and perform hit tests. for (int i = 0; i < graphics.Count; ++i) { Graphic graphic = graphics[i]; // Skip the graphic if it's not in the layer mask. if (((1 << graphic.gameObject.layer) & layerMask) == 0) { continue; } // Perform a raycast against the graphic. RaycastResult result; if (this.Raycast(ray, graphic, out result, maxDistance)) { resultAppendList.Add(result); } } // Sort the results by depth. resultAppendList.Sort((x, y) => y.depth.CompareTo(x.depth)); }
private void SortedRaycastGraphics(Canvas canvas, Ray ray, List <RaycastHitData> results) { var graphics = GraphicRegistry.GetGraphicsForCanvas(canvas); _sortedGraphics.Clear(); for (int i = 0; i < graphics.Count; ++i) { Graphic graphic = graphics[i]; if (graphic.depth == -1) { continue; } Vector3 worldPos; Vector3 worldNormal; float distance; if (RayIntersectsRectTransform(graphic.rectTransform, ray, out worldPos, out worldNormal, out distance)) { _sortedGraphics.Add(new RaycastHitData(graphic, worldPos, worldNormal, distance)); } } _sortedGraphics.Sort((g1, g2) => g2.Graphic.depth.CompareTo(g1.Graphic.depth)); results.AddRange(_sortedGraphics); }
private RaycastResult RaycastAll(Vector2 ptInScreen) { Matrix4x4 matWorldClip = uiCamera.projectionMatrix * uiCamera.worldToCameraMatrix; if (previousResult != null && previousResult.raycastTarget && graphicContainsPoint(ptInScreen, previousResult, uiCamera, matWorldClip, screenScale, supportCanvasGroupsAndDragging)) { return(createRaycastResult(ptInScreen, previousResult)); } previousResult = null; fallbackElement = null; IList <Graphic> graphicsForCanvas = GraphicRegistry.GetGraphicsForCanvas(canvas); int count = graphicsForCanvas.Count; for (int i = 0; i < count; i++) { Graphic graphic = graphicsForCanvas[i]; if (graphic.raycastTarget && graphicContainsPoint(ptInScreen, graphic, uiCamera, matWorldClip, screenScale, supportCanvasGroupsAndDragging)) { EmptyGraphic emptyGraphic = graphic as EmptyGraphic; if (!(emptyGraphic != null) || !emptyGraphic.lowPriorityTarget) { previousResult = graphic; return(createRaycastResult(ptInScreen, graphic)); } fallbackElement = emptyGraphic; } } if (fallbackElement != null) { return(createRaycastResult(ptInScreen, fallbackElement)); } return(default(RaycastResult)); }
public static void UnregisterGraphic(params Graphic[] toUnregister) { for (int i = 0; i < toUnregister.Length; i++) { GraphicRegistry.UnregisterGraphicForCanvas(toUnregister[i].canvas, toUnregister[i]); } }
private void SortedRaycastGraphics(Canvas canvas, Ray ray, List <RaycastHitData> results) { var graphics = GraphicRegistry.GetGraphicsForCanvas(canvas); s_SortedGraphics.Clear(); for (int i = 0; i < graphics.Count; ++i) { Graphic graphic = graphics[i]; if (graphic.depth == -1) { continue; } Vector3 worldPos; float distance; if (RayIntersectsRectTransform(graphic.rectTransform, ray, out worldPos, out distance)) { Vector2 screenPos = eventCamera.WorldToScreenPoint(worldPos); // mask/image intersection - See Unity docs on eventAlphaThreshold for when this does anything if (graphic.Raycast(screenPos, eventCamera)) { s_SortedGraphics.Add(new RaycastHitData(graphic, worldPos, screenPos, distance)); } } } s_SortedGraphics.Sort(CompareRaycastHits); results.AddRange(s_SortedGraphics); }
private static void GraphicsRaycast(Canvas canvas, Ray ray, float hitDistance, Camera camera, List <Graphic> results) { IList <Graphic> graphicsForCanvas = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < graphicsForCanvas.Count; i++) { Graphic graphic = graphicsForCanvas[i]; if (graphic.depth != -1 && !graphic.raycastTarget) { continue; } Vector3 screenPoint = camera.WorldToScreenPoint(ray.GetPoint(hitDistance)); if (!RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, screenPoint, camera)) { continue; } if (graphic.Raycast(screenPoint, camera)) { sortedGraphics.Add(graphic); } } sortedGraphics.Sort((Graphic g1, Graphic g2) => g2.depth.CompareTo(g1.depth)); for (int i = 0; i < sortedGraphics.Count; i++) { results.Add(sortedGraphics[i]); } sortedGraphics.Clear(); }
private static void Raycast(Canvas canvas, Ray ray, float hitDistance, Camera eventCamera, List <TGraphicRaycastResult> results) { // Debug.Log("ttt" + pointerPoision + ":::" + camera); // Necessary for the event system IList <Graphic> foundGraphics = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < foundGraphics.Count; ++i) { Graphic graphic = foundGraphics[i]; // -1 means it hasn't been processed by the canvas, which means it isn't actually drawn if (graphic.depth == -1 || !graphic.raycastTarget) { continue; } Transform trans = graphic.transform.transform; Vector3 transForward = trans.forward; // http://geomalgorithms.com/a06-_intersect-2.html float distance = (Vector3.Dot(transForward, trans.position - ray.origin) / Vector3.Dot(transForward, ray.direction)); // Check to see if the go is behind the camera. if (distance < 0) { continue; } // is behind some blocking 2D or 3D if (distance >= hitDistance) { continue; } Vector3 position = ray.GetPoint(distance); Vector2 pointerPosition = eventCamera.WorldToScreenPoint(position); if (!RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, pointerPosition, eventCamera)) { continue; } if (graphic.Raycast(pointerPosition, eventCamera)) { s_SortedGraphics.Add(new TGraphicRaycastResult() { graphic = graphic, distance = distance, pointerPosition = pointerPosition, position = position }); } } s_SortedGraphics.Sort((g1, g2) => g2.graphic.depth.CompareTo(g1.graphic.depth)); for (int i = 0; i < s_SortedGraphics.Count; ++i) { results.Add(s_SortedGraphics[i]); } s_SortedGraphics.Clear(); }
private bool CheckGraphicAddedToRaycastGraphicRegistry() { var graphicList = GraphicRegistry.GetRaycastableGraphicsForCanvas(m_canvas); var graphicListSize = graphicList.Count; return(ContainsGraphic(graphicList, graphicListSize, m_graphic)); }
private void GraphicRaycast(Canvas canvas, Ray ray, List <OVRRaycaster.RaycastHit> results) { IList <Graphic> graphicsForCanvas = GraphicRegistry.GetGraphicsForCanvas(canvas); OVRRaycaster.s_SortedGraphics.Clear(); for (int i = 0; i < graphicsForCanvas.Count; i++) { Graphic graphic = graphicsForCanvas[i]; if (graphic.depth != -1 && !(this.pointer == graphic.gameObject)) { Vector3 vector; if (OVRRaycaster.RayIntersectsRectTransform(graphic.rectTransform, ray, out vector)) { Vector2 sp = this.eventCamera.WorldToScreenPoint(vector); if (graphic.Raycast(sp, this.eventCamera)) { OVRRaycaster.RaycastHit item; item.graphic = graphic; item.worldPos = vector; item.fromMouse = false; OVRRaycaster.s_SortedGraphics.Add(item); } } } } OVRRaycaster.s_SortedGraphics.Sort((OVRRaycaster.RaycastHit g1, OVRRaycaster.RaycastHit g2) => g2.graphic.depth.CompareTo(g1.graphic.depth)); for (int j = 0; j < OVRRaycaster.s_SortedGraphics.Count; j++) { results.Add(OVRRaycaster.s_SortedGraphics[j]); } }
public static void Raycast(Canvas canvas, bool ignoreReversedGraphics, BaseRaycaster module, Vector2 position, Camera eventCamera, List <RaycastResult> raycastResults) { if (canvas == null) { return; } var ray = eventCamera.ScreenPointToRay(position); var distance = eventCamera.farClipPlane - eventCamera.nearClipPlane; var graphics = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < graphics.Count; ++i) { var graphic = graphics[i]; // -1 means it hasn't been processed by the canvas, which means it isn't actually drawn if (graphic.depth == -1 || !graphic.raycastTarget) { continue; } if (!RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, position, eventCamera)) { continue; } if (ignoreReversedGraphics && Vector3.Dot(eventCamera.transform.forward, graphic.transform.forward) <= 0f) { continue; } if (!graphic.Raycast(position, eventCamera)) { continue; } float dist; new Plane(graphic.transform.forward, graphic.transform.position).Raycast(ray, out dist); if (dist > distance) { continue; } raycastResults.Add(new RaycastResult { gameObject = graphic.gameObject, module = module, distance = dist, worldPosition = ray.GetPoint(dist), worldNormal = graphic.transform.forward, screenPosition = position, index = raycastResults.Count, depth = graphic.depth, sortingLayer = canvas.sortingLayerID, sortingOrder = canvas.sortingOrder }); } }
protected override void OnTransformParentChanged() { base.OnTransformParentChanged(); if (!raycastTarget) { GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); } }
protected override void OnCanvasHierarchyChanged() { base.OnCanvasHierarchyChanged(); if (!raycastTarget) { GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); } }
protected override void OnEnable() { base.OnEnable(); if (!raycastTarget) { GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); } }
public virtual void GraphicRaycast(Canvas canvas, bool ignoreReversedGraphics, Ray ray, float distance, TXRPointerRaycaster raycaster, List <RaycastResult> raycastResults) { if (canvas == null) { return; } var eventCamera = raycaster.eventCamera; var screenCenterPoint = TXRInputModule.ScreenCenterPoint; var graphics = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < graphics.Count; ++i) { var graphic = graphics[i]; // -1 means it hasn't been processed by the canvas, which means it isn't actually drawn if (graphic.depth == -1 || !graphic.raycastTarget) { continue; } if (!RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, screenCenterPoint, eventCamera)) { continue; } if (ignoreReversedGraphics && Vector3.Dot(ray.direction, graphic.transform.forward) <= 0f) { continue; } if (!graphic.Raycast(screenCenterPoint, eventCamera)) { continue; } float dist; new Plane(graphic.transform.forward, graphic.transform.position).Raycast(ray, out dist); if (dist > distance) { continue; } raycastResults.Add(new RaycastResult { gameObject = graphic.gameObject, module = raycaster, distance = dist, worldPosition = ray.GetPoint(dist), worldNormal = -graphic.transform.forward, screenPosition = screenCenterPoint, index = raycastResults.Count, depth = graphic.depth, sortingLayer = canvas.sortingLayerID, sortingOrder = canvas.sortingOrder }); } }
// based on code provided by unity protected virtual void Raycast(Canvas canvas, Camera eventCamera, PointerEventData eventData, Ray ray, ref List <RaycastResult> results) { float hitDistance = GetHitDistance(ray, float.MaxValue); IList <Graphic> canvasGraphics = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < canvasGraphics.Count; ++i) { Graphic graphic = canvasGraphics[i]; if (graphic.depth == -1 || !graphic.raycastTarget) { continue; } Transform graphicTransform = graphic.transform; Vector3 graphicForward = graphicTransform.forward; float distance = Vector3.Dot(graphicForward, graphicTransform.position - ray.origin) / Vector3.Dot(graphicForward, ray.direction); if (distance < 0) { continue; } //Prevents "flickering hover" on items near canvas center. if ((distance - UI_CONTROL_OFFSET) > hitDistance) { continue; } Vector3 position = ray.GetPoint(distance); Vector2 pointerPosition = eventCamera.WorldToScreenPoint(position); if (!RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, pointerPosition, eventCamera)) { continue; } if (graphic.Raycast(pointerPosition, eventCamera)) { RaycastResult result = new RaycastResult() { gameObject = graphic.gameObject, module = this, distance = distance, screenPosition = pointerPosition, worldPosition = position, depth = graphic.depth, sortingLayer = canvas.sortingLayerID, sortingOrder = canvas.sortingOrder, }; results.Add(result); } } results.Sort((g1, g2) => g2.depth.CompareTo(g1.depth)); }
private bool CheckGraphicAddedToGraphicRaycaster() { // check that Graphic is removed from m_CanvasGraphics var raycaster = m_canvas.GetComponent <GraphicRaycaster>(); var graphicList = GraphicRegistry.GetGraphicsForCanvas(m_canvas); var graphicListSize = graphicList.Count; return(ContainsGraphic(graphicList, graphicListSize, m_graphic)); }
private void Raycast(Canvas canvas, Camera eventCamera, Ray ray, List <VIVE_Graphic> results) { var hitDistance = GetHitDistance(ray); var canvasGraphics = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < canvasGraphics.Count; ++i) { var graphic = canvasGraphics[i]; if (graphic.depth == -1 || !graphic.raycastTarget) { continue; } var graphicTransform = graphic.transform; Vector3 graphicFormward = graphicTransform.forward; float distance = (Vector3.Dot(graphicFormward, graphicTransform.position - ray.origin) / Vector3.Dot(graphicFormward, ray.direction)); if (distance < 0) { continue; } if ((distance - UI_CONTROL_OFFSET) > hitDistance) { continue; } Vector3 position = ray.GetPoint(distance); Vector2 pointerPosition = eventCamera.WorldToScreenPoint(position); if (!RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, pointerPosition, eventCamera)) { continue; } if (graphic.Raycast(pointerPosition, eventCamera)) { var vrGraphic = new VIVE_Graphic(); vrGraphic.graphic = graphic; vrGraphic.position = position; vrGraphic.distance = distance; vrGraphic.pointerPosition = pointerPosition; sortedGraphics.Add(vrGraphic); } } sortedGraphics.Sort((g1, g2) => g2.graphic.depth.CompareTo(g1.graphic.depth)); for (int i = 0; i < sortedGraphics.Count; ++i) { results.Add(sortedGraphics[i]); } sortedGraphics.Clear(); }
/// <summary> /// 手指检测最近的平面 /// </summary> private bool FingerRaycast(XRPointEventData eventData, out Vector3 raycasterDirection) { raycasterDirection = Vector3.forward; if (UICanvas == null) { return(false); } if (UICanvas.renderMode == RenderMode.ScreenSpaceOverlay) { return(false); } var canvasGraphics = GraphicRegistry.GetGraphicsForCanvas(UICanvas); if (canvasGraphics == null || canvasGraphics.Count == 0) { return(false); } float maxSqrDistance = eventData.hitDistance * eventData.hitDistance; int lengthOfGraphics = canvasGraphics.Count; float minSqrDistance = maxSqrDistance + 1f; for (int i = 0; i < lengthOfGraphics; i++) { Graphic graphic = canvasGraphics[i]; if (graphic.depth == -1 || !graphic.raycastTarget || graphic.canvasRenderer.cull) { continue; } RectTransform rectTransform = graphic.rectTransform; if (ignoreReversedGraphics) { var rayDir = eventData.origin - rectTransform.position; if (Vector3.Dot(rayDir, rectTransform.forward) > 0) { continue; } } float sqrDistance = maxSqrDistance + 1; if (rectTransform.InRectangle(eventData.origin, out sqrDistance)) { if (sqrDistance < minSqrDistance && sqrDistance <= maxSqrDistance) { minSqrDistance = sqrDistance; raycasterDirection = rectTransform.forward; } } } return(minSqrDistance <= maxSqrDistance); }
protected override void OnEnable() { base.OnEnable(); if (!Application.isPlaying) { return; } if (!_useRaycast) { GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); } }
protected override void OnTransformParentChanged() { base.OnTransformParentChanged(); if (!Application.isPlaying) { return; } if (!_useRaycast) { GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); } }
private void GraphicRaycast(Canvas canvas, Ray ray, List <RaycastHit> results) { //This function is based closely on : // void GraphicRaycaster.Raycast(Canvas canvas, Camera eventCamera, Vector2 pointerPosition, List<Graphic> results) // But modified to take a Ray instead of a canvas pointer, and also to explicitly ignore // the graphic associated with the pointer // Necessary for the event system var foundGraphics = GraphicRegistry.GetGraphicsForCanvas(canvas); s_SortedGraphics.Clear(); for (int i = 0; i < foundGraphics.Count; ++i) { Graphic graphic = foundGraphics[i]; //WriteToLog("graphic = " + graphic); // WriteToLog("graphic.depth = " + graphic.depth); // -1 means it hasn't been processed by the canvas, which means it isn't actually drawn if (graphic.depth == -1 || (pointer == graphic.gameObject)) { continue; } Vector3 worldPos; // WriteToLog("Before if of RayIntersectsRectTransform"); if (RayIntersectsRectTransform(graphic.rectTransform, ray, out worldPos)) { //WriteToLog("inside if of RayIntersectsRectTransform"); //Work out where this is on the screen for compatibility with existing Unity UI code Vector2 screenPos = eventCamera.WorldToScreenPoint(worldPos); // mask/image intersection - See Unity docs on eventAlphaThreshold for when this does anything if (graphic.Raycast(screenPos, eventCamera)) { RaycastHit hit; hit.graphic = graphic; hit.worldPos = worldPos; hit.fromMouse = false; s_SortedGraphics.Add(hit); } } } s_SortedGraphics.Sort((g1, g2) => g2.graphic.depth.CompareTo(g1.graphic.depth)); for (int i = 0; i < s_SortedGraphics.Count; ++i) { results.Add(s_SortedGraphics[i]); } }
// Start is called before the first frame update void Start() { var canvas = GetComponent <Canvas>(); Vector2 p = new Vector2(Screen.width / 2.0f, Screen.height / 2.0f); p = new Vector2(-1000, -10000); var allGraphics = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < allGraphics.Count; i++) { var g = allGraphics[i]; bool con = RectTransformUtility.RectangleContainsScreenPoint(g.rectTransform, p, Camera.main); Debug.LogError(g.Raycast(p, Camera.main) + " " + g.name + " " + con); } }
/// <summary> /// Returns all the canvas objects that are intersected by given ray /// </summary> /// <returns>The objects hit by ray.</returns> /// <param name="ray">Ray.</param> public List <GameObject> GetObjectsHitByRay(Ray ray) { List <GameObject> results = new List <GameObject>(); Vector2 pointerPosition; //ray outside the canvas, return null if (!GetScreenSpacePointByRay(ray, out pointerPosition)) { return(results); } //lets find the graphics under ray! List <Graphic> s_SortedGraphics = new List <Graphic>(); var foundGraphics = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < foundGraphics.Count; ++i) { Graphic graphic = foundGraphics[i]; // -1 means it hasn't been processed by the canvas, which means it isn't actually drawn if (graphic.depth == -1 || !graphic.raycastTarget) { continue; } if (!RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, pointerPosition, eventCamera)) { continue; } if (graphic.Raycast(pointerPosition, eventCamera)) { s_SortedGraphics.Add(graphic); } } s_SortedGraphics.Sort((g1, g2) => g2.depth.CompareTo(g1.depth)); for (int i = 0; i < s_SortedGraphics.Count; ++i) { results.Add(s_SortedGraphics[i].gameObject); } s_SortedGraphics.Clear(); return(results); }
/// <summary> /// 优化 GraphicRaycaster.Raycast 避免CPU周期浪费 /// </summary> public void OptimizeFrameGraphic() { for (int i = 0; i < this.m_frameCanvases.Length; ++i) { Canvas canvasInFrame = this.m_frameCanvases[i]; IList <Graphic> canvasGraphics = GraphicRegistry.GetGraphicsForCanvas(canvasInFrame); for (int j = 0; j < canvasGraphics.Count; ++j) { Graphic graphic = canvasGraphics[j]; if (!graphic.raycastTarget) { GraphicRegistry.UnregisterGraphicForCanvas(canvasInFrame, graphic); } } } }
/// Perform a raycast into the screen and collect all graphics underneath it. private static void Raycast(Canvas canvas, Ray ray, Camera cam, float maxPointerDistance, List <Graphic> results, out Ray finalRay) { Vector3 screenPoint = cam.WorldToScreenPoint(ray.GetPoint(maxPointerDistance)); finalRay = cam.ScreenPointToRay(screenPoint); // Necessary for the event system IList <Graphic> foundGraphics = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < foundGraphics.Count; ++i) { Graphic graphic = foundGraphics[i]; // -1 means it hasn't been processed by the canvas, which means it isn't actually drawn if (graphic.depth == -1 #if UNITY_5_3_OR_NEWER || UNITY_5_3 || UNITY_5_2 || !graphic.raycastTarget #endif ) { continue; } if (!RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, screenPoint, cam)) { continue; } if (graphic.Raycast(screenPoint, cam)) { sortedGraphics.Add(graphic); } } sortedGraphics.Sort((g1, g2) => g2.depth.CompareTo(g1.depth)); for (int i = 0; i < sortedGraphics.Count; ++i) { results.Add(sortedGraphics[i]); } sortedGraphics.Clear(); }
public static int GetGraphicsForCanvas_s(IntPtr l) { int result; try { Canvas canvas; LuaObject.checkType <Canvas>(l, 1, out canvas); IList <Graphic> graphicsForCanvas = GraphicRegistry.GetGraphicsForCanvas(canvas); LuaObject.pushValue(l, true); LuaObject.pushValue(l, graphicsForCanvas); result = 2; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public List <GameObject> GetObjectsHitByRay(Ray ray) { Vector2 vector; List <GameObject> list = new List <GameObject>(); if (this.GetScreenSpacePointByRay(ray, out vector)) { List <Graphic> list2 = new List <Graphic>(); IList <Graphic> graphicsForCanvas = GraphicRegistry.GetGraphicsForCanvas(this.myCanvas); for (int i = 0; i < graphicsForCanvas.Count; i++) { Graphic item = graphicsForCanvas[i]; if ((item.depth != -1) && (item.raycastTarget && (RectTransformUtility.RectangleContainsScreenPoint(item.rectTransform, vector, this.eventCamera) && item.Raycast(vector, this.eventCamera)))) { list2.Add(item); } } if (< > f__am$cache1 == null) {