【发布时间】:2014-01-20 07:42:38
【问题描述】:
我需要找到一个小部件及其所有孩子的边界。我尝试使用以下代码,但得到了一个奇怪的输出。小部件有宽度和高度超过 100 像素的子级,输出大约为 1。
Vector3 widgetBounds = NGUIMath.CalculateRelativeWidgetBounds(this.transform).size;
我做错了什么?
谢谢。
【问题讨论】:
标签: c# widget unity3d bounds ngui
我需要找到一个小部件及其所有孩子的边界。我尝试使用以下代码,但得到了一个奇怪的输出。小部件有宽度和高度超过 100 像素的子级,输出大约为 1。
Vector3 widgetBounds = NGUIMath.CalculateRelativeWidgetBounds(this.transform).size;
我做错了什么?
谢谢。
【问题讨论】:
标签: c# widget unity3d bounds ngui
这是你想要的吗?
// 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;
}
【讨论】:
Encapsulate() 而不是SetMinMax(),如此壮观。 :D