コード例 #1
0
        //the part that is enabled and disabled
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            if (HighLogic.LoadedSceneIsEditor)
            {
                if (!editorChangeRegistered)
                {
                    GameEvents.onEditorShipModified.Add(shipModified);
                    editorChangeRegistered = false;
                }
                if (flightChangeRegistered)
                {
                    GameEvents.onVesselWasModified.Remove(vesselModified);
                    flightChangeRegistered = false;
                }
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (!flightChangeRegistered)
                {
                    GameEvents.onVesselWasModified.Add(vesselModified);
                    flightChangeRegistered = true;
                }
                if (flightChangeRegistered)
                {
                    GameEvents.onEditorShipModified.Remove(shipModified);
                    editorChangeRegistered = false;
                }
            }

            string[] nodenames           = nodeNames.Split(',');
            string[] transformGroupNames = transormNames.Split(',');

            List <string[]> transformnames = new List <string[]>();

            //when the lengths are not equal
            if (transformGroupNames.Length != nodenames.Length)
            {
                return;
            }

            //----------------------------------------------------------
            //create the list of transforms to be made visible on attach
            //----------------------------------------------------------

            //remove the whitespaces
            for (int i = 0; i < nodenames.Length; i++)
            {
                nodenames[i] = nodenames[i].Trim();

                //split up the names for the nodes
                string[] transformGroup = transformGroupNames[i].Split('|');

                for (int j = 0; j < transformGroup.Length; j++)
                {
                    transformGroup[j] = transformGroup[j].Trim();
                }
                transformnames.Add(transformGroup);
            }

            int num = 0;

            for (int i = 0; i < nodenames.Length; i++)
            {
                AttachNode       node       = part.FindAttachNode(nodenames[i]);
                List <Transform> transforms = new List <Transform>();
                for (int k = 0; k < transformnames[num].Length; k++)
                {
                    transforms.AddRange(part.FindModelTransforms(transformnames[num][k]));
                }

                //when nodes and transforms are valid and found
                if ((node != null) && (transforms.Count > 0))
                {
                    //create the new corridor data
                    CorridorPart corridor = new CorridorPart();
                    corridor.node       = node;
                    corridor.transforms = transforms;

                    if ((allowSurfaceAttach) && (surfaceAttachNode == nodenames[i]) && (part.srfAttachNode != null))
                    {
                        corridor.isSurfaceAttachPoint = true;
                    }
                    else
                    {
                        corridor.isSurfaceAttachPoint = false;
                    }

                    corridor.lastAttached = true;
                    corridors.Add(corridor);
                }
                num++;
            }

            //------------------------------------------------------------
            //create the list of transforms to be made invisible on attach
            //------------------------------------------------------------
            string[]        replaceTransformGroupNames = null;
            string[]        replaceNodeGroupNames      = null;
            List <string[]> replacetransformnames      = new List <string[]>();
            List <string[]> replacenodenames           = new List <string[]>();

            if ((replaceTransformNames != string.Empty) && (replaceNodeNames != string.Empty))
            {
                replaceTransformGroupNames = replaceTransformNames.Split(',');
                replaceNodeGroupNames      = replaceNodeNames.Split(',');

                if (replaceNodeGroupNames.Length == replaceTransformGroupNames.Length)
                {
                    //split up all the name for the groups
                    for (int i = 0; i < replaceNodeGroupNames.Length; i++)
                    {
                        //split up the names for the nodes
                        string[] transformGroup = replaceTransformGroupNames[i].Split('|');
                        for (int j = 0; j < transformGroup.Length; j++)
                        {
                            transformGroup[j] = transformGroup[j].Trim();
                        }
                        replacetransformnames.Add(transformGroup);

                        string[] nodeGroup = replaceNodeGroupNames[i].Split('|');
                        for (int j = 0; j < nodeGroup.Length; j++)
                        {
                            nodeGroup[j] = nodeGroup[j].Trim();
                        }
                        replacenodenames.Add(nodeGroup);
                    }


                    //for all transform groups
                    num = 0;
                    for (int i = 0; i < replacetransformnames.Count; i++)
                    {
                        List <Transform>  rTransforms  = new List <Transform>();
                        List <AttachNode> rAttachnodes = new List <AttachNode>();

                        for (int j = 0; j < replacetransformnames[i].Length; j++)
                        {
                            //Debug.Log("[KPBS] Replace Tranform Name: " + replacetransformnames[i][j]);
                            rTransforms.AddRange(part.FindModelTransforms(replacetransformnames[i][j]));
                        }

                        for (int j = 0; j < replacenodenames[num].Length; j++)
                        {
                            //Debug.Log("[KPBS] Replace Node Name: " + replacenodenames[num][j]);
                            rAttachnodes.Add(part.FindAttachNode(replacenodenames[num][j]));
                        }

                        if ((rTransforms.Count > 0) && (rAttachnodes.Count > 0))
                        {
                            ReplacedPart rp = new ReplacedPart();
                            rp.nodes      = rAttachnodes;
                            rp.transforms = rTransforms;
                            replaceParts.Add(rp);
                        }
                        num++;
                    }
                }
            }
            //check the visibility of all the parts
            updateAllCorridors();
        }
