本文整理汇总了C#中UnityEngine.Bounds.IntersectRay方法的典型用法代码示例。如果您正苦于以下问题:C# Bounds.IntersectRay方法的具体用法?C# Bounds.IntersectRay怎么用?C# Bounds.IntersectRay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Bounds
的用法示例。
在下文中一共展示了Bounds.IntersectRay方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClampToBounds
public static Vector3 ClampToBounds( this Vector3 v, Bounds bounds )
{
Vector3 clamp = v;
Ray clampRay = new Ray( Vector2.zero, v );
float dist;
if( bounds.IntersectRay( clampRay, out dist ) ) {
clamp = Vector3.ClampMagnitude( v, dist );
}
return clamp;
}
示例2: Internal_RaycastRef
internal bool Internal_RaycastRef(Ray ray, ref UIHotSpot.Hit hit)
{
Bounds bound = new Bounds(this.center, this.size);
if (!bound.IntersectRay(ray, out hit.distance))
{
return false;
}
hit.point = ray.GetPoint(hit.distance);
hit.normal = -ray.direction;
return true;
}
示例3: BoundsWithinPoints
// BoundsWithinPoints //
// Cchecks if passed bounds contains either point (return false) //
// Then Fires rays between both points to check if the bounds are contained within both rays (return true) //
public static bool BoundsWithinPoints( Vector3 point_a, Vector3 point_b, Bounds bounds )
{
// If the start or end point are within the object, do nothing
if( bounds.Contains( point_a ) || bounds.Contains( point_b ) )
{
return false;
}
// If the object is fully on both rays
Ray ray_forward = new Ray( point_a, point_b - point_a );
Ray ray_backward = new Ray( point_b, point_a - point_b );
if( bounds.IntersectRay( ray_forward ) && bounds.IntersectRay( ray_backward ))
{
return true;
}
else
{
return false;
}
}
示例4: HandleIntersectionRouting
void HandleIntersectionRouting()
{
FastList<NodeLaneMarker> nodeMarkers;
if (m_nodeMarkers.TryGetValue(m_selectedNode, out nodeMarkers))
{
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
NodeLaneMarker hoveredMarker = null;
Bounds bounds = new Bounds(Vector3.zero, Vector3.one);
for (int i = 0; i < nodeMarkers.m_size; i++)
{
NodeLaneMarker marker = nodeMarkers.m_buffer[i];
if (!IsActive(marker))
continue;
bounds.center = marker.m_position;
if (bounds.IntersectRay(mouseRay))
{
hoveredMarker = marker;
marker.m_size = 2f;
}
else
marker.m_size = 1f;
}
if (hoveredMarker != null && Input.GetMouseButtonUp(0))
{
if (m_selectedMarker == null)
{
m_selectedMarker = hoveredMarker;
}
else if (RoadManager.RemoveLaneConnection(m_selectedMarker.m_lane, hoveredMarker.m_lane))
{
m_selectedMarker.m_connections.Remove(hoveredMarker);
}
else if (RoadManager.AddLaneConnection(m_selectedMarker.m_lane, hoveredMarker.m_lane))
{
m_selectedMarker.m_connections.Add(hoveredMarker);
}
}
}
if (Input.GetMouseButtonUp(1))
{
if (m_selectedMarker != null)
m_selectedMarker = null;
else
m_selectedNode = 0;
}
}
示例5: IsPickingParticle
// Control --------------------------------------------------------------------------
public bool IsPickingParticle(Ray ray)
{
if (IsParticle() == false)
return false;
if (m_WireObject == null)
return false;
List<Vector4> listPos = m_WireObject.GetLastParticlePostions();
foreach (Vector4 pos in listPos)
{
Bounds bounds = new Bounds(new Vector3(pos.x, pos.y, pos.z), new Vector3(pos.w, pos.w, pos.w));
if (bounds.IntersectRay(ray))
return true;
}
return false;
}
示例6: RaycastSide
private PivotType RaycastSide(SuperCube aCube, Ray aRay) {
aRay.origin = aCube.transform.InverseTransformPoint(aRay.origin);
aRay.direction = aCube.transform.InverseTransformDirection(aRay.direction);
aRay.direction.Normalize();
Vector3 size = aCube.Extents / 2;
PivotType side = PivotType.None;
float closest = float.MaxValue;
float dist = 0;
Bounds bounds = new Bounds();
bounds.center = Vector3.zero;
bounds.extents = size;
if (bounds.IntersectRay(aRay, out dist)) {
side = PivotType.All;
closest = dist + 0.1f;
}
if (CheckSide(aRay, new Vector3( 0, 0,-1), size.z, Mathf.Min(size.x, size.y), closest, out dist)) {
closest = dist;
side = PivotType.Back;
}
if (CheckSide(aRay, new Vector3( 0, 0, 1), size.z, Mathf.Min(size.x, size.y), closest, out dist)) {
closest = dist;
side = PivotType.Front;
}
if (CheckSide(aRay, new Vector3(-1, 0, 0), size.x, Mathf.Min(size.y, size.z), closest, out dist)) {
closest = dist;
side = PivotType.Right;
}
if (CheckSide(aRay, new Vector3( 1, 0, 0), size.x, Mathf.Min(size.y, size.z), closest, out dist)) {
closest = dist;
side = PivotType.Left;
}
if (CheckSide(aRay, new Vector3( 0,-1, 0), size.y, Mathf.Min(size.x, size.z), closest, out dist)) {
closest = dist;
side = PivotType.Top;
}
if (CheckSide(aRay, new Vector3( 0, 1, 0), size.y, Mathf.Min(size.x, size.z), closest, out dist)) {
closest = dist;
side = PivotType.Bottom;
}
return side;
}
示例7: ObjectRaycast
/**
* Return the nearest hit object in scene. Does not require a collider.
*/
public static GameObject ObjectRaycast(Ray ray, IEnumerable<GameObject> objects)
{
Renderer renderer;
float distance = Mathf.Infinity;
float best = Mathf.Infinity;
GameObject obj = null;
Bounds bounds = new Bounds(Vector3.zero, Vector3.one);
pb_RaycastHit hit;
foreach(GameObject go in objects)
{
Ray localRay = TransformRay(ray, go.transform);
renderer = go.GetComponent<Renderer>();
if( renderer != null )
{
if( renderer.bounds.IntersectRay(ray, out distance) )
{
MeshFilter mf = go.GetComponent<MeshFilter>();
if( mf != null && mf.sharedMesh != null && MeshRaycast(mf.sharedMesh, localRay, out hit))
{
if(hit.distance < best)
{
best = hit.distance;
obj = go;
}
}
}
}
else
{
bounds.center = go.transform.position;
if(bounds.IntersectRay(ray, out distance))
{
if( distance < best )
{
best = distance;
obj = go;
}
}
}
}
return obj;
}