本文整理汇总了C#中GameObject.GetBounds方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.GetBounds方法的具体用法?C# GameObject.GetBounds怎么用?C# GameObject.GetBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameObject
的用法示例。
在下文中一共展示了GameObject.GetBounds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GizmosDrawCollider
public static void GizmosDrawCollider( GameObject go, Color color, Vector3 offset, bool recursive = false )
{
if ( recursive )
for ( int i = 0 ; i < go.transform.childCount; i++ )
GizmosDrawCollider ( go.transform.GetChild ( i ).gameObject, color, offset, recursive );
PolygonCollider2D poly = go.GetComponent<PolygonCollider2D>();
if ( poly != null )
{
Vector3 position = go.transform.position + (Vector3)poly.offset + offset;
Gizmos.color = color;
for ( int i = 0; i < poly.points.Length - 1; i++ )
Gizmos.DrawLine
(
position + (Vector3)poly.points[i],
position + (Vector3)poly.points[i + 1]
);
Gizmos.DrawLine
(
position + (Vector3)poly.points[0],
position + (Vector3)poly.points[poly.points.Length - 1]
);
Gizmos.color = Color.white;
return;
}
CircleCollider2D circ = go.GetComponent<CircleCollider2D> ();
if ( circ != null )
{
Vector3 position = go.transform.position + (Vector3)circ.offset + offset;
// Gizmos.color = Color.clear;
// float r2 = circ.radius * 1.5f;
// Gizmos.DrawCube ( position, new Vector3 ( r2, r2, r2 ) );
// Gizmos.color = Color.white;
Handles.color = color;
Handles.DrawWireDisc ( position, Vector3.back, circ.radius );
Handles.color = Color.white;
return;
}
BoxCollider2D box2d = go.GetComponent<BoxCollider2D> ();
if ( box2d != null )
{
Vector3 position = go.transform.position + (Vector3)box2d.offset + offset;
// Gizmos.color = Color.clear;
// Gizmos.DrawCube ( position, box.size );
// Gizmos.color = Color.white;
Gizmos.color = color;
Gizmos.DrawWireCube ( position, box2d.size );
Gizmos.color = Color.white;
return;
}
BoxCollider box = go.GetComponent<BoxCollider> ();
if ( box != null )
{
Vector3 position = go.transform.position + (Vector3)box.center + offset;
// Gizmos.color = Color.clear;
// Gizmos.DrawCube ( position, box.size );
// Gizmos.color = Color.white;
Matrix4x4 matrixCopy = Gizmos.matrix;
Gizmos.matrix = Matrix4x4.TRS ( position, go.transform.rotation, go.transform.lossyScale );
Gizmos.color = color;
Gizmos.DrawWireCube ( /*position*/Vector3.zero, box.size );
Gizmos.color = Color.white;
Gizmos.matrix = matrixCopy;
return;
}
Bounds bounds = go.GetBounds ( GetBoundsOption.ChildOnly );
if ( bounds.size != Vector3.zero )
{
Vector3 position = bounds.center + offset;
// Gizmos.color = Color.clear;
// Gizmos.DrawCube ( offset, bounds.size );
// Gizmos.color = Color.white;
Gizmos.color = color;
Gizmos.DrawWireCube ( position, bounds.size );
Gizmos.color = Color.white;
return;
}
//.........这里部分代码省略.........
示例2: PixelCollisionHFlip
private bool PixelCollisionHFlip(GameObject other, Color[] dataA, Color[] dataB)
{
int top = Math.Max(bounds.Top, other.GetBounds().Top);
int bottom = Math.Min(bounds.Bottom, other.GetBounds().Bottom);
int left = Math.Max(bounds.Left, other.GetBounds().Left);
int right = Math.Min(bounds.Right, other.GetBounds().Right);
for (int y = top; y < bottom; y++)
{
for (int x = left; x < right; x++)
{
Color colorA = dataA[(int)(bounds.Width / sprite.GetRealScale().X) - 1 - (int)((x - bounds.Left) / sprite.GetRealScale().X) +
(int)((int)((y - bounds.Top) / sprite.GetRealScale().Y) * (bounds.Width / sprite.GetRealScale().X))];
Color colorB = dataB[(int)((x - other.GetBounds().Left) / other.sprite.GetRealScale().X) +
(int)((int)((y - other.GetBounds().Top) / other.sprite.GetRealScale().Y) * (other.GetBounds().Width / other.sprite.GetRealScale().X))];
if (colorA.A != 0 && colorB.A != 0) // Collision
return true;
}
}
return false;
}
示例3: HandlesDrawCollider
public static void HandlesDrawCollider( GameObject go, Color color, Vector3 offset )
{
PolygonCollider2D poly = go.GetComponent<PolygonCollider2D> ();
if ( poly != null )
{
Vector3 position = go.transform.position + (Vector3)poly.offset + offset;
Handles.color = color;
for ( int i = 0; i < poly.points.Length - 1; i++ )
Handles.DrawLine
(
position + (Vector3)poly.points[i],
position + (Vector3)poly.points[i + 1]
);
Handles.DrawLine
(
position + (Vector3)poly.points[0],
position + (Vector3)poly.points[poly.points.Length - 1]
);
Gizmos.color = Color.white;
return;
}
CircleCollider2D circ = go.GetComponent<CircleCollider2D> ();
if ( circ != null )
{
Vector3 position = go.transform.position + (Vector3)circ.offset + offset;
Handles.color = Color.clear;
float r2 = circ.radius * 1.5f;
HandlesDrawWireCube ( position, new Vector3 ( r2, r2, r2 ) );
Handles.color = Color.white;
return;
}
BoxCollider2D box = go.GetComponent<BoxCollider2D> ();
if ( box != null )
{
Vector3 position = go.transform.position + (Vector3)box.offset + offset;
Handles.color = color;
HandlesDrawWireCube ( position, box.size );
Handles.color = Color.white;
return;
}
Bounds bounds = go.GetBounds ( GetBoundsOption.ChildOnly );
if ( bounds.size != Vector3.zero )
{
Vector3 position = bounds.center + offset;
Handles.color = color;
HandlesDrawWireCube ( position, bounds.size );
Handles.color = Color.white;
return;
}
}