PersistentTrails.Utilities.CelestialBodyFromName C# (CSharp) Method

CelestialBodyFromName() public static method

public static CelestialBodyFromName ( string searchName ) : CelestialBody
searchName string
return CelestialBody
        public static CelestialBody CelestialBodyFromName(string searchName)
        {
            foreach (CelestialBody body in FlightGlobals.Bodies) {
                if (body.name == searchName)
                    return body;
            }
            Debug.Log("Invalid CelestialBodyName " + searchName + ", defaulting to Kerbin");
            return FlightGlobals.Bodies[0];
            //return FlightGlobals.Bodies.FirstOrDefault(a => a.bodyName == BodyName);
        }

Usage Example

        private void parseLegacyTrack(StreamReader reader)
        {
            Debug.Log("parsing legacy track");

            this.TrackName   = reader.ReadLine();
            this.Description = reader.ReadLine();
            string visString = reader.ReadLine();

            string refBodyName = reader.ReadLine();

            //Debug.Log("reading celestialbody = " + refBodyName);
            this.referenceBody = Utilities.CelestialBodyFromName(refBodyName);
            //Debug.Log("reading + parsing samplingFactor");
            this.SamplingFactor = int.Parse(reader.ReadLine());
            //Debug.Log("samplingString = " + samplingString + ", parsed to samplingFactor = " + samplingFactor);

            string colorString = reader.ReadLine();

            this.LineColor = Utilities.makeColor(colorString);
            LineWidth      = float.Parse(reader.ReadLine());

            string numString = reader.ReadLine();

            this.ConeRadiusToLineWidthFactor = float.Parse(numString);
            numString = reader.ReadLine();
            this.NumDirectionMarkers = int.Parse(numString);

            //Debug.Log("Header reading complete");



            //Debug.Log("read waypoints");
            reader.ReadLine();               //WAYPOINTS
            string line = reader.ReadLine(); //first waypoint

            while (line != "[LOGENTRIES]" && !reader.EndOfStream)
            {
                //Debug.Log("reading waypointline = " + line);
                string[] split = line.Split(';');
                double   lat, lon, alt, time;
                Double.TryParse(split[0], out lat);
                Double.TryParse(split[1], out lon);
                Double.TryParse(split[2], out alt);
                Double.TryParse(split[3], out time);
                waypoints.Add(new Waypoint(lat, lon, alt, Quaternion.identity, new Vector3(), time));
                line = reader.ReadLine();
            }


            //Debug.Log("read logentries");
            line = reader.ReadLine();//first entry
            while (!reader.EndOfStream)
            {
                string trimmed = line;
                trimmed = trimmed.Trim();
                if (!string.IsNullOrEmpty(trimmed))
                {
                    //Debug.Log("reading logentryline = " + line);
                    string[] split = line.Split(';');
                    double   lat, lon, alt, time;
                    Double.TryParse(split[0], out lat);
                    Double.TryParse(split[1], out lon);
                    Double.TryParse(split[2], out alt);
                    Double.TryParse(split[3], out time);
                    logEntries.Add(new LogEntry(lat, lon, alt, Quaternion.identity, new Vector3(), time, split[4], split[5]));
                }
                line = reader.ReadLine();
            }



            Debug.Log("Created track from file containing " + waypoints.Count + "waypoints and " + logEntries.Count + " log entries");
            Visible  = (visString == "1");
            Modified = true; //legacy tracks are marked as modified for conversion
        }
All Usage Examples Of PersistentTrails.Utilities::CelestialBodyFromName