本文整理汇总了C#中UnityEngine.RectTransform.InverseTransformPoint方法的典型用法代码示例。如果您正苦于以下问题:C# RectTransform.InverseTransformPoint方法的具体用法?C# RectTransform.InverseTransformPoint怎么用?C# RectTransform.InverseTransformPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.RectTransform
的用法示例。
在下文中一共展示了RectTransform.InverseTransformPoint方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScreenPointToLocalPointInRectangle
public static bool ScreenPointToLocalPointInRectangle(RectTransform rect, Vector2 screenPoint, Camera cam, out Vector2 localPoint)
{
localPoint = Vector2.zero;
Vector3 position;
if (RectTransformUtility.ScreenPointToWorldPointInRectangle(rect, screenPoint, cam, out position))
{
localPoint = rect.InverseTransformPoint(position);
return true;
}
return false;
}
示例2: GetCanvasInputPosition
public static Vector2 GetCanvasInputPosition(RectTransform canvas)
{
float camDistance = canvas.gameObject.transform.position.z - Camera.main.transform.position.z;
if (INPUT_DEBUG) { //return mouse position in canvas
Vector3 screenPoint = new Vector3(Input.mousePosition.x,Input.mousePosition.y,camDistance);
Vector3 worldPoint = Camera.main.ScreenToWorldPoint (screenPoint);
//Debug.Log ("worldpoint: " + worldPoint.x + ", " +worldPoint.y + ", " + worldPoint.z);
Vector3 canvasPoint = canvas.InverseTransformPoint(worldPoint);
//Debug.Log ("canvaspoint: " + canvasPoint.x + ", " +canvasPoint.y + ", " + canvasPoint.z);
return new Vector2(canvasPoint.x,canvasPoint.y);
} else { //return first finger position in canvas, or 0,0 if no touches exist
if(Input.touchCount < 1){
return lastCanvasPos;
}
Touch t = Input.GetTouch(0);
Vector3 screenPoint = new Vector3(t.position.x,t.position.y,camDistance);
Vector3 worldPoint = Camera.main.ScreenToWorldPoint (screenPoint);
Vector3 canvasPoint = canvas.InverseTransformPoint(worldPoint);
lastCanvasPos = new Vector2(canvasPoint.x,canvasPoint.y);
return lastCanvasPos;
}
}
示例3: ScreenPointToLocalPointInRectangle
public static bool ScreenPointToLocalPointInRectangle(RectTransform rect, Vector2 screenPoint, Camera cam, out Vector2 localPoint)
{
Vector3 vector;
localPoint = Vector2.zero;
if (ScreenPointToWorldPointInRectangle(rect, screenPoint, cam, out vector))
{
localPoint = rect.InverseTransformPoint(vector);
return true;
}
return false;
}
示例4: CalculateDragPosition
/// <summary>
/// Calculates the drag position.
/// </summary>
/// <returns>The drag position.</returns>
/// <param name="screenPosition">Screen position.</param>
/// <param name="canvas">Canvas.</param>
/// <param name="canvasRect">Canvas rect.</param>
static public Vector3 CalculateDragPosition(Vector3 screenPosition, Canvas canvas, RectTransform canvasRect)
{
Vector3 result;
var canvasSize = canvasRect.sizeDelta;
Vector2 min = Vector2.zero;
Vector2 max = canvasSize;
var isOverlay = canvas.renderMode == RenderMode.ScreenSpaceOverlay;
var noCamera = canvas.renderMode == RenderMode.ScreenSpaceCamera && canvas.worldCamera == null;
if (isOverlay || noCamera)
{
result = screenPosition;
}
else
{
var ray = canvas.worldCamera.ScreenPointToRay(screenPosition);
var plane = new Plane(canvasRect.forward, canvasRect.position);
float distance;
plane.Raycast(ray, out distance);
result = canvasRect.InverseTransformPoint(ray.origin + (ray.direction * distance));
min = - Vector2.Scale(max, canvasRect.pivot);
max = canvasSize - min;
}
result.x = Mathf.Clamp(result.x, min.x, max.y);
result.y = Mathf.Clamp(result.y, min.x, max.y);
return result;
}
示例5: GetWorldPointInWidget
Vector3 GetWorldPointInWidget(RectTransform target, Vector3 worldPoint)
{
return target.InverseTransformPoint(worldPoint);
}
示例6: ScreenPointToLocalPointInRectangle
public static bool ScreenPointToLocalPointInRectangle(RectTransform rect, Vector2 screenPoint, Camera cam, out Vector2 localPoint)
{
localPoint = Vector2.zero;
Vector3 worldPoint;
if (!RectTransformUtility.ScreenPointToWorldPointInRectangle(rect, screenPoint, cam, out worldPoint))
return false;
localPoint = (Vector2) rect.InverseTransformPoint(worldPoint);
return true;
}