(EDITED)
은 일부 검색 후, 나는 당신을 위해이 excelent 방법 here을 발견
public static Rect ObjectBounds(GameObject go)
{
Vector3 cen = go.GetComponent<Renderer>().bounds.center;
Vector3 ext = go.GetComponent<Renderer>().bounds.extents;
Vector2[] extentPoints = new Vector2[8]
{
HandleUtility.WorldToGUIPoint(new Vector3(cen.x-ext.x, cen.y-ext.y, cen.z-ext.z)),
HandleUtility.WorldToGUIPoint(new Vector3(cen.x+ext.x, cen.y-ext.y, cen.z-ext.z)),
HandleUtility.WorldToGUIPoint(new Vector3(cen.x-ext.x, cen.y-ext.y, cen.z+ext.z)),
HandleUtility.WorldToGUIPoint(new Vector3(cen.x+ext.x, cen.y-ext.y, cen.z+ext.z)),
HandleUtility.WorldToGUIPoint(new Vector3(cen.x-ext.x, cen.y+ext.y, cen.z-ext.z)),
HandleUtility.WorldToGUIPoint(new Vector3(cen.x+ext.x, cen.y+ext.y, cen.z-ext.z)),
HandleUtility.WorldToGUIPoint(new Vector3(cen.x-ext.x, cen.y+ext.y, cen.z+ext.z)),
HandleUtility.WorldToGUIPoint(new Vector3(cen.x+ext.x, cen.y+ext.y, cen.z+ext.z))
};
Vector2 min = extentPoints[0];
Vector2 max = extentPoints[0];
foreach (Vector2 v in extentPoints)
{
min = Vector2.Min(min, v);
max = Vector2.Max(max, v);
}
return new Rect(min.x, min.y, max.x - min.x, max.y - min.y);
}
구형 영역에 메소드를 호출하고 화면에 그리기의 예 :
void OnGUI() //EditorGUI.DrawRect must be in this function name
{
//create a rect using the method and the GameObject this script is attached to (gameObject)
Rect boundsRect = new Rect(GUIRectWithObject(gameObject));
//draw a blue rect on the box of the rect (will hide the object)
EditorGUI.DrawRect(boundsRect, Color.blue);
}
너는 직사각형의 너비를 얻으려면 :
float boundswidth = boundsRect.width;
당신이 달성하고자하는 것은 전화가 어떤 종류의 마커 (종이 일 수 있음)를 처음으로 인식 할 수있는 경우에만 가능합니다. 그러면 3D 환경을 실제 환경에 매핑 할 수 있습니다. 그렇지 않으면 객체의 실제 크기 (센티미터 단위)를 추측해야합니다. 이미지 크기가 10cm인지 여부를 모르기 때문에 크기를 알 수 없습니다. 물체로부터 1m. 개체에서. – Hristo