[英]How to calculate widget bounds?
我需要找到所有小部件的邊界。 我嘗試使用以下代碼,但得到了奇怪的輸出。 該小部件的子級寬度和高度均超過100像素,輸出約為1。
Vector3 widgetBounds = NGUIMath.CalculateRelativeWidgetBounds(this.transform).size;
我究竟做錯了什么?
謝謝。
這是您想要的嗎?
// copied from UIDragObject.UpdateBounds()
public static Bounds GetContentRectBounds(UIRect content, UIPanel uiPanel){
Matrix4x4 toLocal = uiPanel.transform.worldToLocalMatrix;
Vector3[] corners = content.worldCorners;
for( int i = 0; i < 4; ++i ){
corners[i] = toLocal.MultiplyPoint3x4(corners[i]);
}
Bounds mBounds = new Bounds(corners[0], Vector3.zero);
for( int i = 1; i < 4; ++i ){
mBounds.Encapsulate(corners[i]);
}
return mBounds;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.