Ejemplo n.º 1
0
    public GameObject loadStarSystem(OrbitalDetails orbitalDetails)
    {
        GameObject centreMass = Instantiate(systemCentreMass, new Vector3(0, 0, 0), Quaternion.identity);

        centreMass.name = "CentreMass";
        CelestialBody centreMassBody = ((CelestialBody)centreMass.GetComponent(typeof(CelestialBody)));

        centreMassBody.loadDetails(orbitalDetails.getRadius(), orbitalDetails.getMass());

        for (int i = 0; i < orbitalDetails.getOrbitingBodies().Count; i++)
        {
            GameObject planet = Instantiate(planetPrefab, centreMass.transform);
            planet.name = "Planet-" + i;
            OrbitingBody planetBody = ((OrbitingBody)planet.GetComponent(typeof(OrbitingBody)));
            planetBody.loadDetails(orbitalDetails.getOrbitingBodies()[i]);

            //moon generation for current planet
            for (int j = 0; j < orbitalDetails.getOrbitingBodies()[i].getOrbitingBodies().Count; j++)
            {
                GameObject moon = Instantiate(moonPrefab, planet.transform);
                moon.name = "Planet-" + i + "-Moon-" + j;
                OrbitingBody moonBody = ((OrbitingBody)moon.GetComponent(typeof(OrbitingBody)));
                moonBody.loadDetails(orbitalDetails.getOrbitingBodies()[i].getOrbitingBodies()[j]);
            }
        }

        return(centreMass);
    }