コード例 #2
0
        //the part that is enabled and disabled
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            if (HighLogic.LoadedSceneIsEditor)
            {
                if (!editorChangeRegistered)
                {
                    GameEvents.onEditorShipModified.Add(shipModified);
                    editorChangeRegistered = false;
                }
                if (flightChangeRegistered)
                {
                    GameEvents.onVesselWasModified.Remove(vesselModified);
                    flightChangeRegistered = false;
                }
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (!flightChangeRegistered)
                {
                    GameEvents.onVesselWasModified.Add(vesselModified);
                    flightChangeRegistered = true;
                }
                if (flightChangeRegistered)
                {
                    GameEvents.onEditorShipModified.Remove(shipModified);
                    editorChangeRegistered = false;
                }
            }

            string[] nodenames = nodeNames.Split(',');
            string[] transformGroupNames = transormNames.Split(',');

            List<string[]> transformnames = new List<string[]>();

            //when the lengths are not equal
            if (transformGroupNames.Length != nodenames.Length)
                return;

            //----------------------------------------------------------
            //create the list of transforms to be made visible on attach
            //----------------------------------------------------------

            //remove the whitespaces
            for (int i = 0; i < nodenames.Length; i++)
            {
                nodenames[i] = nodenames[i].Trim();

                //split up the names for the nodes
                string[] transformGroup = transformGroupNames[i].Split('|');

                for (int j = 0; j < transformGroup.Length; j++)
                {
                    transformGroup[j] = transformGroup[j].Trim();
                }
                transformnames.Add(transformGroup);
            }

            int num = 0;
            foreach (string nodeName in nodenames)
            {
                AttachNode node = part.findAttachNode(nodeName);

                List<Transform> transforms = new List<Transform>();
                for (int k = 0; k < transformnames[num].Length; k++) {
                    transforms.AddRange(part.FindModelTransforms(transformnames[num][k]));
                }

                //when nodes and transforms are valid and found
                if ((node != null) && (transforms.Count > 0))
                {
                    //create the new corridor data
                    CorridorPart corridor = new CorridorPart();
                    corridor.node = node;
                    corridor.transforms = transforms;

                    if ((allowSurfaceAttach) && (surfaceAttachNode == nodeName) && (part.srfAttachNode != null))
                    {
                        corridor.isSurfaceAttachPoint = true;
                    }
                    else
                    {
                        corridor.isSurfaceAttachPoint = false;
                    }

                    corridor.lastAttached = true;
                    corridors.Add(corridor);
                }
                num++;
            }

            //------------------------------------------------------------
            //create the list of transforms to be made invisible on attach
            //------------------------------------------------------------
            string[] replaceTransformGroupNames = null;
            string[] replaceNodeGroupNames = null;
            List<string[]> replacetransformnames = new List<string[]>();
            List<string[]> replacenodenames = new List<string[]>();

            if ((replaceTransformNames != string.Empty) && (replaceNodeNames != string.Empty))
            {
                replaceTransformGroupNames = replaceTransformNames.Split(',');
                replaceNodeGroupNames = replaceNodeNames.Split(',');

                if (replaceNodeGroupNames.Length == replaceTransformGroupNames.Length)
                {

                    //split up all the name for the groups
                    for (int i = 0; i < replaceNodeGroupNames.Length; i++)
                    {
                        //split up the names for the nodes
                        string[] transformGroup = replaceTransformGroupNames[i].Split('|');
                        for (int j = 0; j < transformGroup.Length; j++)
                        {
                            transformGroup[j] = transformGroup[j].Trim();
                        }
                        replacetransformnames.Add(transformGroup);

                        string[] nodeGroup = replaceNodeGroupNames[i].Split('|');
                        for (int j = 0; j < nodeGroup.Length; j++)
                        {
                            nodeGroup[j] = nodeGroup[j].Trim();
                        }
                        replacenodenames.Add(nodeGroup);
                    }

                    //for all transform groups
                    num = 0;
                    foreach (string[] tNames in replacetransformnames)
                    {

                        List<Transform> rTransforms = new List<Transform>();
                        List<AttachNode> rAttachnodes = new List<AttachNode>();

                        foreach (string tName in tNames)
                        {
                            Debug.Log("[KPBS] Replace Tranform Name: " + tName);
                            rTransforms.AddRange(part.FindModelTransforms(tName));
                        }
                        foreach (string nName in replacenodenames[num])
                        {
                            Debug.Log("[KPBS] Replace Node Name: " + nName);
                            rAttachnodes.Add(part.findAttachNode(nName));
                        }

                        if ((rTransforms.Count > 0) && (rAttachnodes.Count > 0))
                        {
                            ReplacedPart rp = new ReplacedPart();
                            rp.nodes = rAttachnodes;
                            rp.transforms = rTransforms;
                            replaceParts.Add(rp);
                        }
                        num++;
                    }
                }
            }
            //check the visibility of all the parts
            updateAllCorridors();
        }