Raycast() private static method

private static Raycast ( Canvas canvas, Camera eventCamera, Vector2 pointerPosition, List results ) : void
canvas UnityEngine.Canvas
eventCamera UnityEngine.Camera
pointerPosition Vector2
results List
return void
Esempio n. 1
0
 static public int Raycast(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.UI.GraphicRaycaster           self = (UnityEngine.UI.GraphicRaycaster)checkSelf(l);
         UnityEngine.EventSystems.PointerEventData a1;
         checkType(l, 2, out a1);
         System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult> a2;
         checkType(l, 3, out a2);
         self.Raycast(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Esempio n. 2
0
    /// <summary>
    /// Cast a ray to test if screenPosition is over any UI object in canvas. This is a replacement
    /// for IsPointerOverGameObject() which does not work on Android in 4.6.0f3
    /// </summary>
    public static bool IsPointerOverUIObject(Canvas canvas, Vector2 screenPosition)
    {
        UnityEngine.EventSystems.PointerEventData eventDataCurrentPosition = new UnityEngine.EventSystems.PointerEventData(UnityEngine.EventSystems.EventSystem.current);
        eventDataCurrentPosition.position = screenPosition;

        UnityEngine.UI.GraphicRaycaster uiRaycaster           = canvas.gameObject.GetComponent <UnityEngine.UI.GraphicRaycaster>();
        List <UnityEngine.EventSystems.RaycastResult> results = new List <UnityEngine.EventSystems.RaycastResult>();

        uiRaycaster.Raycast(eventDataCurrentPosition, results);
        return(results.Count > 0);
    }
Esempio n. 3
0
    /// <summary>
    /// Cast a ray to test if screenPosition is over any UI object in canvas. This is a replacement
    /// for IsPointerOverGameObject() which does not work on Android in 4.6.0f3
    /// </summary>
    public static bool IsPointerOverUIObject(Canvas canvas, Vector2 screenPosition)
    {
        // Referencing this code for GraphicRaycaster https://gist.github.com/stramit/ead7ca1f432f3c0f181f
        // the ray cast appears to require only eventData.position.
        UnityEngine.EventSystems.PointerEventData eventDataCurrentPosition = new UnityEngine.EventSystems.PointerEventData(UnityEngine.EventSystems.EventSystem.current);
        eventDataCurrentPosition.position = screenPosition;

        UnityEngine.UI.GraphicRaycaster uiRaycaster           = canvas.gameObject.GetComponent <UnityEngine.UI.GraphicRaycaster>();
        List <UnityEngine.EventSystems.RaycastResult> results = new List <UnityEngine.EventSystems.RaycastResult>();

        uiRaycaster.Raycast(eventDataCurrentPosition, results);
        return(results.Count > 0);
    }
 static public int Raycast(IntPtr l)
 {
     try {
         UnityEngine.UI.GraphicRaycaster           self = (UnityEngine.UI.GraphicRaycaster)checkSelf(l);
         UnityEngine.EventSystems.PointerEventData a1;
         checkType(l, 2, out a1);
         System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult> a2;
         checkType(l, 3, out a2);
         self.Raycast(a1, a2);
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static int Raycast(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UnityEngine.UI.GraphicRaycaster           obj  = (UnityEngine.UI.GraphicRaycaster)ToLua.CheckObject <UnityEngine.UI.GraphicRaycaster>(L, 1);
         UnityEngine.EventSystems.PointerEventData arg0 = (UnityEngine.EventSystems.PointerEventData)ToLua.CheckObject <UnityEngine.EventSystems.PointerEventData>(L, 2);
         System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult> arg1 = (System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>)ToLua.CheckObject(L, 3, typeof(System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>));
         obj.Raycast(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static public int Raycast(IntPtr l)
 {
     try{
         UnityEngine.UI.GraphicRaycaster           self = (UnityEngine.UI.GraphicRaycaster)checkSelf(l);
         UnityEngine.EventSystems.PointerEventData a1;
         checkType(l, 2, out a1);
         List <UnityEngine.EventSystems.RaycastResult> a2;
         checkType(l, 3, out a2);
         self.Raycast(a1, a2);
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Esempio n. 7
0
    /// <summary>
    /// Raycasts to UI using the given graphic raycaster and input position.
    /// </summary>
    /// <returns>The U.</returns>
    /// <param name="gr">Gr.</param>
    /// <param name="inputPos">Input position.</param>
    public static GameObject RaycastUI(UnityEngine.UI.GraphicRaycaster gr, Vector2 inputPos)
    {
        if (gr == null)
        {
            return(null);
        }

        UnityEngine.EventSystems.PointerEventData ped = new UnityEngine.EventSystems.PointerEventData(null);
        ped.position = inputPos;          // Input.mousePosition;

        List <UnityEngine.EventSystems.RaycastResult> results = new List <UnityEngine.EventSystems.RaycastResult>();

        gr.Raycast(ped, results);

        if (results.Count > 0)
        {
            return(results[0].gameObject);
        }

        return(null);
    }
Esempio n. 8
0
    public static bool IsPointerOverGameObject(Canvas canvas, Vector2 screenPosition)
    {
        if (_isOnUI)
        {
            return(true);
        }

        if (EventSystem.current == null)
        {
            return(false);
        }

        PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);

        eventDataCurrentPosition.position = screenPosition;
        UnityEngine.UI.GraphicRaycaster uiRaycaster = canvas.gameObject.GetComponent <UnityEngine.UI.GraphicRaycaster>();

        _list.Clear();
        uiRaycaster.Raycast(eventDataCurrentPosition, _list);

        return(_list.Count > 0);
    }
Esempio n. 9
0
        public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
        {
            if (!(this.canvas == null))
            {
                int targetDisplay;
                if (this.canvas.renderMode == RenderMode.ScreenSpaceOverlay || !this.eventCamera)
                {
                    targetDisplay = this.canvas.targetDisplay;
                }
                else
                {
                    targetDisplay = this.eventCamera.targetDisplay;
                }
                Vector3 vector = Display.RelativeMouseAt(eventData.position);
                if (vector != Vector3.zero)
                {
                    int num = (int)vector.z;
                    if (num != targetDisplay)
                    {
                        return;
                    }
                }
                else
                {
                    vector = eventData.position;
                }
                Vector2 vector2;
                if (this.eventCamera == null)
                {
                    float num2 = (float)Screen.width;
                    float num3 = (float)Screen.height;
                    if (targetDisplay > 0 && targetDisplay < Display.displays.Length)
                    {
                        num2 = (float)Display.displays[targetDisplay].systemWidth;
                        num3 = (float)Display.displays[targetDisplay].systemHeight;
                    }
                    vector2 = new Vector2(vector.x / num2, vector.y / num3);
                }
                else
                {
                    vector2 = this.eventCamera.ScreenToViewportPoint(vector);
                }
                if (vector2.x >= 0f && vector2.x <= 1f && vector2.y >= 0f && vector2.y <= 1f)
                {
                    float num4 = 3.40282347E+38f;
                    Ray   r    = default(Ray);
                    if (this.eventCamera != null)
                    {
                        r = this.eventCamera.ScreenPointToRay(vector);
                    }
                    if (this.canvas.renderMode != RenderMode.ScreenSpaceOverlay && this.blockingObjects != GraphicRaycaster.BlockingObjects.None)
                    {
                        float num5 = 100f;
                        if (this.eventCamera != null)
                        {
                            num5 = this.eventCamera.farClipPlane - this.eventCamera.nearClipPlane;
                        }
                        if (this.blockingObjects == GraphicRaycaster.BlockingObjects.ThreeD || this.blockingObjects == GraphicRaycaster.BlockingObjects.All)
                        {
                            if (ReflectionMethodsCache.Singleton.raycast3D != null)
                            {
                                RaycastHit raycastHit;
                                if (ReflectionMethodsCache.Singleton.raycast3D(r, out raycastHit, num5, this.m_BlockingMask))
                                {
                                    num4 = raycastHit.distance;
                                }
                            }
                        }
                        if (this.blockingObjects == GraphicRaycaster.BlockingObjects.TwoD || this.blockingObjects == GraphicRaycaster.BlockingObjects.All)
                        {
                            if (ReflectionMethodsCache.Singleton.raycast2D != null)
                            {
                                RaycastHit2D raycastHit2D = ReflectionMethodsCache.Singleton.raycast2D(r.origin, r.direction, num5, this.m_BlockingMask);
                                if (raycastHit2D.collider)
                                {
                                    num4 = raycastHit2D.fraction * num5;
                                }
                            }
                        }
                    }
                    this.m_RaycastResults.Clear();
                    GraphicRaycaster.Raycast(this.canvas, this.eventCamera, vector, this.m_RaycastResults);
                    int i = 0;
                    while (i < this.m_RaycastResults.Count)
                    {
                        GameObject gameObject = this.m_RaycastResults[i].gameObject;
                        bool       flag       = true;
                        if (this.ignoreReversedGraphics)
                        {
                            if (this.eventCamera == null)
                            {
                                Vector3 rhs = gameObject.transform.rotation * Vector3.forward;
                                flag = (Vector3.Dot(Vector3.forward, rhs) > 0f);
                            }
                            else
                            {
                                Vector3 lhs  = this.eventCamera.transform.rotation * Vector3.forward;
                                Vector3 rhs2 = gameObject.transform.rotation * Vector3.forward;
                                flag = (Vector3.Dot(lhs, rhs2) > 0f);
                            }
                        }
                        if (flag)
                        {
                            float num6;
                            if (this.eventCamera == null || this.canvas.renderMode == RenderMode.ScreenSpaceOverlay)
                            {
                                num6 = 0f;
                            }
                            else
                            {
                                Transform transform = gameObject.transform;
                                Vector3   forward   = transform.forward;
                                num6 = Vector3.Dot(forward, transform.position - r.origin) / Vector3.Dot(forward, r.direction);
                                if (num6 < 0f)
                                {
                                    goto IL_4C8;
                                }
                            }
                            if (num6 < num4)
                            {
                                RaycastResult item = new RaycastResult
                                {
                                    gameObject     = gameObject,
                                    module         = this,
                                    distance       = num6,
                                    screenPosition = vector,
                                    index          = (float)resultAppendList.Count,
                                    depth          = this.m_RaycastResults[i].depth,
                                    sortingLayer   = this.canvas.sortingLayerID,
                                    sortingOrder   = this.canvas.sortingOrder
                                };
                                resultAppendList.Add(item);
                            }
                        }
IL_4C8:
                        i++;
                        continue;
                        goto IL_4C8;
                    }
                }
            }
        }
Esempio n. 10
0
        public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
        {
            if (!(this.canvas == null))
            {
                IList <Graphic> graphicsForCanvas = GraphicRegistry.GetGraphicsForCanvas(this.canvas);
                if (graphicsForCanvas != null && graphicsForCanvas.Count != 0)
                {
                    Camera eventCamera = this.eventCamera;
                    int    targetDisplay;
                    if (this.canvas.renderMode == RenderMode.ScreenSpaceOverlay || eventCamera == null)
                    {
                        targetDisplay = this.canvas.targetDisplay;
                    }
                    else
                    {
                        targetDisplay = eventCamera.targetDisplay;
                    }
                    Vector3 vector = Display.RelativeMouseAt(eventData.position);
                    if (vector != Vector3.zero)
                    {
                        int num = (int)vector.z;
                        if (num != targetDisplay)
                        {
                            return;
                        }
                    }
                    else
                    {
                        vector = eventData.position;
                    }
                    Vector2 vector2;
                    if (eventCamera == null)
                    {
                        float num2 = (float)Screen.width;
                        float num3 = (float)Screen.height;
                        if (targetDisplay > 0 && targetDisplay < Display.displays.Length)
                        {
                            num2 = (float)Display.displays[targetDisplay].systemWidth;
                            num3 = (float)Display.displays[targetDisplay].systemHeight;
                        }
                        vector2 = new Vector2(vector.x / num2, vector.y / num3);
                    }
                    else
                    {
                        vector2 = eventCamera.ScreenToViewportPoint(vector);
                    }
                    if (vector2.x >= 0f && vector2.x <= 1f && vector2.y >= 0f && vector2.y <= 1f)
                    {
                        float num4 = 3.40282347E+38f;
                        Ray   r    = default(Ray);
                        if (eventCamera != null)
                        {
                            r = eventCamera.ScreenPointToRay(vector);
                        }
                        if (this.canvas.renderMode != RenderMode.ScreenSpaceOverlay && this.blockingObjects != GraphicRaycaster.BlockingObjects.None)
                        {
                            float f = 100f;
                            if (eventCamera != null)
                            {
                                float z = r.direction.z;
                                f = ((!Mathf.Approximately(0f, z)) ? Mathf.Abs((eventCamera.farClipPlane - eventCamera.nearClipPlane) / z) : float.PositiveInfinity);
                            }
                            if (this.blockingObjects == GraphicRaycaster.BlockingObjects.ThreeD || this.blockingObjects == GraphicRaycaster.BlockingObjects.All)
                            {
                                if (ReflectionMethodsCache.Singleton.raycast3D != null)
                                {
                                    RaycastHit[] array = ReflectionMethodsCache.Singleton.raycast3DAll(r, f, this.m_BlockingMask);
                                    if (array.Length > 0)
                                    {
                                        num4 = array[0].distance;
                                    }
                                }
                            }
                            if (this.blockingObjects == GraphicRaycaster.BlockingObjects.TwoD || this.blockingObjects == GraphicRaycaster.BlockingObjects.All)
                            {
                                if (ReflectionMethodsCache.Singleton.raycast2D != null)
                                {
                                    RaycastHit2D[] array2 = ReflectionMethodsCache.Singleton.getRayIntersectionAll(r, f, this.m_BlockingMask);
                                    if (array2.Length > 0)
                                    {
                                        num4 = array2[0].distance;
                                    }
                                }
                            }
                        }
                        this.m_RaycastResults.Clear();
                        GraphicRaycaster.Raycast(this.canvas, eventCamera, vector, graphicsForCanvas, this.m_RaycastResults);
                        int count = this.m_RaycastResults.Count;
                        int i     = 0;
                        while (i < count)
                        {
                            GameObject gameObject = this.m_RaycastResults[i].gameObject;
                            bool       flag       = true;
                            if (this.ignoreReversedGraphics)
                            {
                                if (eventCamera == null)
                                {
                                    Vector3 rhs = gameObject.transform.rotation * Vector3.forward;
                                    flag = (Vector3.Dot(Vector3.forward, rhs) > 0f);
                                }
                                else
                                {
                                    Vector3 lhs  = eventCamera.transform.rotation * Vector3.forward;
                                    Vector3 rhs2 = gameObject.transform.rotation * Vector3.forward;
                                    flag = (Vector3.Dot(lhs, rhs2) > 0f);
                                }
                            }
                            if (flag)
                            {
                                float num5;
                                if (eventCamera == null || this.canvas.renderMode == RenderMode.ScreenSpaceOverlay)
                                {
                                    num5 = 0f;
                                }
                                else
                                {
                                    Transform transform = gameObject.transform;
                                    Vector3   forward   = transform.forward;
                                    num5 = Vector3.Dot(forward, transform.position - eventCamera.transform.position) / Vector3.Dot(forward, r.direction);
                                    if (num5 < 0f)
                                    {
                                        goto IL_4EE;
                                    }
                                }
                                if (num5 < num4)
                                {
                                    RaycastResult item = new RaycastResult
                                    {
                                        gameObject     = gameObject,
                                        module         = this,
                                        distance       = num5,
                                        screenPosition = vector,
                                        index          = (float)resultAppendList.Count,
                                        depth          = this.m_RaycastResults[i].depth,
                                        sortingLayer   = this.canvas.sortingLayerID,
                                        sortingOrder   = this.canvas.sortingOrder
                                    };
                                    resultAppendList.Add(item);
                                }
                            }
IL_4EE:
                            i++;
                            continue;
                            goto IL_4EE;
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
        {
            if ((UnityEngine.Object) this.canvas == (UnityEngine.Object)null)
            {
                return;
            }
            Vector2 vector2;

            if ((UnityEngine.Object) this.eventCamera == (UnityEngine.Object)null)
            {
                float width  = (float)Screen.width;
                float height = (float)Screen.height;
                vector2 = new Vector2(eventData.position.x / width, eventData.position.y / height);
            }
            else
            {
                vector2 = (Vector2)this.eventCamera.ScreenToViewportPoint((Vector3)eventData.position);
            }
            if ((double)vector2.x < 0.0 || (double)vector2.x > 1.0 || ((double)vector2.y < 0.0 || (double)vector2.y > 1.0))
            {
                return;
            }
            float num1 = float.MaxValue;
            Ray   ray  = new Ray();

            if ((UnityEngine.Object) this.eventCamera != (UnityEngine.Object)null)
            {
                ray = this.eventCamera.ScreenPointToRay((Vector3)eventData.position);
            }
            if (this.canvas.renderMode != RenderMode.ScreenSpaceOverlay && this.blockingObjects != GraphicRaycaster.BlockingObjects.None)
            {
                float num2 = 100f;
                if ((UnityEngine.Object) this.eventCamera != (UnityEngine.Object)null)
                {
                    num2 = this.eventCamera.farClipPlane - this.eventCamera.nearClipPlane;
                }
                RaycastHit hitInfo;
                if ((this.blockingObjects == GraphicRaycaster.BlockingObjects.ThreeD || this.blockingObjects == GraphicRaycaster.BlockingObjects.All) && Physics.Raycast(ray, out hitInfo, num2, (int)this.m_BlockingMask))
                {
                    num1 = hitInfo.distance;
                }
                if (this.blockingObjects == GraphicRaycaster.BlockingObjects.TwoD || this.blockingObjects == GraphicRaycaster.BlockingObjects.All)
                {
                    RaycastHit2D raycastHit2D = Physics2D.Raycast((Vector2)ray.origin, (Vector2)ray.direction, num2, (int)this.m_BlockingMask);
                    if ((UnityEngine.Object)raycastHit2D.collider != (UnityEngine.Object)null)
                    {
                        num1 = raycastHit2D.fraction * num2;
                    }
                }
            }
            this.m_RaycastResults.Clear();
            GraphicRaycaster.Raycast(this.canvas, this.eventCamera, eventData.position, this.m_RaycastResults);
            for (int index = 0; index < this.m_RaycastResults.Count; ++index)
            {
                GameObject gameObject = this.m_RaycastResults[index].gameObject;
                bool       flag       = true;
                if (this.ignoreReversedGraphics)
                {
                    flag = !((UnityEngine.Object) this.eventCamera == (UnityEngine.Object)null) ? (double)Vector3.Dot(this.eventCamera.transform.rotation * Vector3.forward, gameObject.transform.rotation * Vector3.forward) > 0.0 : (double)Vector3.Dot(Vector3.forward, gameObject.transform.rotation * Vector3.forward) > 0.0;
                }
                if (flag)
                {
                    float num2;
                    if ((UnityEngine.Object) this.eventCamera == (UnityEngine.Object)null || this.canvas.renderMode == RenderMode.ScreenSpaceOverlay)
                    {
                        num2 = 0.0f;
                    }
                    else
                    {
                        Transform transform = gameObject.transform;
                        Vector3   forward   = transform.forward;
                        num2 = Vector3.Dot(forward, transform.position - ray.origin) / Vector3.Dot(forward, ray.direction);
                        if ((double)num2 < 0.0)
                        {
                            continue;
                        }
                    }
                    if ((double)num2 < (double)num1)
                    {
                        RaycastResult raycastResult = new RaycastResult()
                        {
                            gameObject = gameObject, module = (BaseRaycaster)this, distance = num2, screenPosition = eventData.position, index = (float)resultAppendList.Count, depth = this.m_RaycastResults[index].depth, sortingLayer = this.canvas.sortingLayerID, sortingOrder = this.canvas.sortingOrder
                        };
                        resultAppendList.Add(raycastResult);
                    }
                }
            }
        }