UnityEngine.Display.RelativeMouseAt C# (CSharp) Method

RelativeMouseAt() public static method

Query relative mouse coordinates.

public static RelativeMouseAt ( Vector3 inputMouseCoordinates ) : Vector3
inputMouseCoordinates Vector3 Mouse Input Position as Coordinates.
return Vector3
        public static Vector3 RelativeMouseAt(Vector3 inputMouseCoordinates)
        {
            Vector3 vector;
            int rx = 0;
            int ry = 0;
            int x = (int) inputMouseCoordinates.x;
            int y = (int) inputMouseCoordinates.y;
            vector.z = RelativeMouseAtImpl(x, y, out rx, out ry);
            vector.x = rx;
            vector.y = ry;
            return vector;
        }

Usage Example

コード例 #1
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;
        }