public void Encapsulate(RectTransform rectTransform) { var rectBounds = new RectBounds(rectTransform); Encapsulate(rectBounds.LeftUpPos); Encapsulate(rectBounds.RightDownPos); }
/// <summary> /// 使用Debug画方块 /// </summary> public static void DrawRectRange(RectBounds rectBounds, Color color) { Debug.DrawLine(rectBounds.LeftUpPos, rectBounds.RightUpPos, color); Debug.DrawLine(rectBounds.LeftDownPos, rectBounds.RightDownPos, color); Debug.DrawLine(rectBounds.LeftUpPos, rectBounds.LeftDownPos, color); Debug.DrawLine(rectBounds.RightUpPos, rectBounds.RightDownPos, color); }
private void FitMask() { RectBounds rectBounds = new RectBounds(scrollGallery.Splits[1]); for (int i = 2; i < scrollGallery.Splits.Length - 1; i++) { var curSplit = scrollGallery.Splits[i]; rectBounds.Encapsulate(curSplit); } var listChildren = ListPool <Transform> .Get(); foreach (Transform aTrans in this.maskTransform) { listChildren.Add(aTrans); } listChildren.ForEach(temp => temp.SetParent(this.maskTransform.parent)); Undo.RecordObject(this.maskTransform, "FitMask Main"); this.maskTransform.position = rectBounds.center; var lossyScale = this.maskTransform.lossyScale; this.maskTransform.sizeDelta = new Vector2(rectBounds.width / lossyScale.x, rectBounds.height / lossyScale.y); listChildren.ForEach(temp => temp.SetParent(this.maskTransform)); ListPool <Transform> .Release(listChildren); Debug.Log("FitMask"); }
/// <summary> /// 使用Debug画方块 /// </summary> public static void DrawRectRange(RectBounds rectRange, float z, Color color) { var allPos = rectRange.GetAllPos(z); Debug.DrawLine(allPos[0], allPos[1], color); Debug.DrawLine(allPos[1], allPos[3], color); Debug.DrawLine(allPos[2], allPos[3], color); Debug.DrawLine(allPos[0], allPos[2], color); }
public static RectBounds GetRectBounds(Vector2 worldPos, float worldWidth, float worldHeight) { var rectBounds = new RectBounds(); rectBounds.left = worldPos.x - worldWidth / 2; rectBounds.right = worldPos.x + worldWidth / 2; rectBounds.up = worldPos.y + worldHeight / 2; rectBounds.up = worldPos.y - worldHeight / 2; return(rectBounds); }
public bool Overlaps(RectBounds other) { if (this.right >= other.left && this.left <= other.right && this.down <= other.up && this.up >= other.down) { return(true); } else { return(false); } }
public static RectBounds GetRectBounds(RectTransform rectTransform, out float worldPosZ) { var pivot = rectTransform.pivot; var width = rectTransform.rect.width * rectTransform.lossyScale.x; var height = rectTransform.rect.height * rectTransform.lossyScale.y; var rectBounds = new RectBounds(); rectBounds.left = rectTransform.transform.position.x + width * (-pivot.x); rectBounds.right = rectTransform.transform.position.x + width * (1 - pivot.x); rectBounds.up = rectTransform.transform.position.y + height * (1 - pivot.y); rectBounds.down = rectTransform.transform.position.y + height * (-pivot.y); worldPosZ = rectTransform.position.z; return(rectBounds); }
public static RectBounds GetRectBounds(Vector2 pivot, Vector3 lossyScale, float width, float height, Vector3 worldPosition, RectBounds rectRange = null) { width = width * lossyScale.x; height = height * lossyScale.y; if (rectRange == null) { rectRange = new RectBounds(); } rectRange.left = worldPosition.x + width * (-pivot.x); rectRange.right = worldPosition.x + width * (1 - pivot.x); rectRange.up = worldPosition.y + height * (1 - pivot.y); rectRange.down = worldPosition.y + height * (-pivot.y); return(rectRange); }
public static void DrawRect(RectBounds rectBounds, float worldPosZ, Color color) { Vector3 leftUpPos = rectBounds.LeftUpPos; Vector3 rightUpPos = rectBounds.RightUpPos; Vector3 rightDownPos = rectBounds.RightDownPos; Vector3 leftDownPos = rectBounds.LeftDownPos; leftUpPos.z = worldPosZ; rightUpPos.z = worldPosZ; rightDownPos.z = worldPosZ; leftDownPos.z = worldPosZ; Debug.DrawLine(leftUpPos, rightUpPos, color); Debug.DrawLine(rightUpPos, rightDownPos, color); Debug.DrawLine(rightDownPos, leftDownPos, color); Debug.DrawLine(leftDownPos, leftUpPos, color); }
/// <summary> /// 获得RectTransform的边界,用一个来接收 /// </summary> public static RectBounds GetRectBounds(RectTransform rectTransform, RectBounds rectRange = null) { var pivot = rectTransform.pivot; var width = rectTransform.rect.width * rectTransform.lossyScale.x; var height = rectTransform.rect.height * rectTransform.lossyScale.y; if (rectRange == null) { rectRange = new RectBounds(); } rectRange.left = rectTransform.transform.position.x + width * (-pivot.x); rectRange.right = rectTransform.transform.position.x + width * (1 - pivot.x); rectRange.up = rectTransform.transform.position.y + height * (1 - pivot.y); rectRange.down = rectTransform.transform.position.y + height * (-pivot.y); return(rectRange); }