Renderer.bounds 边界框

var bounds : Bounds

Description描述

The bounding volume of the renderer (Read Only).

渲染器的边界框(只读)。

This is the axis-aligned bounding box fully enclosing the object in world space.

这是物体在世界空间坐标完全封闭的轴对齐的边界框。

Using bounds is convenient to make rough approximations about the object's location and its extents. For example, renderer.bounds.center often is more precise "center of the object" than transform.position - especially if the object is not symmetrical.

使用边界框很方便的制造物体的位置及扩展的粗略的近似值,例如,renderer.bounds.center大多数去情况下比transform.position是更精确的“物体的中心”,尤其是如果物体不是对称的。

See also Mesh.bounds property that returns bounds of the mesh in local space.

参考Mesh.bounds属性,返回在自身坐标的mesh的边界框。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public void Awake() {
		print(renderer.bounds.min.x);
		print(renderer.bounds.max.x);
	}
}
// Prints the left extreme point of the bounding volume on the x-axis
//打印边界框在x轴最左边的点
print(renderer.bounds.min.x);
// Prints the right extreme point of the bounding volume on the x-axis
//打印边界框在x轴最右边的点
print(renderer.bounds.max.x);

另一个例子

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void OnDrawGizmosSelected() {
		Vector3 center = renderer.bounds.center;
		float radius = renderer.bounds.extents.magnitude;
		Gizmos.color = Color.white;
		Gizmos.DrawWireSphere(center, radius);
	}
}
// Draws a wireframe sphere in the scene view, fully enclosing the object.
//在场景视图绘制一个线框球体,完全封闭的物体。
function OnDrawGizmosSelected () {
// A sphere that fully encloses the bounding box
//一个球,完全包围边界框
var center = renderer.bounds.center;
var radius = renderer.bounds.extents.magnitude;
// Draw it 绘制它
Gizmos.color = Color.white;
Gizmos.DrawWireSphere (center, radius);
}

参见: Bounds class, Mesh.bounds property.

最后修改:2010年12月17日 Friday 21:33

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。