Esempio n. 1
0
        public static Ray GUIPointToWorldRay(Vector2 position)
        {
            if (!RuntimeHandles.currentCamera)
            {
                Debug.LogError("Unable to convert GUI point to world ray if a camera has not been set up!");
                return(new Ray(Vector3.zero, Vector3.forward));
            }
            Vector2 position2 = GUIClipUtil.Unclip(position);
            Vector2 vector    = PointsToPixels(position2);

            vector.y = (float)Screen.height - vector.y;
            Camera current = RuntimeHandles.currentCamera;

            return(current.ScreenPointToRay(new Vector2(vector.x, vector.y)));
        }
        public static void SetCamera(Rect position, Camera camera)
        {
            Rect rect = GUIClipUtil.Unclip(position);

            rect = RuntimeHandlesUtility.PointsToPixels(rect);
            Rect pixelRect = new Rect(rect.xMin, (float)Screen.height - rect.yMax, rect.width, rect.height);

            camera.pixelRect = pixelRect;
            Event current = Event.current;

            if (current.type == EventType.Repaint)
            {
                Camera.SetupCurrent(camera);
            }
            else
            {
                currentCamera = camera;
            }
        }