GetBaseConfigNode() public static method

public static GetBaseConfigNode ( PartModule partModule ) : ConfigNode
partModule PartModule
return System.ConfigNode
Esempio n. 1
0
        private void LoadBays()
        {
            bays.Clear();
            ConfigNode node = KAS_Shared.GetBaseConfigNode(this);

            foreach (ConfigNode bayNode in node.GetNodes("BAY"))
            {
                if (bayNode.HasValue("attachNode") && bayNode.HasValue("type"))
                {
                    string     attachNodeName = bayNode.GetValue("attachNode");
                    AttachNode an             = this.part.findAttachNode(attachNodeName);
                    if (an == null)
                    {
                        KAS_Shared.DebugError("LoadBays(PartBay) - Node : " + attachNodeName + " not found !");
                        continue;
                    }
                    List <string> allTypes = new List <string>(bayNode.GetValues("type"));
                    KAS_Shared.AddNodeTransform(this.part, an);
                    bays.Add(an, allTypes);
                }
            }
        }
        private void LoadSections()
        {
            sections.Clear();
            sectionTotalLenght = 0;
            ConfigNode node = KAS_Shared.GetBaseConfigNode(this);
            int        i    = 0;

            foreach (ConfigNode sectionNode in node.GetNodes("SECTION"))
            {
                if (sectionNode.HasValue("transformName") && sectionNode.HasValue("lenght"))
                {
                    SectionInfo section = new SectionInfo();
                    string      sectionTransformName = sectionNode.GetValue("transformName");
                    section.transform = this.part.FindModelTransform(sectionTransformName);
                    if (!section.transform)
                    {
                        KAS_Shared.DebugError("LoadSections(TelescopicArm) Section transform "
                                              + sectionTransformName + " not found in the model !");
                        continue;
                    }
                    if (!float.TryParse(sectionNode.GetValue("lenght"), out section.lenght))
                    {
                        KAS_Shared.DebugError(
                            "LoadSections(TelescopicArm) Unable to parse lenght of the Section : "
                            + sectionTransformName);
                        continue;
                    }
                    section.orgLocalPos = KAS_Shared.GetLocalPosFrom(section.transform, this.part.transform);
                    section.orgLocalRot = KAS_Shared.GetLocalRotFrom(section.transform, this.part.transform);
                    if (savedSectionsLocalPos.Count > 0)
                    {
                        section.savedLocalPos = savedSectionsLocalPos[i];
                    }
                    sections.Add(i, section);
                    sectionTotalLenght += section.lenght;
                    i++;
                }
            }
        }
Esempio n. 3
0
        public void LoadBoomHead()
        {
            if (savedSectionsLocalPos.Count > 0)
            {
                //Reset section(s) to org pos
                foreach (KeyValuePair <int, SectionInfo> section in sections)
                {
                    section.Value.transform.position = this.part.transform.TransformPoint(section.Value.orgLocalPos);
                }
            }

            KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) Create physical object...");
            boomHeadPhysicModule = this.part.gameObject.GetComponent <KASModulePhysicChild>();
            if (!boomHeadPhysicModule)
            {
                KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - KASModulePhysicChild do not exist, adding it...");
                boomHeadPhysicModule = this.part.gameObject.AddComponent <KASModulePhysicChild>();
            }
            boomHeadPhysicModule.mass      = boomHeadMass;
            boomHeadPhysicModule.physicObj = sections[0].transform.gameObject;
            boomHeadPhysicModule.Start();

            orgBoomHeadMass = this.part.mass;
            float newMass = this.part.mass - boomHeadMass;

            if (newMass > 0)
            {
                this.part.mass = newMass;
            }
            else
            {
                KAS_Shared.DebugWarning("LoadBoomHead(TelescopicArm) - Mass of the boom head is greater than the part !");
            }

            KAS_Shared.DebugLog("LoadRotor - Disable collision...");
            disableSectionCollision();

            KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Create configurable joint...");
            slideJoint = this.part.gameObject.AddComponent <ConfigurableJoint>();
            slideJoint.connectedBody  = sections[0].transform.rigidbody;
            slideJoint.axis           = Vector3.zero;
            slideJoint.secondaryAxis  = Vector3.zero;
            slideJoint.breakForce     = breakForce;
            slideJoint.breakTorque    = breakForce;
            slideJoint.angularXMotion = ConfigurableJointMotion.Locked;
            slideJoint.angularYMotion = ConfigurableJointMotion.Locked;
            slideJoint.angularZMotion = ConfigurableJointMotion.Locked;
            slideJoint.xMotion        = ConfigurableJointMotion.Locked;
            slideJoint.yMotion        = ConfigurableJointMotion.Locked;
            slideJoint.zMotion        = ConfigurableJointMotion.Locked;

            if (direction.x != 0)
            {
                slideJoint.xMotion = ConfigurableJointMotion.Limited;
                driveWay           = direction.x;
                KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Direction set to x axis with driveWay set to : " + driveWay);
            }
            else if (direction.y != 0)
            {
                slideJoint.yMotion = ConfigurableJointMotion.Limited;
                driveWay           = direction.y;
                KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Direction set to y axis with driveWay set to : " + driveWay);
            }
            else if (direction.z != 0)
            {
                slideJoint.zMotion = ConfigurableJointMotion.Limited;
                driveWay           = direction.z;
                KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Direction set to z axis with driveWay set to : " + driveWay);
            }

            JointDrive drv = new JointDrive();

            drv.mode           = JointDriveMode.PositionAndVelocity;
            drv.positionSpring = driveSpring;
            drv.positionDamper = driveDamper;
            drv.maximumForce   = driveForce;
            slideJoint.xDrive  = slideJoint.yDrive = slideJoint.zDrive = drv;

            SoftJointLimit jointLimit = new SoftJointLimit();

            jointLimit.limit       = sectionTotalLenght;
            jointLimit.damper      = 200;
            jointLimit.spring      = 1000;
            jointLimit.bounciness  = 1;
            slideJoint.linearLimit = jointLimit;

            if (savedSectionsLocalPos.Count > 0)
            {
                KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Re-set section position from save");
                float sumLenght = 0;
                foreach (KeyValuePair <int, SectionInfo> section in sections)
                {
                    KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Move section " + section.Key + " to local position : " + section.Value.savedLocalPos);
                    section.Value.transform.position = this.part.transform.TransformPoint(section.Value.savedLocalPos);
                    sumLenght += section.Value.lenght;
                    if (headPos > sumLenght)
                    {
                        KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Parent section " + sections[section.Key + 1].transform.name + " to : " + section.Value.transform.name);
                        sections[section.Key + 1].transform.parent = section.Value.transform;
                    }
                }
            }

            // Get boom head attach nodes
            attachNodes.Clear();
            ConfigNode    node          = KAS_Shared.GetBaseConfigNode(this);
            List <string> attachNodesSt = new List <string>(node.GetValues("attachNode"));

            foreach (String anString in attachNodesSt)
            {
                AttachNode an = this.part.findAttachNode(anString);
                if (an != null)
                {
                    KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Boom head attach node added : " + an.id);
                    attachNodes.Add(an);
                    if (an.attachedPart)
                    {
                        KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Setting boom head joint on : " + an.attachedPart.partInfo.title);
                        KAS_Shared.RemoveFixedJointBetween(this.part, an.attachedPart);
                        KAS_Shared.RemoveHingeJointBetween(this.part, an.attachedPart);
                        FixedJoint fjnt = an.attachedPart.gameObject.AddComponent <FixedJoint>();
                        fjnt.connectedBody = sections[0].transform.rigidbody;
                        fixedJnts.Add(fjnt);
                    }
                }
            }
            SetTargetPos(targetPos);
            boomHeadLoaded = true;
        }
