GetAllCameras() private method

private GetAllCameras ( Camera cameras ) : int
cameras Camera
return int
コード例 #1
0
        static void DoSendMouseEvents(int skipRTCameras)
        {
            var mousePosition = Input.mousePosition;

            int camerasCount = Camera.allCamerasCount;

            if (m_Cameras == null || m_Cameras.Length != camerasCount)
            {
                m_Cameras = new Camera[camerasCount];
            }

            // Fetch all cameras.
            Camera.GetAllCameras(m_Cameras);

            // Clear the HitInfos from last time
            for (var hitIndex = 0; hitIndex < m_CurrentHit.Length; ++hitIndex)
            {
                m_CurrentHit[hitIndex] = new HitInfo();
            }

            // If UnityGUI has the mouse over, we simply don't do any mouse hit detection.
            // That way, it will appear as if the mouse has missed everything.
            if (!s_MouseUsed)
            {
                foreach (var camera in m_Cameras)
                {
                    // we do not want to check cameras that are rendering to textures, starting with 4.0
                    if (camera == null || skipRTCameras != 0 && camera.targetTexture != null)
                    {
                        continue;
                    }

                    int displayIndex = camera.targetDisplay;

                    var eventPosition = Display.RelativeMouseAt(mousePosition);
                    if (eventPosition != Vector3.zero)
                    {
                        // We support multiple display and display identification based on event position.
                        int eventDisplayIndex = (int)eventPosition.z;

                        // Discard events that are not part of this display so the user does not interact with multiple displays at once.
                        if (eventDisplayIndex != displayIndex)
                        {
                            continue;
                        }

                        // Multiple display support only when not the main display. For display 0 the reported
                        // resolution is always the desktop resolution since it's part of the display API,
                        // so we use the standard non multiple display method.
                        float w = Screen.width;
                        float h = Screen.height;
                        if (displayIndex > 0 && displayIndex < Display.displays.Length)
                        {
                            w = Display.displays[displayIndex].systemWidth;
                            h = Display.displays[displayIndex].systemHeight;
                        }

                        Vector2 pos = new Vector2(eventPosition.x / w, eventPosition.y / h);

                        // If the mouse is outside the display bounds, do nothing
                        if (pos.x < 0f || pos.x > 1f || pos.y < 0f || pos.y > 1f)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        // The multiple display system is not supported on all platforms, when it is not supported the returned position
                        // will be all zeros so when the returned index is 0 we will default to the mouse position to be safe.
                        eventPosition = mousePosition;
                    }

                    // Is the mouse inside the cameras viewport?
                    var rect = camera.pixelRect;
                    if (!rect.Contains(eventPosition))
                    {
                        continue;
                    }

                    HitTestLegacyGUI(camera, eventPosition, ref m_CurrentHit[m_HitIndexGUI]);

                    // There is no need to continue if the camera shouldn't be sending out events
                    if (camera.eventMask == 0)
                    {
                        continue;
                    }

                    // Calculate common physics projection and distance.
                    var screenProjectionRay = camera.ScreenPointToRay(eventPosition);
                    var projectionDirection = screenProjectionRay.direction.z;
                    var distanceToClipPlane = Mathf.Approximately(0.0f, projectionDirection) ? Mathf.Infinity : Mathf.Abs((camera.farClipPlane - camera.nearClipPlane) / projectionDirection);

                    // Did we hit any 3D colliders?
                    var hit3D = CameraRaycastHelper.RaycastTry(camera, screenProjectionRay, distanceToClipPlane, camera.cullingMask & camera.eventMask);
                    if (hit3D != null)
                    {
                        m_CurrentHit[m_HitIndexPhysics3D].target = hit3D;
                        m_CurrentHit[m_HitIndexPhysics3D].camera = camera;
                    }
                    // We did not hit anything with a raycast from this camera. But our camera
                    // clears the screen and renders on top of whatever was below, thus making things
                    // rendered before invisible. So clear any previous hit we have found.
                    else if (camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.SolidColor)
                    {
                        m_CurrentHit[m_HitIndexPhysics3D].target = null;
                        m_CurrentHit[m_HitIndexPhysics3D].camera = null;
                    }

                    // Did we hit any 2D colliders?
                    var hit2D = CameraRaycastHelper.RaycastTry2D(camera, screenProjectionRay, distanceToClipPlane, camera.cullingMask & camera.eventMask);
                    if (hit2D != null)
                    {
                        m_CurrentHit[m_HitIndexPhysics2D].target = hit2D;
                        m_CurrentHit[m_HitIndexPhysics2D].camera = camera;
                    }
                    // We did not hit anything with a raycast from this camera. But our camera
                    // clears the screen and renders on top of whatever was below, thus making things
                    // rendered before invisible. So clear any previous hit we have found.
                    else if (camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.SolidColor)
                    {
                        m_CurrentHit[m_HitIndexPhysics2D].target = null;
                        m_CurrentHit[m_HitIndexPhysics2D].camera = null;
                    }
                }
            }

            // Send hit events.
            for (var hitIndex = 0; hitIndex < m_CurrentHit.Length; ++hitIndex)
            {
                SendEvents(hitIndex, m_CurrentHit[hitIndex]);
            }

            s_MouseUsed = false;
        }
