當前位置: 首頁>>代碼示例>>C#>>正文


C# RectTransform.InverseTransformPoint方法代碼示例

本文整理匯總了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;
		}
開發者ID:guozanhua,項目名稱:UnityDecompiled,代碼行數:11,代碼來源:RectTransformUtility.cs

示例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;
     }
 }
開發者ID:Benedict-SC,項目名稱:doom-dial,代碼行數:22,代碼來源:InputWatcher.cs

示例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;
 }
開發者ID:CarlosHBC,項目名稱:UnityDecompiled,代碼行數:11,代碼來源:RectTransformUtility.cs

示例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;
		}
開發者ID:matmuze,項目名稱:cellVIEW_color,代碼行數:39,代碼來源:Utilites.cs

示例5: GetWorldPointInWidget

 Vector3 GetWorldPointInWidget(RectTransform target, Vector3 worldPoint)
 {
     return target.InverseTransformPoint(worldPoint);
 }
開發者ID:osangar88,項目名稱:GameFramework,代碼行數:4,代碼來源:ScrollRectEnsureVisible.cs

示例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;
 }
開發者ID:BlakeTriana,項目名稱:unity-decompiled,代碼行數:9,代碼來源:RectTransformUtility.cs


注:本文中的UnityEngine.RectTransform.InverseTransformPoint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。