Esempio n. 4
0
        public void LoadRotor()
        {
            KAS_Shared.DebugLog("LoadRotor(Rotor) - Find rotor transform...");
            rotorTransform = this.part.FindModelTransform(rotorTransformName);

            KAS_Shared.DebugLog("LoadRotor(Rotor) - Create physical object...");
            rotorPhysicModule = this.part.gameObject.GetComponent <KASModulePhysicChild>();
            if (!rotorPhysicModule)
            {
                KAS_Shared.DebugLog("LoadRotor(Rotor) - KASModulePhysicChild do not exist, adding it...");
                rotorPhysicModule = this.part.gameObject.AddComponent <KASModulePhysicChild>();
            }
            rotorPhysicModule.mass      = rotorMass;
            rotorPhysicModule.physicObj = rotorTransform.gameObject;
            rotorPhysicModule.Start();

            orgRotorMass = this.part.mass;
            float newMass = this.part.mass - rotorMass;

            if (newMass > 0)
            {
                this.part.mass = newMass;
            }
            else
            {
                KAS_Shared.DebugWarning("LoadRotor(Rotor) - Mass of the rotor is greater than the part !");
            }

            KAS_Shared.DebugLog("LoadRotor - Save original rotor position...");
            rotorOrgLocalPos = KAS_Shared.GetLocalPosFrom(rotorTransform, this.part.transform);
            rotorOrgLocalRot = KAS_Shared.GetLocalRotFrom(rotorTransform, this.part.transform);

            KAS_Shared.DebugLog("LoadRotor - Disable collision...");
            if (rotorTransform.collider)
            {
                KAS_Shared.DisableVesselCollision(this.part.vessel, rotorTransform.collider);
            }
            else
            {
                KAS_Shared.DebugError("LoadRotor - Rotor transform do not have any collider !");
            }

            KAS_Shared.DebugLog("LoadRotor - Create hinge joint...");
            hingeJnt = this.part.gameObject.AddComponent <HingeJoint>();
            hingeJnt.connectedBody = rotorTransform.rigidbody;
            ResetLimitsConfig();
            ResetMotorConfig();
            ResetSpringConfig();
            ResetJointConfig();

            if (firstLoad)
            {
                firstLoad = false;
            }
            else
            {
                KAS_Shared.DebugLog("LoadRotor - Return rotor to the current position and rotation : " + rotorLocalPos + " | " + rotorLocalRot);
                KAS_Shared.SetPartLocalPosRotFrom(rotorTransform.transform, this.part.transform, rotorLocalPos, rotorLocalRot);
            }

            // Get rotor attach nodes
            attachNodes.Clear();
            ConfigNode    node          = KAS_Shared.GetBaseConfigNode(this);
            List <string> attachNodesSt = new List <string>(node.GetValues("attachNode"));

            foreach (String anString in attachNodesSt)
            {
                AttachNode an = this.part.findAttachNode(anString);
                if (an != null)
                {
                    KAS_Shared.DebugLog("LoadRotor - Rotor attach node added : " + an.id);
                    attachNodes.Add(an);
                    if (an.attachedPart)
                    {
                        KAS_Shared.DebugLog("LoadRotor - Setting rotor joint on : " + an.attachedPart.partInfo.title);
                        KAS_Shared.RemoveFixedJointBetween(this.part, an.attachedPart);
                        KAS_Shared.RemoveHingeJointBetween(this.part, an.attachedPart);
                        FixedJoint fjnt = an.attachedPart.gameObject.AddComponent <FixedJoint>();
                        fjnt.connectedBody = rotorTransform.rigidbody;
                        fixedJnts.Add(fjnt);
                    }
                }
            }
            MotorStop();
            rotorLoaded = true;
        }