private void MultiPartJointBuildJoint(Part p, Part linkPart)
        {
            if (multiJointManager.CheckMultiJointBetweenParts(p, linkPart) || !multiJointManager.TrySetValidLinkedSet(p, linkPart))
            {
                return;
            }

            multiJointManager.RegisterMultiJointBetweenParts(p, linkPart, KJRJointUtils.BuildJoint(p, linkPart));
        }
示例#2
0
        public void MultiPartJointTreeChildren(Vessel v)
        {
            if (v.Parts.Count <= 1)
            {
                return;
            }

            List <Part> childPartsToConnect = new List <Part>();

            for (int i = 0; i < v.Parts.Count; ++i)
            {
                Part p = v.Parts[i];
                if (p.children.Count == 0 && !p.Modules.Contains("LaunchClamp") && KJRJointUtils.MaximumPossiblePartMass(p) > KJRJointUtils.settings.massForAdjustment)
                {
                    if (p.rb == null && p.Rigidbody != null)
                    {
                        p = p.RigidBodyPart;
                    }
                    childPartsToConnect.Add(p);
                }
            }


            Rigidbody rootRb = v.rootPart.Rigidbody;

            for (int i = 0; i < childPartsToConnect.Count; ++i)
            {
                Part p        = childPartsToConnect[i];
                Part linkPart = childPartsToConnect[i + 1 >= childPartsToConnect.Count ? 0 : i + 1];

                Rigidbody rigidBody = linkPart.Rigidbody;
                if (!p.rb || !rigidBody || p.rb == rigidBody)
                {
                    continue;
                }

                if (!multiJointManager.CheckMultiJointBetweenParts(p, linkPart) && multiJointManager.TrySetValidLinkedSet(p, linkPart))
                {
                    ConfigurableJoint betweenChildJoint;

                    betweenChildJoint = p.gameObject.AddComponent <ConfigurableJoint>();

                    betweenChildJoint.connectedBody = rigidBody;
                    betweenChildJoint.anchor        = Vector3.zero;
                    betweenChildJoint.axis          = Vector3.right;
                    betweenChildJoint.secondaryAxis = Vector3.forward;
                    betweenChildJoint.breakForce    = KJRJointUtils.settings.decouplerAndClampJointStrength;
                    betweenChildJoint.breakTorque   = KJRJointUtils.settings.decouplerAndClampJointStrength;

                    betweenChildJoint.xMotion        = betweenChildJoint.yMotion = betweenChildJoint.zMotion = ConfigurableJointMotion.Locked;
                    betweenChildJoint.angularXMotion = betweenChildJoint.angularYMotion = betweenChildJoint.angularZMotion = ConfigurableJointMotion.Locked;

                    multiJointManager.RegisterMultiJointBetweenParts(p, linkPart, betweenChildJoint);
                    //multiJointManager.RegisterMultiJoint(p, betweenChildJoint);
                    //multiJointManager.RegisterMultiJoint(linkPart, betweenChildJoint);
                }

                Part linkPart2;

                int part2Index = i + childPartsToConnect.Count / 2;
                if (part2Index >= childPartsToConnect.Count)
                {
                    part2Index -= childPartsToConnect.Count;
                }

                linkPart2 = childPartsToConnect[part2Index];
                rigidBody = linkPart2.Rigidbody;

                if (!p.rb || !rigidBody || p.rb == rigidBody)
                {
                    continue;
                }

                if (!multiJointManager.CheckMultiJointBetweenParts(p, linkPart2) && multiJointManager.TrySetValidLinkedSet(p, linkPart2))
                {
                    ConfigurableJoint betweenChildJoint2;

                    betweenChildJoint2 = p.gameObject.AddComponent <ConfigurableJoint>();

                    betweenChildJoint2.connectedBody = rigidBody;
                    betweenChildJoint2.anchor        = Vector3.zero;
                    betweenChildJoint2.axis          = Vector3.right;
                    betweenChildJoint2.secondaryAxis = Vector3.forward;
                    betweenChildJoint2.breakForce    = KJRJointUtils.settings.decouplerAndClampJointStrength;
                    betweenChildJoint2.breakTorque   = KJRJointUtils.settings.decouplerAndClampJointStrength;

                    betweenChildJoint2.xMotion        = betweenChildJoint2.yMotion = betweenChildJoint2.zMotion = ConfigurableJointMotion.Locked;
                    betweenChildJoint2.angularXMotion = betweenChildJoint2.angularYMotion = betweenChildJoint2.angularZMotion = ConfigurableJointMotion.Locked;

                    multiJointManager.RegisterMultiJointBetweenParts(p, linkPart2, betweenChildJoint2);
                    //multiJointManager.RegisterMultiJoint(p, betweenChildJoint2);
                    //multiJointManager.RegisterMultiJoint(linkPart2, betweenChildJoint2);
                }


                if (!rootRb || p.rb == rootRb)
                {
                    continue;
                }

                if (multiJointManager.CheckMultiJointBetweenParts(p, v.rootPart) && multiJointManager.TrySetValidLinkedSet(p, v.rootPart))
                {
                    ConfigurableJoint toRootJoint;

                    toRootJoint = p.gameObject.AddComponent <ConfigurableJoint>();

                    toRootJoint.connectedBody = rootRb;
                    toRootJoint.anchor        = Vector3.zero;
                    toRootJoint.axis          = Vector3.right;
                    toRootJoint.secondaryAxis = Vector3.forward;
                    toRootJoint.breakForce    = KJRJointUtils.settings.decouplerAndClampJointStrength;
                    toRootJoint.breakTorque   = KJRJointUtils.settings.decouplerAndClampJointStrength;

                    toRootJoint.xMotion        = toRootJoint.yMotion = toRootJoint.zMotion = ConfigurableJointMotion.Locked;
                    toRootJoint.angularXMotion = toRootJoint.angularYMotion = toRootJoint.angularZMotion = ConfigurableJointMotion.Locked;

                    multiJointManager.RegisterMultiJointBetweenParts(p, v.rootPart, toRootJoint);
                    //multiJointManager.RegisterMultiJoint(p, toRootJoint);
                    //multiJointManager.RegisterMultiJoint(v.rootPart, toRootJoint);
                }
            }
        }