예제 #1
0
        public override void OnEnable()
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                childrenParent.localScale = Vector3.one.Divide(trs.lossyScale);
                BoxCollider boxCollider = collider as BoxCollider;
                if (autoSetBoxCollider && boxCollider != null)
                {
                    BoxCollider _boxCollider = gameObject.AddComponent <BoxCollider>();
                    boxCollider.center = _boxCollider.center;
                    boxCollider.size   = _boxCollider.size;
                    DestroyImmediate(_boxCollider);
                }
                if (autoSetMass && rigid != null)
                {
                    Bounds bounds = GetComponent <MeshRenderer>().bounds;
                    rigid.mass = bounds.size.x * bounds.size.y * bounds.size.z;
                    for (int i = 0; i < childrenParent.childCount; i++)
                    {
                        Transform child = childrenParent.GetChild(i);
                        bounds      = child.GetComponent <MeshRenderer>().bounds;
                        rigid.mass += bounds.size.x * bounds.size.y * bounds.size.z;
                        Piston piston = child.GetComponent <Piston>();
                        if (piston != null)
                        {
                            piston.SetMass();
                            rigid.mass += piston.rigid.mass;
                        }
                    }
                }
            }
#endif
            base.OnEnable();
        }
예제 #2
0
 public void SetMass()
 {
     rigid.mass = axelTrs.lossyScale.x * axelTrs.lossyScale.y * axelTrs.lossyScale.z;
     for (int i = 0; i < physicsObject.childrenParent.childCount; i++)
     {
         Transform child  = physicsObject.childrenParent.GetChild(i);
         Piston    piston = child.GetComponent <Piston>();
         if (piston != null)
         {
             piston.SetMass();
             rigid.mass += piston.rigid.mass;
         }
         else
         {
             rigid.mass += child.lossyScale.x * child.lossyScale.y * child.lossyScale.z;
         }
     }
 }