第一种方法:使用RectTransformUtility函数 使用Unity中的RectTransformUtility.ScreenPointToLocalPointInRectangle()可以将屏幕坐标转化为相对RectTransform的本地坐标。 然后再使用RectTransform的Contains()方法就可以判断某个坐标点是否在该RectTransform区域
public void OnDrag(PointerEventData eventData){Vector2 newPos;//将屏幕空间转换为UI的相对父对象的转换RectTransformUtility.ScreenPointToLocalPointInRectangle(this.transform.parent as RectTransform,eventData.position,eventData.enterEventCamera,out newPos);this.transform.localPosition = newPos;print(newPos);} ...
GUILayoutUtility:这几个方法是为编辑器面板布局预留一些空间,如下图就是一种典型的新应用: publicoverridevoidOnInspectorGUI(){Rectrect=GUILayoutUtility.GetRect(200,100);Texture2Dtexture2D=Resources.Load<Texture2D>("title");texture2D.Apply();GUI.DrawTexture(rect,texture2D);GUILayout.Space(20);if(GUI...
(RectTransform rect, Vector2 screenPoint, Camera cam, out Vector3 worldPoint) { return RectTransformUtility.ScreenPointToWorldPointInRectangle(rect, screenPoint, cam, out worldPoint); } #endregion #region 屏幕坐标转UGUI坐标 /// /// 屏幕坐标转某个RectTransform下的localPosition坐标 /// /// ...
Utility class containing helper methods for working with RectTransform. Static Methods FlipLayoutAxes Flips the horizontal and vertical axes of the RectTransform size and alignment, and optionally its children as well. FlipLayoutOnAxis Flips the alignment of the RectTransform along the horizontal or vert...
RectTransformUtility.PixelAdjustRect public static Rect PixelAdjustRect (RectTransform rectTransform, Canvas canvas); 戻り値 Rect ピクセル調整された矩形。 説明 Rect Transform を指定すると、ピクセル精度座標で角のポイントを返します。 Did you find this page useful? Please give it a rating: Rep...
而UGUI中Canvas的坐标系以左下角为原点,因此需要先进行坐标转换,然后再通过Rect Transform Utility类中的RectangleContainsScreenPoint函数可以判断RectTransform是否包含指定位置: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 using UnityEngine; using UnityEditor; using System.Linq; using System.Collections.Gener...
}#region屏幕坐标转UGUI坐标//////屏幕坐标转某个RectTransform下的localPosition坐标///publicstaticboolScreenPointToLocalPointInRectangle(RectTransform rect, Vector2 screenPoint,outVector2 localPoint) {returnRectTransformUtility.ScreenPointToLocalPointInRectangle(rect, screenPoint, UGUICamera,outlocalPoint);...
2、RectTransformUtility.RectangleContainsScreenPoint(target, sp);矩形区域包不包含鼠标点击的点 3、在GuideController脚本中改 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; // 枚举,引导的类型 public enum GuideType { Rect, Circle } //组件:需要的组件...
4、RectTransformUtility.ScreenPointToLocalPointInRectangle:屏幕坐标转换为局部坐标 参数: RectTransform rect ---转换为谁的局部坐标 Vector2 screenPoint ---要转换的屏幕坐标 Camera cam, ---相机 out Vector2 localPoint --- 输出的局部坐标 //讲四个角的世界...