UnityEngine.RectTransformUtility.ScreenPointToWorldPointInRectangle C# (CSharp) Method

ScreenPointToWorldPointInRectangle() public static method

public static ScreenPointToWorldPointInRectangle ( RectTransform rect, Vector2 screenPoint, Camera cam, Vector3 &worldPoint ) : bool
rect RectTransform
screenPoint Vector2
cam Camera
worldPoint Vector3
return bool
        public static bool ScreenPointToWorldPointInRectangle(RectTransform rect, Vector2 screenPoint, Camera cam, out Vector3 worldPoint)
        {
            float num;
            worldPoint = (Vector3) Vector2.zero;
            Ray ray = ScreenPointToRay(cam, screenPoint);
            Plane plane = new Plane((Vector3) (rect.rotation * Vector3.back), rect.position);
            if (!plane.Raycast(ray, out num))
            {
                return false;
            }
            worldPoint = ray.GetPoint(num);
            return true;
        }

Usage Example

コード例 #1
0
        public static bool ScreenPointToLocalPointInRectangle(RectTransform rect, Vector2 screenPoint, Camera cam, out Vector2 localPoint)
        {
            localPoint = Vector2.zero;
            Vector3 position;
            bool    result;

            if (RectTransformUtility.ScreenPointToWorldPointInRectangle(rect, screenPoint, cam, out position))
            {
                localPoint = rect.InverseTransformPoint(position);
                result     = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }