Unity Bounds 边界框包围盒

Represents an axis aligned bounding box.

表示一个轴对齐的边界框。

An axis-aligned bounding box, or AABB for short, is a box aligned with coordinate axes and fully enclosing some object. Because the box is never rotated with respect to the axes, it can be defined by just its center and extents, or alternatively by min and max points.

一个轴对齐边界框,或AABB的简称,是一个坐标对齐的框(盒子)并且完全封闭一些对象。由于这个框(盒子)不会相对轴进行旋转,它只能通过center(中心)和extents(范围)进行定义,或者选择min(小)和 max(大)点。

                                       

Bounds is used by Collider.bounds, Mesh.bounds, Renderer.bounds.

边界框被用于Collider.bounds, Mesh.bounds, Renderer.bounds。

 

Variables  变量

center

中心

The center of the bounding box.

边界框(包围盒子)的中心

size

尺寸

The total size of the box. This is always twice as large as the extents.

盒子的总尺寸。这(尺寸size)总是extents(范围)的两倍大

extents

范围

The extents of the box. This is always half of the size.

边框(盒子)的范围。这(范围extents)总是size(尺寸)的一半

min

最小值

The minimal point of the box. This is always equal to center-extents.

框(盒子)的最小点,这总是等于center-extents(中心减范围)

max

最大值

The maximal point of the box. This is always equal to center extents.

框(盒子)的最大点,这总是等于center extents(中心加范围)

                                       于飞 unity

Constructors  构造函数 

Bounds

边界框(包围盒子)

Creates new Bounds with a given center and total size. Bound extents will be half the given size.

使用给定中心和总尺寸来创建新边界框。边界框范围将为给定尺寸的一半。

 

Functions  函数

SetMinMax

设置最小最大

Sets the bounds to the min and max value of the box.

设置边界框的最小和最大值

Encapsulate

封装

Grows the Bounds to include the point.

增大边界框来包含这个点

Expand

扩大

Expand the bounds by increasing its size by amount along each side.

通过增加总数的大小(尺寸)延长每条边的长度来扩大

Intersects

相交

Does another bounding box intersect with this bounding box?

另一个边界框是否与这个边界框相交?

Contains

包含

Is point contained in the bounding box?

这个点是否被包含在边界框内?

SqrDistance

平方距离

The smallest squared distance between the point and this bounding box.

这个点和边界框之间的最小平方距离。

IntersectRay

相交射线

Does ray intersect this bounding box?

射线可以与这个边界框相交么?

ToString

转换为“字符串”

Returns a nicely formatted string for the bounds.

返回边界框已经格式化好的字符串。

 

                                         于飞 unity

Bounds.Bounds   边框

 

static function Bounds (center : Vector3, size : Vector3) : Bounds

 

Description  描述

Creates new Bounds with a given center and total size. Bound extents will be half the given size.

创建新边界和给定center(中心)大小的总和(尺寸和)。边界框范围将是给定尺寸的一半。

JS:

// Create pillar bounding box centered at the origin

//在框内中央的原点创建支点建筑
var bounds = Bounds (Vector3.zero, Vector3 (1, 2, 1));

                                         于飞 unity

 

C#::

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public Bounds bounds = new Bounds(Vector3.zero, new Vector3(1, 2, 1));
}

 

 

Bounds.IntersectRay  相交射线

 

function IntersectRay (ray : Ray) : boolean

Description  描述

Does ray intersect this bounding box?

射线是否与这个边界框相交?

                                         于飞 unity

 

JS:

// Creates a ray that points from the origin to the infinity among the z Axis.

//创建一个射线沿着Z轴从原点到无穷(远)

// And prints if the transform touched the ray.

//如果transform(转换)遇到射线,就输出
var ra : Ray  = new Ray (Vector3.zero, Vector3.forward);;

function Update () {
    // Color ra in the scene editor.

//在场景编辑器中赋予射线颜色

    Debug.DrawRay (Vector3.zero, Vector3.forward * 999, Color.green);
    var bounds : Bounds = transform.collider.bounds;
    if (bounds.IntersectRay (ra))
        Debug.Log("Touched the ray");
}

 

C#:

using UnityEngine;
using System.Collections;
 

                                         于飞 unity

public class example : MonoBehaviour {
    public Ray ra = new Ray(Vector3.zero, Vector3.forward);
    void Update() {
        Debug.DrawRay(Vector3.zero, Vector3.forward * 999, Color.green);
        Bounds bounds = transform.collider.bounds;
        if (bounds.IntersectRay(ra))
            Debug.Log("Touched the ray");
       
    }
}

 

function IntersectRay (ray : Ray, out distance : float) : boolean

Description  描述

Does ray intersect this bounding box?

射线是否与这个边界框相交?

 

When IntersectRay returns true distance will be the distance to the ray's origin.

当IntersectRay(相交线)返回为真时, distance(距离)为射线到原点的距离。

                                         于飞 unity

 

 

JS:

// Creates a ray that points from the origin to 10 units among the z Axis.

//创建一个射线,沿着Z轴,从原点到10个单位的距离

// And prints if the transform touched the ray.
//如果transform(转换)遇到射线就输出。

var ra : Ray = new Ray (Vector3.zero, Vector3.forward);;
var t : float = 10.0;

function Update () {
    // Color ra in the scene editor.

//在场景编辑器中赋予射线颜色

    Debug.DrawRay (Vector3.zero, Vector3.forward * 10, Color.green);
    var bounds : Bounds = transform.collider.bounds;
    if (bounds.IntersectRay (ra, t))
        Debug.Log("Touched the ray");
}

                                         于飞 unity

 

C#:

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public Ray ra = new Ray(Vector3.zero, Vector3.forward);
    public float t = 10.0F;
    void Update() {
        Debug.DrawRay(Vector3.zero, Vector3.forward * 10, Color.green);
        Bounds bounds = transform.collider.bounds;
        if (bounds.IntersectRay(ra, out t))
            Debug.Log("Touched the ray");
       
    }
}

                                         于飞 unity

 

Bounds.SetMinMax  设置最小最大

 

function SetMinMax (min : Vector3, max : Vector3) : void

Description  描述

Sets the bounds to the min and max value of the box.

设置边界框的最小最大值

Using this function is faster than assigning min and max separately.

使用这个函数比单独分配最小最大值要快。

原文地址:https://blog.csdn.net/qq_37524903/article/details/113625126

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


这篇文章主要介绍了Unity游戏开发中外观模式是什么意思,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家...
这篇文章主要介绍Unity中地面检测方案的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!1.普通射线在角色坐标(一般是脚底)...
这篇文章主要介绍了Unity游戏开发中如何消除不想要的黄色警告,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带...
这篇文章主要介绍了Unity中有多少种渲染队列,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解
这篇文章主要介绍Unity中如何实现Texture,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!了解Texture2D 如上图,Texture2D是一张
小编给大家分享一下Unity中DOTS要实现的特点有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让...
这篇文章给大家分享的是有关unity中如何实现UGUI遮罩流光特效的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。下面是核心shader:Sh...
这篇文章主要为大家展示了“Unity中如何实现3D坐标转换UGUI坐标”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下...
这篇文章主要介绍了Unity游戏开发中设计模式的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家...
这篇文章主要介绍了Unity中如何实现仿真丝袜渲染,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了...
这篇文章给大家分享的是有关Unity插件OVRLipSync有什么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。项目需要接入对话口型动...
这篇文章主要介绍了Unity性能优化之DrawCall的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家...
这篇文章给大家分享的是有关Unity给力插件之Final IK怎么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。这插件有什么用:一般游...
这篇文章给大家分享的是有关Unity中如何内嵌网页插件UniWebView的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。一、常见Unity中内...
小编给大家分享一下Unity如何做流体物理的几个轮子,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让...
小编给大家分享一下Unity中Lod和Occlusion Culling的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收...
这篇文章将为大家详细讲解有关Unity中LineRenderer与TrailRenderer有什么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获...
这篇文章主要介绍了Unity中coroutine问题的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起...
这篇文章将为大家详细讲解有关unity中spine怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。骨骼动画首先我们来看到...
这篇文章主要为大家展示了“Unity Shader后处理中如何实现简单均值模糊”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学...