makeColor() public static method

public static makeColor ( string colorString ) : Color
colorString string
return Color
Exemplo n.º 1
0
        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
        }
Exemplo n.º 2
0
        public Track(string filename)
        {
            initDefaultValues();

            StreamReader reader = new StreamReader(filename);

            try
            {
                string line = reader.ReadLine(); //VERSION:X for new format, [HEADER] for legacy
                //check if we need the legacy parser
                if (!line.StartsWith("VERSION"))
                {
                    parseLegacyTrack(reader);
                    return;
                }

                //Debug.Log("parsing Track");

                int fileVersion = int.Parse(line.Split(':')[1]);

                Debug.Log("parsing Track Version = " + fileVersion);

                line = reader.ReadLine(); //[HEADER]

                //Debug.Log("Filename=" + filename);
                Char separator = '/';                                                //Path.DirectorySeparatorChar doesnt give the correct one here...?
                //Debug.Log("DirectorySeparator=" + separator + "last index in filename = " + filename.LastIndexOf(separator));
                TrackName = filename.Substring(filename.LastIndexOf(separator) + 1); //cut path
                //Debug.Log("cut-down filename = " + TrackName);
                TrackName = TrackName.Substring(0, TrackName.Length - 4);            //cut .trk
                //Debug.Log("final trackname = " + TrackName);

                Debug.Log(line);
                bool makeVisible = false;

                while (line != "[WAYPOINTS]" && !reader.EndOfStream)
                {
                    line = reader.ReadLine();
                    //Debug.Log("HeaderLine:" + line);
                    String[] lineSplit = line.Split(':');

                    if (lineSplit[0].Equals("VESSELNAME"))
                    {
                        VesselName = lineSplit[1];
                    }
                    else if (lineSplit[0].Equals("DESCRIPTION"))
                    {
                        Description = lineSplit[1];
                    }
                    else if (lineSplit[0].Equals("VISIBLE"))
                    {
                        makeVisible = lineSplit[1].Equals("1");
                    }
                    else if (lineSplit[0].Equals("MAINBODY"))
                    {
                        this.referenceBody = Utilities.CelestialBodyFromName(lineSplit[1]);
                    }
                    else if (lineSplit[0].Equals("SAMPLING"))
                    {
                        this.SamplingFactor = int.Parse(lineSplit[1]);
                    }
                    else if (lineSplit[0].Equals("LINECOLOR"))
                    {
                        LineColor = Utilities.makeColor(lineSplit[1]);
                    }
                    else if (lineSplit[0].Equals("LINEWIDTH"))
                    {
                        LineWidth = float.Parse(lineSplit[1]);
                    }
                    else if (lineSplit[0].Equals("CONERADIUSFACTOR"))
                    {
                        ConeRadiusToLineWidthFactor = float.Parse(lineSplit[1]);
                    }
                    else if (lineSplit[0].Equals("NUMDIRECTIONMARKERS"))
                    {
                        NumDirectionMarkers = int.Parse(lineSplit[1]);
                    }
                    else if (lineSplit[0].Equals("REPLAYCOLLIDERS"))
                    {
                        ReplayColliders = lineSplit[1].Equals("1");
                    }
                    else if (lineSplit[0].Equals("END"))
                    {
                        //Debug.Log("Parsing END-TAG="+lineSplit[1]);
                        EndAction = (EndActions)Enum.Parse(typeof(EndActions), lineSplit[1]);
                        //Debug.Log("EndAction = " + EndAction.ToString("F"));

                        if (EndAction == EndActions.LOOP)
                        {
                            //Debug.Log("LOOP endaction: Parsing string for looptime=" + lineSplit[2]);
                            LoopClosureTime = float.Parse(lineSplit[2]);
                        }
                    }
                } //End Header

                line = reader.ReadLine(); //first actual waypoint
                while (line != "[LOGENTRIES]" && !reader.EndOfStream)
                {
                    //Debug.Log("Waypointline = " + line);
                    string[] split = line.Split(';');
                    double   lat, lon, alt, time;
                    float    oriX, oriY, oriZ, oriW, vX, vY, vZ;
                    Double.TryParse(split[0], out time);
                    Double.TryParse(split[1], out lat);
                    Double.TryParse(split[2], out lon);
                    Double.TryParse(split[3], out alt);
                    float.TryParse(split[4], out oriX);
                    float.TryParse(split[5], out oriY);
                    float.TryParse(split[6], out oriZ);
                    float.TryParse(split[7], out oriW);
                    float.TryParse(split[8], out vX);
                    float.TryParse(split[9], out vY);
                    float.TryParse(split[10], out vZ);

                    waypoints.Add(new Waypoint(lat, lon, alt, new Quaternion(oriX, oriY, oriZ, oriW), new Vector3(vX, vY, vZ), time));
                    line = reader.ReadLine();
                }

                Debug.Log("reading 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, new Quaternion(), 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 = makeVisible; //set visible at end only
            }
            catch (Exception e) {
                Debug.Log(e.ToString());
            }
        }