public OrbitalDetails getOrbitalDetails(GameObject baseObject) { CelestialBody centreMassBody = ((CelestialBody)baseObject.GetComponent(typeof(CelestialBody))); OrbitalDetails orbitalDetails = new OrbitalDetails(centreMassBody.radius, centreMassBody.mass, new List <OrbitalDetails>()); foreach (Transform transform in baseObject.transform) { OrbitingBody planetBody = ((OrbitingBody)transform.gameObject.GetComponent(typeof(OrbitingBody))); OrbitalDetails planetOrbitalDetails = new OrbitalDetails(planetBody.radius, planetBody.mass, planetBody.getSemiMinorAxis(), planetBody.getSemiMajorAxis(), planetBody.getEccentricity(), planetBody.getFoci1(), planetBody.getFoci2(), planetBody.getCentre(), planetBody.getLocalCentreVector(), planetBody.getCurrentTheta(), planetBody.getCosineEllipseRotation(), planetBody.getSineEllipseRotation(), planetBody.getDistanceFromFoci(), new List <OrbitalDetails>()); foreach (Transform subTransform in transform) { OrbitingBody moonBody = ((OrbitingBody)subTransform.gameObject.GetComponent(typeof(OrbitingBody))); OrbitalDetails moonOrbitalDetails = new OrbitalDetails(moonBody.radius, moonBody.mass, moonBody.getSemiMinorAxis(), moonBody.getSemiMajorAxis(), moonBody.getEccentricity(), moonBody.getFoci1(), moonBody.getFoci2(), moonBody.getCentre(), moonBody.getLocalCentreVector(), moonBody.getCurrentTheta(), moonBody.getCosineEllipseRotation(), moonBody.getSineEllipseRotation(), moonBody.getDistanceFromFoci(), new List <OrbitalDetails>()); planetOrbitalDetails.addOrbitingBody(moonOrbitalDetails); } orbitalDetails.addOrbitingBody(planetOrbitalDetails); } return(orbitalDetails); }
public GameObject generateStarSystem(GameObject baseObject) { GameObject centreMass = Instantiate(systemCentreMass, new Vector3(0, 0, 0), Quaternion.identity, baseObject != null ? baseObject.transform : gameObject.transform); centreMass.name = "CentreMass"; float currentMinBodySeparation = Random.Range(initialMinBodySeparation, initialMaxBodySeparation); int totalPlanets = (int)Random.Range(minPlanetGeneration, maxPlanetGeneration); for (int i = 0; i < totalPlanets; i++) { GameObject planet = Instantiate(planetPrefab, centreMass.transform); planet.name = "Planet-" + i; OrbitingBody planetBody = ((OrbitingBody)planet.GetComponent(typeof(OrbitingBody))); planetBody.minBodySeparation = currentMinBodySeparation; planetBody.setupOrbit(); currentMinBodySeparation = planetBody.getDistanceFromFoci() + minBodySeparation; //moon generation for current planet float currentMinMoonSeparation = Random.Range(initialMinMoonSeparation, initialMaxMoonSeparation); int totalMoons = (int)Random.Range(minMoonGeneration, maxMoonGeneration); for (int j = 0; j < totalMoons; j++) { GameObject moon = Instantiate(moonPrefab, planet.transform); moon.name = "Planet-" + i + "-Moon-" + j; OrbitingBody moonBody = ((OrbitingBody)moon.GetComponent(typeof(OrbitingBody))); moonBody.minBodySeparation = currentMinMoonSeparation; moonBody.setupOrbit(); currentMinMoonSeparation = moonBody.getDistanceFromFoci() + minMoonSeparation; } } return(centreMass); }