コード例 #2
0
        private static void DoSendMouseEvents(int skipRTCameras)
        {
            Vector3 mousePosition   = Input.mousePosition;
            int     allCamerasCount = Camera.allCamerasCount;

            if (SendMouseEvents.m_Cameras == null || SendMouseEvents.m_Cameras.Length != allCamerasCount)
            {
                SendMouseEvents.m_Cameras = new Camera[allCamerasCount];
            }
            Camera.GetAllCameras(SendMouseEvents.m_Cameras);
            for (int index = 0; index < SendMouseEvents.m_CurrentHit.Length; ++index)
            {
                SendMouseEvents.m_CurrentHit[index] = new SendMouseEvents.HitInfo();
            }
            if (!SendMouseEvents.s_MouseUsed)
            {
                foreach (Camera camera in SendMouseEvents.m_Cameras)
                {
                    if (!((Object)camera == (Object)null) && (skipRTCameras == 0 || !((Object)camera.targetTexture != (Object)null)) && camera.pixelRect.Contains(mousePosition))
                    {
                        GUILayer component = camera.GetComponent <GUILayer>();
                        if ((bool)((Object)component))
                        {
                            GUIElement guiElement = component.HitTest(mousePosition);
                            if ((bool)((Object)guiElement))
                            {
                                SendMouseEvents.m_CurrentHit[0].target = guiElement.gameObject;
                                SendMouseEvents.m_CurrentHit[0].camera = camera;
                            }
                            else
                            {
                                SendMouseEvents.m_CurrentHit[0].target = (GameObject)null;
                                SendMouseEvents.m_CurrentHit[0].camera = (Camera)null;
                            }
                        }
                        if (camera.eventMask != 0)
                        {
                            Ray        ray         = camera.ScreenPointToRay(mousePosition);
                            float      z           = ray.direction.z;
                            float      distance    = !Mathf.Approximately(0.0f, z) ? Mathf.Abs((camera.farClipPlane - camera.nearClipPlane) / z) : float.PositiveInfinity;
                            GameObject gameObject1 = camera.RaycastTry(ray, distance, camera.cullingMask & camera.eventMask);
                            if ((Object)gameObject1 != (Object)null)
                            {
                                SendMouseEvents.m_CurrentHit[1].target = gameObject1;
                                SendMouseEvents.m_CurrentHit[1].camera = camera;
                            }
                            else if (camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.Color)
                            {
                                SendMouseEvents.m_CurrentHit[1].target = (GameObject)null;
                                SendMouseEvents.m_CurrentHit[1].camera = (Camera)null;
                            }
                            GameObject gameObject2 = camera.RaycastTry2D(ray, distance, camera.cullingMask & camera.eventMask);
                            if ((Object)gameObject2 != (Object)null)
                            {
                                SendMouseEvents.m_CurrentHit[2].target = gameObject2;
                                SendMouseEvents.m_CurrentHit[2].camera = camera;
                            }
                            else if (camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.Color)
                            {
                                SendMouseEvents.m_CurrentHit[2].target = (GameObject)null;
                                SendMouseEvents.m_CurrentHit[2].camera = (Camera)null;
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < SendMouseEvents.m_CurrentHit.Length; ++i)
            {
                SendMouseEvents.SendEvents(i, SendMouseEvents.m_CurrentHit[i]);
            }
            SendMouseEvents.s_MouseUsed = false;
        }
コード例 #3
0
        private static void DoSendMouseEvents(int skipRTCameras)
        {
            Vector3 mousePosition   = Input.mousePosition;
            int     allCamerasCount = Camera.allCamerasCount;

            if (SendMouseEvents.m_Cameras == null || SendMouseEvents.m_Cameras.Length != allCamerasCount)
            {
                SendMouseEvents.m_Cameras = new Camera[allCamerasCount];
            }
            Camera.GetAllCameras(SendMouseEvents.m_Cameras);
            for (int i = 0; i < SendMouseEvents.m_CurrentHit.Length; i++)
            {
                SendMouseEvents.m_CurrentHit[i] = default(SendMouseEvents.HitInfo);
            }
            if (!SendMouseEvents.s_MouseUsed)
            {
                Camera[] cameras = SendMouseEvents.m_Cameras;
                for (int j = 0; j < cameras.Length; j++)
                {
                    Camera camera = cameras[j];
                    if (!(camera == null) && (skipRTCameras == 0 || !(camera.targetTexture != null)))
                    {
                        if (camera.pixelRect.Contains(mousePosition))
                        {
                            GUILayer component = camera.GetComponent <GUILayer>();
                            if (component)
                            {
                                GUIElement gUIElement = component.HitTest(mousePosition);
                                if (gUIElement)
                                {
                                    SendMouseEvents.m_CurrentHit[0].target = gUIElement.gameObject;
                                    SendMouseEvents.m_CurrentHit[0].camera = camera;
                                }
                                else
                                {
                                    SendMouseEvents.m_CurrentHit[0].target = null;
                                    SendMouseEvents.m_CurrentHit[0].camera = null;
                                }
                            }
                            if (camera.eventMask != 0)
                            {
                                Ray        ray        = camera.ScreenPointToRay(mousePosition);
                                float      z          = ray.direction.z;
                                float      distance   = (!Mathf.Approximately(0f, z)) ? Mathf.Abs((camera.farClipPlane - camera.nearClipPlane) / z) : float.PositiveInfinity;
                                GameObject gameObject = camera.RaycastTry(ray, distance, camera.cullingMask & camera.eventMask);
                                if (gameObject != null)
                                {
                                    SendMouseEvents.m_CurrentHit[1].target = gameObject;
                                    SendMouseEvents.m_CurrentHit[1].camera = camera;
                                }
                                else if (camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.Color)
                                {
                                    SendMouseEvents.m_CurrentHit[1].target = null;
                                    SendMouseEvents.m_CurrentHit[1].camera = null;
                                }
                                GameObject gameObject2 = camera.RaycastTry2D(ray, distance, camera.cullingMask & camera.eventMask);
                                if (gameObject2 != null)
                                {
                                    SendMouseEvents.m_CurrentHit[2].target = gameObject2;
                                    SendMouseEvents.m_CurrentHit[2].camera = camera;
                                }
                                else if (camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.Color)
                                {
                                    SendMouseEvents.m_CurrentHit[2].target = null;
                                    SendMouseEvents.m_CurrentHit[2].camera = null;
                                }
                            }
                        }
                    }
                }
            }
            for (int k = 0; k < SendMouseEvents.m_CurrentHit.Length; k++)
            {
                SendMouseEvents.SendEvents(k, SendMouseEvents.m_CurrentHit[k]);
            }
            SendMouseEvents.s_MouseUsed = false;
        }
コード例 #4
0
        private static void DoSendMouseEvents(int skipRTCameras)
        {
            Vector3 mousePosition   = Input.mousePosition;
            int     allCamerasCount = Camera.allCamerasCount;

            if ((m_Cameras == null) || (m_Cameras.Length != allCamerasCount))
            {
                m_Cameras = new Camera[allCamerasCount];
            }
            Camera.GetAllCameras(m_Cameras);
            for (int i = 0; i < m_CurrentHit.Length; i++)
            {
                m_CurrentHit[i] = new HitInfo();
            }
            if (!s_MouseUsed)
            {
                foreach (Camera camera in m_Cameras)
                {
                    if (((camera != null) && ((skipRTCameras == 0) || (camera.targetTexture == null))) && camera.pixelRect.Contains(mousePosition))
                    {
                        GUILayer component = camera.GetComponent <GUILayer>();
                        if (component != null)
                        {
                            GUIElement element = component.HitTest(mousePosition);
                            if (element != null)
                            {
                                m_CurrentHit[0].target = element.gameObject;
                                m_CurrentHit[0].camera = camera;
                            }
                            else
                            {
                                m_CurrentHit[0].target = null;
                                m_CurrentHit[0].camera = null;
                            }
                        }
                        if (camera.eventMask != 0)
                        {
                            Ray        ray      = camera.ScreenPointToRay(mousePosition);
                            float      z        = ray.direction.z;
                            float      distance = !Mathf.Approximately(0f, z) ? Mathf.Abs((float)((camera.farClipPlane - camera.nearClipPlane) / z)) : float.PositiveInfinity;
                            GameObject obj2     = camera.RaycastTry(ray, distance, camera.cullingMask & camera.eventMask);
                            if (obj2 != null)
                            {
                                m_CurrentHit[1].target = obj2;
                                m_CurrentHit[1].camera = camera;
                            }
                            else if ((camera.clearFlags == CameraClearFlags.Skybox) || (camera.clearFlags == CameraClearFlags.Color))
                            {
                                m_CurrentHit[1].target = null;
                                m_CurrentHit[1].camera = null;
                            }
                            GameObject obj3 = camera.RaycastTry2D(ray, distance, camera.cullingMask & camera.eventMask);
                            if (obj3 != null)
                            {
                                m_CurrentHit[2].target = obj3;
                                m_CurrentHit[2].camera = camera;
                            }
                            else if ((camera.clearFlags == CameraClearFlags.Skybox) || (camera.clearFlags == CameraClearFlags.Color))
                            {
                                m_CurrentHit[2].target = null;
                                m_CurrentHit[2].camera = null;
                            }
                        }
                    }
                }
            }
            for (int j = 0; j < m_CurrentHit.Length; j++)
            {
                SendEvents(j, m_CurrentHit[j]);
            }
            s_MouseUsed = false;
        }
コード例 #5
0
        static void DoSendMouseEvents(int skipRTCameras)
        {
            var mousePosition = Input.mousePosition;

            int camerasCount = Camera.allCamerasCount;

            if (m_Cameras == null || m_Cameras.Length != camerasCount)
            {
                m_Cameras = new Camera[camerasCount];
            }

            // Fetch all cameras.
            Camera.GetAllCameras(m_Cameras);

            // Clear the HitInfos from last time
            for (var hitIndex = 0; hitIndex < m_CurrentHit.Length; ++hitIndex)
            {
                m_CurrentHit[hitIndex] = new HitInfo();
            }

            // If UnityGUI has the mouse over, we simply don't do any mouse hit detection.
            // That way, it will appear as if the mouse has missed everything.
            if (!s_MouseUsed)
            {
                foreach (var camera in m_Cameras)
                {
                    // we do not want to check cameras that are rendering to textures, starting with 4.0
                    if (camera == null || skipRTCameras != 0 && camera.targetTexture != null)
                    {
                        continue;
                    }

                    // Is the mouse inside the cameras viewport?
                    var rect = camera.pixelRect;
                    if (!rect.Contains(mousePosition))
                    {
                        continue;
                    }

                    HitTestLegacyGUI(camera, mousePosition, ref m_CurrentHit[m_HitIndexGUI]);

                    // There is no need to continue if the camera shouldn't be sending out events
                    if (camera.eventMask == 0)
                    {
                        continue;
                    }

                    // Calculate common physics projection and distance.
                    var screenProjectionRay = camera.ScreenPointToRay(mousePosition);
                    var projectionDirection = screenProjectionRay.direction.z;
                    var distanceToClipPlane = Mathf.Approximately(0.0f, projectionDirection) ? Mathf.Infinity : Mathf.Abs((camera.farClipPlane - camera.nearClipPlane) / projectionDirection);

                    // Did we hit any 3D colliders?
                    var hit3D = camera.RaycastTry(screenProjectionRay, distanceToClipPlane, camera.cullingMask & camera.eventMask);
                    if (hit3D != null)
                    {
                        m_CurrentHit[m_HitIndexPhysics3D].target = hit3D;
                        m_CurrentHit[m_HitIndexPhysics3D].camera = camera;
                    }
                    // We did not hit anything with a raycast from this camera. But our camera
                    // clears the screen and renders on top of whatever was below, thus making things
                    // rendered before invisible. So clear any previous hit we have found.
                    else if (camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.SolidColor)
                    {
                        m_CurrentHit[m_HitIndexPhysics3D].target = null;
                        m_CurrentHit[m_HitIndexPhysics3D].camera = null;
                    }

                    // Did we hit any 2D colliders?
                    var hit2D = camera.RaycastTry2D(screenProjectionRay, distanceToClipPlane, camera.cullingMask & camera.eventMask);
                    if (hit2D != null)
                    {
                        m_CurrentHit[m_HitIndexPhysics2D].target = hit2D;
                        m_CurrentHit[m_HitIndexPhysics2D].camera = camera;
                    }
                    // We did not hit anything with a raycast from this camera. But our camera
                    // clears the screen and renders on top of whatever was below, thus making things
                    // rendered before invisible. So clear any previous hit we have found.
                    else if (camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.SolidColor)
                    {
                        m_CurrentHit[m_HitIndexPhysics2D].target = null;
                        m_CurrentHit[m_HitIndexPhysics2D].camera = null;
                    }
                }
            }

            // Send hit events.
            for (var hitIndex = 0; hitIndex < m_CurrentHit.Length; ++hitIndex)
            {
                SendEvents(hitIndex, m_CurrentHit[hitIndex]);
            }

            s_MouseUsed = false;
        }
コード例 #6
0
        private static void DoSendMouseEvents(int skipRTCameras)
        {
            Vector3 mousePosition   = Input.mousePosition;
            int     allCamerasCount = Camera.allCamerasCount;

            if (SendMouseEvents.m_Cameras == null || SendMouseEvents.m_Cameras.Length != allCamerasCount)
            {
                SendMouseEvents.m_Cameras = new Camera[allCamerasCount];
            }
            Camera.GetAllCameras(SendMouseEvents.m_Cameras);
            for (int i = 0; i < SendMouseEvents.m_CurrentHit.Length; i++)
            {
                SendMouseEvents.m_CurrentHit[i] = default(SendMouseEvents.HitInfo);
            }
            if (!SendMouseEvents.s_MouseUsed)
            {
                foreach (Camera camera in SendMouseEvents.m_Cameras)
                {
                    if (!(camera == null) && (skipRTCameras == 0 || !(camera.targetTexture != null)))
                    {
                        int     targetDisplay = camera.targetDisplay;
                        Vector3 vector        = Display.RelativeMouseAt(mousePosition);
                        if (vector != Vector3.zero)
                        {
                            int num = (int)vector.z;
                            if (num != targetDisplay)
                            {
                                goto IL_361;
                            }
                            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 vector2 = new Vector2(vector.x / num2, vector.y / num3);
                            if (vector2.x < 0f || vector2.x > 1f || vector2.y < 0f || vector2.y > 1f)
                            {
                                goto IL_361;
                            }
                        }
                        else
                        {
                            vector = mousePosition;
                            if (!camera.pixelRect.Contains(vector))
                            {
                                goto IL_361;
                            }
                        }
                        SendMouseEvents.HitTestLegacyGUI(camera, vector, ref SendMouseEvents.m_CurrentHit[0]);
                        if (camera.eventMask != 0)
                        {
                            Ray        ray        = camera.ScreenPointToRay(vector);
                            float      z          = ray.direction.z;
                            float      distance   = (!Mathf.Approximately(0f, z)) ? Mathf.Abs((camera.farClipPlane - camera.nearClipPlane) / z) : float.PositiveInfinity;
                            GameObject gameObject = camera.RaycastTry(ray, distance, camera.cullingMask & camera.eventMask);
                            if (gameObject != null)
                            {
                                SendMouseEvents.m_CurrentHit[1].target = gameObject;
                                SendMouseEvents.m_CurrentHit[1].camera = camera;
                            }
                            else if (camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.Color)
                            {
                                SendMouseEvents.m_CurrentHit[1].target = null;
                                SendMouseEvents.m_CurrentHit[1].camera = null;
                            }
                            GameObject gameObject2 = camera.RaycastTry2D(ray, distance, camera.cullingMask & camera.eventMask);
                            if (gameObject2 != null)
                            {
                                SendMouseEvents.m_CurrentHit[2].target = gameObject2;
                                SendMouseEvents.m_CurrentHit[2].camera = camera;
                            }
                            else if (camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.Color)
                            {
                                SendMouseEvents.m_CurrentHit[2].target = null;
                                SendMouseEvents.m_CurrentHit[2].camera = null;
                            }
                        }
                    }
                    IL_361 :;
                }
            }
            for (int k = 0; k < SendMouseEvents.m_CurrentHit.Length; k++)
            {
                SendMouseEvents.SendEvents(k, SendMouseEvents.m_CurrentHit[k]);
            }
            SendMouseEvents.s_MouseUsed = false;
        }
コード例 #7
0
        private static void DoSendMouseEvents(int skipRTCameras)
        {
            Vector3 mousePosition   = Input.mousePosition;
            int     allCamerasCount = Camera.allCamerasCount;
            bool    flag            = SendMouseEvents.m_Cameras == null || SendMouseEvents.m_Cameras.Length != allCamerasCount;

            if (flag)
            {
                SendMouseEvents.m_Cameras = new Camera[allCamerasCount];
            }
            Camera.GetAllCameras(SendMouseEvents.m_Cameras);
            for (int i = 0; i < SendMouseEvents.m_CurrentHit.Length; i++)
            {
                SendMouseEvents.m_CurrentHit[i] = default(SendMouseEvents.HitInfo);
            }
            bool flag2 = !SendMouseEvents.s_MouseUsed;

            if (flag2)
            {
                Camera[] cameras = SendMouseEvents.m_Cameras;
                for (int j = 0; j < cameras.Length; j++)
                {
                    Camera camera = cameras[j];
                    bool   flag3  = camera == null || (skipRTCameras != 0 && camera.targetTexture != null);
                    if (!flag3)
                    {
                        int     targetDisplay = camera.targetDisplay;
                        Vector3 vector        = Display.RelativeMouseAt(mousePosition);
                        bool    flag4         = vector != Vector3.zero;
                        if (flag4)
                        {
                            int  num   = (int)vector.z;
                            bool flag5 = num != targetDisplay;
                            if (flag5)
                            {
                                goto IL_358;
                            }
                            float num2  = (float)Screen.width;
                            float num3  = (float)Screen.height;
                            bool  flag6 = targetDisplay > 0 && targetDisplay < Display.displays.Length;
                            if (flag6)
                            {
                                num2 = (float)Display.displays[targetDisplay].systemWidth;
                                num3 = (float)Display.displays[targetDisplay].systemHeight;
                            }
                            Vector2 vector2 = new Vector2(vector.x / num2, vector.y / num3);
                            bool    flag7   = vector2.x <0f || vector2.x> 1f || vector2.y <0f || vector2.y> 1f;
                            if (flag7)
                            {
                                goto IL_358;
                            }
                        }
                        else
                        {
                            vector = mousePosition;
                        }
                        bool flag8 = !camera.pixelRect.Contains(vector);
                        if (!flag8)
                        {
                            bool flag9 = camera.eventMask == 0;
                            if (!flag9)
                            {
                                Ray        ray        = camera.ScreenPointToRay(vector);
                                float      z          = ray.direction.z;
                                float      distance   = Mathf.Approximately(0f, z) ? float.PositiveInfinity : Mathf.Abs((camera.farClipPlane - camera.nearClipPlane) / z);
                                GameObject gameObject = CameraRaycastHelper.RaycastTry(camera, ray, distance, camera.cullingMask & camera.eventMask);
                                bool       flag10     = gameObject != null;
                                if (flag10)
                                {
                                    SendMouseEvents.m_CurrentHit[1].target = gameObject;
                                    SendMouseEvents.m_CurrentHit[1].camera = camera;
                                }
                                else
                                {
                                    bool flag11 = camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.Color;
                                    if (flag11)
                                    {
                                        SendMouseEvents.m_CurrentHit[1].target = null;
                                        SendMouseEvents.m_CurrentHit[1].camera = null;
                                    }
                                }
                                GameObject gameObject2 = CameraRaycastHelper.RaycastTry2D(camera, ray, distance, camera.cullingMask & camera.eventMask);
                                bool       flag12      = gameObject2 != null;
                                if (flag12)
                                {
                                    SendMouseEvents.m_CurrentHit[2].target = gameObject2;
                                    SendMouseEvents.m_CurrentHit[2].camera = camera;
                                }
                                else
                                {
                                    bool flag13 = camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.Color;
                                    if (flag13)
                                    {
                                        SendMouseEvents.m_CurrentHit[2].target = null;
                                        SendMouseEvents.m_CurrentHit[2].camera = null;
                                    }
                                }
                            }
                        }
                    }
                    IL_358 :;
                }
            }
            for (int k = 0; k < SendMouseEvents.m_CurrentHit.Length; k++)
            {
                SendMouseEvents.SendEvents(k, SendMouseEvents.m_CurrentHit[k]);
            }
            SendMouseEvents.s_MouseUsed = false;
        }
コード例 #8
0
ファイル: SendMouseEvents.cs プロジェクト: Hengle/JellyTerain
        private static void DoSendMouseEvents(int skipRTCameras)
        {
            Vector3 mousePosition   = Input.mousePosition;
            int     allCamerasCount = Camera.allCamerasCount;

            if (m_Cameras == null || m_Cameras.Length != allCamerasCount)
            {
                m_Cameras = new Camera[allCamerasCount];
            }
            Camera.GetAllCameras(m_Cameras);
            for (int i = 0; i < m_CurrentHit.Length; i++)
            {
                m_CurrentHit[i] = default(HitInfo);
            }
            if (!s_MouseUsed)
            {
                Camera[] cameras = m_Cameras;
                foreach (Camera camera in cameras)
                {
                    if (camera == null || (skipRTCameras != 0 && camera.targetTexture != null))
                    {
                        continue;
                    }
                    int     targetDisplay = camera.targetDisplay;
                    Vector3 vector        = Display.RelativeMouseAt(mousePosition);
                    if (vector != Vector3.zero)
                    {
                        int num = (int)vector.z;
                        if (num != targetDisplay)
                        {
                            continue;
                        }
                        float num2 = Screen.width;
                        float num3 = Screen.height;
                        if (targetDisplay > 0 && targetDisplay < Display.displays.Length)
                        {
                            num2 = Display.displays[targetDisplay].systemWidth;
                            num3 = Display.displays[targetDisplay].systemHeight;
                        }
                        Vector2 vector2 = new Vector2(vector.x / num2, vector.y / num3);
                        if (vector2.x < 0f || vector2.x > 1f || vector2.y < 0f || vector2.y > 1f)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        vector = mousePosition;
                        if (!camera.pixelRect.Contains(vector))
                        {
                            continue;
                        }
                    }
                    GUILayer component = camera.GetComponent <GUILayer>();
                    if ((bool)component)
                    {
                        GUIElement gUIElement = component.HitTest(vector);
                        if ((bool)gUIElement)
                        {
                            m_CurrentHit[0].target = gUIElement.gameObject;
                            m_CurrentHit[0].camera = camera;
                        }
                        else
                        {
                            m_CurrentHit[0].target = null;
                            m_CurrentHit[0].camera = null;
                        }
                    }
                    if (camera.eventMask != 0)
                    {
                        Ray        ray        = camera.ScreenPointToRay(vector);
                        Vector3    direction  = ray.direction;
                        float      z          = direction.z;
                        float      distance   = (!Mathf.Approximately(0f, z)) ? Mathf.Abs((camera.farClipPlane - camera.nearClipPlane) / z) : float.PositiveInfinity;
                        GameObject gameObject = camera.RaycastTry(ray, distance, camera.cullingMask & camera.eventMask);
                        if (gameObject != null)
                        {
                            m_CurrentHit[1].target = gameObject;
                            m_CurrentHit[1].camera = camera;
                        }
                        else if (camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.Color)
                        {
                            m_CurrentHit[1].target = null;
                            m_CurrentHit[1].camera = null;
                        }
                        GameObject gameObject2 = camera.RaycastTry2D(ray, distance, camera.cullingMask & camera.eventMask);
                        if (gameObject2 != null)
                        {
                            m_CurrentHit[2].target = gameObject2;
                            m_CurrentHit[2].camera = camera;
                        }
                        else if (camera.clearFlags == CameraClearFlags.Skybox || camera.clearFlags == CameraClearFlags.Color)
                        {
                            m_CurrentHit[2].target = null;
                            m_CurrentHit[2].camera = null;
                        }
                    }
                }
            }
            for (int k = 0; k < m_CurrentHit.Length; k++)
            {
                SendEvents(k, m_CurrentHit[k]);
            }
            s_MouseUsed = false;
        }