當前位置: 首頁>>代碼示例>>C#>>正文


C# Rigidbody.GetComponents方法代碼示例

本文整理匯總了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;
    }
開發者ID:Edudjr,項目名稱:riftbdu,代碼行數:67,代碼來源:AddRemoveBodyUtil.cs


注:本文中的UnityEngine.Rigidbody.GetComponents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。