Exemple #1
0
    // GameObject[] _objects;
    void Start()
    {
        string[] lines = System.IO.File.ReadAllLines(@"planetsInfo.txt");

        celestialBodies = new List <CelestialBodies>();

        for (int i = 0; i < lines.Length; i++)
        {
            CelestialBodies c = GameObject.Find(lines[i]).GetComponent <CelestialBodies>(); //find all planet objects by their names

            PlanetInfo info = new PlanetInfo();
            c.setName(lines[i]);
            c.setType("Planet");

            i++;
            string[] words  = lines[i].Split(' ');
            float    volume = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat);
            info.setVolume(volume);
            //--------------------------------------------------------------
            i++;
            words = lines[i].Split(' ');
            float radius = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat);
            info.setRadius(radius);
            //----------------------------------------------------------------
            i++;
            words = lines[i].Split(' ');
            float circumference = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat);
            info.setCircumference(circumference);
            //-------------------------------------------------------------
            i++;
            words = lines[i].Split(' ');
            float mass = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat);
            info.setMass(mass);
            //----------------------------------------------------------------
            i++;
            words = lines[i].Split('*');
            info.setSurface(words[1]);
            //---------------------------------------------------------------------
            i++;
            words = lines[i].Split(' ');
            float avergTemperature = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat);
            info.setAverageTemperature(avergTemperature);
            //--------------------------------------------------------------------
            i++;
            words = lines[i].Split('*');
            info.setPositionFromSun(words[1]);
            //--------------------------------------------------------------------------
            i++;
            words = lines[i].Split(' ');
            int orbitalPeriod = Convert.ToInt32(words[1]);
            info.setOrbitalPeriod(orbitalPeriod);
            //  print(words[1]);
            //------------------------------------------------------------------------------
            i++;
            words = lines[i].Split('*');
            info.setDayHours(words[1]);
            //---------------------------------------------------------------------------
            i++;
            words = lines[i].Split(' ');
            int numberOfMoons = Convert.ToInt32(words[1]);
            info.setNumberOfMoons(numberOfMoons);
            //print(words[1]);
            //--------------------------------------------------------------------------
            i++;
            //lightspeed
            //---------------------------------------------------------------------------
            i++;
            words = lines[i].Split(' ');
            float gravity = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat);
            c.setGravity(gravity);
            //------------------------------------------------------------------------------
            i++;
            words = lines[i].Split(' ');
            float distanceFromSun = float.Parse(words[1], CultureInfo.InvariantCulture.NumberFormat);
            info.setDistanceFromSun(distanceFromSun);
            //---------------------------------------------------------------------
            i++;
            c.setInfo(info);
            celestialBodies.Add(c);
        }
        // foreach (CelestialBodies c in celestialBodies) print(c.ToString());
    }