Beispiel #1
0
        public static List <PartValue> loadCraftFromFile(string fileName)
        {
            List <PartValue> loadedList = new List <PartValue>();
            PartValue        newValue   = new PartValue();
            StreamReader     stream     = new StreamReader(fileName); // exceptions handled by assembleCraft
            string           newLine    = string.Empty;
            int craftFileFormat         = 0;

            int.TryParse(stream.ReadLine(), out craftFileFormat);
            Utilities.debug.debugMessage(String.Concat("Loading crf file, format ", craftFileFormat, ", ", fileName));
            try
            {
                while (!stream.EndOfStream && !(newLine == "[EOF]"))
                {
                    newLine           = stream.ReadLine();
                    newValue.partName = newLine;
                    newValue.position = Utilities.parseVector3(stream.ReadLine());
                    newValue.rotation = Utilities.parseQuaternion(stream.ReadLine());
                    float.TryParse(stream.ReadLine(), out newValue.scale);
                    //Debug.Log("finding model " + newValue.partName);
                    newValue.model = findPartModel(newValue.partName);
                    //Debug.Log("model null? " + (newValue.model == null));
                    loadedList.Add(newValue.clone());
                }
            }
            catch (Exception e)
            {
                //Utilities.debug.debugMessage("load craft file error: " + e.ToString());
                Utilities.debug.debugMessage("Got expected exception from streamreader, part list done");
            }
            return(loadedList);
        }
Beispiel #2
0
        public PartValue clone()
        {
            PartValue cloneValue = new PartValue();

            cloneValue.partName = partName;
            cloneValue.position = position;
            cloneValue.rotation = rotation;
            cloneValue.scale    = scale;
            cloneValue.model    = model;
            return(cloneValue);
        }
Beispiel #3
0
        public static List <PartValue> getParts(Vessel vessel, bool fetchModel)
        {
            List <PartValue> partList = new List <PartValue>();
            Vector3          rootPosition;
            Quaternion       rootRotation;
            Transform        referenceFrame = new GameObject().transform;
            Transform        localTransform = new GameObject().transform;

            localTransform.parent = referenceFrame;
            if (vessel != null)
            {
                if (vessel.parts.Count > 0)
                {
                    //Debug.Log("vessel parts: " + vessel.parts.Count);
                    rootPosition = vessel.parts[0].transform.position;
                    rootRotation = vessel.parts[0].transform.rotation;
                    Quaternion worldUp = Quaternion.Euler((vessel.GetComponent <Rigidbody>().position - vessel.mainBody.position).normalized);
                    referenceFrame.position = vessel.transform.position;
                    referenceFrame.rotation = vessel.transform.rotation;
                    foreach (Part part in vessel.parts)
                    {
                        if (part.name == "launchClamp1" || part.name == "strutConnector" || part.name == "fuelLine")
                        {
                            Utilities.debug.debugMessage("Excluding part from crf file: " + part.name);
                        }
                        else
                        {
                            PartValue newPartValue = new PartValue();
                            newPartValue.scale      = 1f / part.scaleFactor;
                            localTransform.rotation = part.transform.rotation;
                            localTransform.position = part.transform.position;
                            newPartValue.position   = localTransform.localPosition;
                            newPartValue.rotation   = localTransform.localRotation;
                            newPartValue.partName   = part.name.Split(' ')[0];
                            if (fetchModel)
                            {
                                newPartValue.model = findPartModel(newPartValue.partName);
                            }
                            partList.Add(newPartValue);
                        }
                    }
                }
            }
            return(partList);
        }
 public static List<PartValue> getParts(Vessel vessel, bool fetchModel)
 {
     List<PartValue> partList = new List<PartValue>();
     Vector3 rootPosition;
     Quaternion rootRotation;
     Transform referenceFrame = new GameObject().transform;
     Transform localTransform = new GameObject().transform;
     localTransform.parent = referenceFrame;
     if (vessel != null)
     {
         if (vessel.parts.Count > 0)
         {
             //Debug.Log("vessel parts: " + vessel.parts.Count);
             rootPosition = vessel.parts[0].transform.position;
             rootRotation = vessel.parts[0].transform.rotation;
             Quaternion worldUp = Quaternion.Euler((vessel.rigidbody.position - vessel.mainBody.position).normalized);
             referenceFrame.position = vessel.transform.position;
             referenceFrame.rotation = vessel.transform.rotation;
             foreach (Part part in vessel.parts)
             {
                 if (part.name == "launchClamp1" || part.partName == "StrutConnector" || part.partName == "FuelLine")
                 {
                     Utilities.debug.debugMessage("Excluding part from crf file: " + part.name);
                 }
                 else
                 {
                     PartValue newPartValue = new PartValue();
                     newPartValue.scale = 1f / part.scaleFactor;
                     localTransform.rotation = part.transform.rotation;
                     localTransform.position = part.transform.position;
                     newPartValue.position = localTransform.localPosition;
                     newPartValue.rotation = localTransform.localRotation;
                     newPartValue.partName = part.name.Split(' ')[0];
                     if (fetchModel) newPartValue.model = findPartModel(newPartValue.partName);
                     partList.Add(newPartValue);
                 }
             }
         }
     }
     return partList;
 }
 public PartValue clone()
 {
     PartValue cloneValue = new PartValue();
     cloneValue.partName = partName;
     cloneValue.position = position;
     cloneValue.rotation = rotation;
     cloneValue.scale = scale;
     cloneValue.model = model;
     return cloneValue;
 }
 public static List<PartValue> loadCraftFromFile(string fileName)
 {
     List<PartValue> loadedList = new List<PartValue>();
     PartValue newValue = new PartValue();
     StreamReader stream = new StreamReader(fileName); // exceptions handled by assembleCraft
     string newLine = string.Empty;
     int craftFileFormat = 0;
     int.TryParse(stream.ReadLine(), out craftFileFormat);
     Utilities.debug.debugMessage(String.Concat("Loading crf file, format ", craftFileFormat, ", ", fileName));
     try
     {
         while (!stream.EndOfStream && !(newLine == "[EOF]"))
         {
             newLine = stream.ReadLine();
             newValue.partName = newLine;
             newValue.position = Utilities.parseVector3(stream.ReadLine());
             newValue.rotation = Utilities.parseQuaternion(stream.ReadLine());
             float.TryParse(stream.ReadLine(), out newValue.scale);
             //Debug.Log("finding model " + newValue.partName);
             newValue.model = findPartModel(newValue.partName);
             //Debug.Log("model null? " + (newValue.model == null));
             loadedList.Add(newValue.clone());
         }
     }
     catch (Exception e)
     {
         //Utilities.debug.debugMessage("load craft file error: " + e.ToString());
         Utilities.debug.debugMessage("Got expected exception from streamreader, part list done");
     }
     return loadedList;
 }