本文整理汇总了C#中UnityEngine.Rigidbody.GetComponents方法的典型用法代码示例。如果您正苦于以下问题:C# Rigidbody.GetComponents方法的具体用法?C# Rigidbody.GetComponents怎么用?C# Rigidbody.GetComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Rigidbody
的用法示例。
在下文中一共展示了Rigidbody.GetComponents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBodyToLeapFromUnity
public Body AddBodyToLeapFromUnity(Rigidbody rigidbody)
{
LeapInteraction properties = rigidbody.GetComponent<LeapInteraction>();
if (rigidbody.collider && properties)
{
Collider[] colliders = rigidbody.GetComponents<Collider>();
Shape shape = new Shape();
foreach(Collider collider in colliders)
{
if (collider is SphereCollider)
{
float scale = rigidbody.transform.lossyScale.x;
SphereCollider sc = collider as SphereCollider;
shape = Shape.CreateSphere(sc.radius * scale);
}
else if (collider is CapsuleCollider)
{
float scale = rigidbody.transform.lossyScale.x;
CapsuleCollider cc = collider as CapsuleCollider;
shape = Shape.CreateCapsule((Shape.CapsuleOrientation)cc.direction, Math.Max(0f, cc.height / 2f - cc.radius) * scale, cc.radius * scale);
}
else if (collider is BoxCollider)
{
BoxCollider bc = collider as BoxCollider;
Vector3 scale = collider.transform.lossyScale;
shape = Shape.CreateBox(Vector3.Scale(bc.size, scale) / 2f, 0f);
}
}
if (shape != IntPtr.Zero)
{
Body body = new Body();//shape);
body.Shape = shape;
body.Mass = rigidbody.mass;
// Add body anchors.
for (int i = 0; i < rigidbody.transform.childCount; i++)
{
Transform child = rigidbody.transform.GetChild(i);
if (child.name.StartsWith("Anchor") || child.name.StartsWith("ClickAnchor"))
{
LeapTransform anchor = new LeapTransform();
anchor.Position = Vector3.Scale(child.localPosition - rigidbody.transform.rotation * TransformSyncUtil.GetCenterFromCollider(rigidbody.gameObject), rigidbody.transform.lossyScale);
anchor.Rotation = child.localRotation;
if (child.name.StartsWith("Anchor")) { body.Shape.AddAnchor(anchor); }
if (child.name.StartsWith("ClickAnchor"))
{
body.Shape.AddClickAnchor(anchor);
}
}
}
// Apply BodyProperties
properties.ApplyToBody(body);
Scene.AddBody(body);
BodyMapper.Add(rigidbody.gameObject, body);
rigidbody.maxAngularVelocity = 100.0f;
return body;
}
}
return null;
}