public void CreatePlanets(System.Collections.Generic.List <Exoplanet> planets) { Universe universe = Object.FindObjectOfType(typeof(Universe)) as Universe; _PlanetOrbits = new GameObject[planets.Count]; _PlanetData = planets.ToArray(); _Planets = new Transform[planets.Count]; for (int i = 0; i < planets.Count; i++) { Exoplanet planet = planets[i]; GameObject planetParent = new GameObject("planetParent"); GameObject go = new GameObject("planet"); MeshFilter meshFilter = go.AddComponent <MeshFilter>(); MeshRenderer meshRenderer = go.AddComponent <MeshRenderer>(); Mesh mesh = GenerateMesh(Color.white); meshFilter.sharedMesh = mesh; meshRenderer.sharedMaterial = universe.PlanetMaterial; planetParent.transform.parent = transform; planetParent.transform.localPosition = Vector3.zero; go.transform.parent = planetParent.transform; float inclination = _PlanetData[i].Inclination; if (inclination == 0) { inclination = Random.Range(80, 100); } planetParent.transform.localRotation = Quaternion.Euler(0, inclination, 0); go.transform.localPosition = new Vector3(planet.SemiMajorAxis, 0, 0); if (planet.PlanetaryRadius == 0) { go.transform.localScale = Vector3.one * 0.1f; } else { go.transform.localScale = Vector3.one * 0.1f * planet.PlanetaryRadius; } _Planets[i] = go.transform; _PlanetOrbits[i] = Orbit.CreateOrbitObject(Vector3.zero, planet.SemiMajorAxis, planet.SemiMajorAxis, 0, inclination, planet.OrbitalEccentricity, universe.AsteroidMaterial); _PlanetOrbits[i].transform.parent = this.transform; } }
public static GameObject CreateRepresentation(Asteroid asteroid, Material mat) { GameObject go = Orbit.CreateOrbitObject(Vector3.zero, asteroid.AphelionDistance, asteroid.SemiMajorAxis, asteroid.ArgOfPerihelion, asteroid.AscNodeLongitude, asteroid.Eccentricity, mat); GameObject parentObj = new GameObject("asteroid " + asteroid.FullName); GameObject asteroidMesh = GameObject.CreatePrimitive(PrimitiveType.Sphere); asteroidMesh.transform.localScale = new Vector3(0.0001f, 0.0001f, 0.0001f) * asteroid.Diameter;; GameObject asteroidObject = new GameObject("Asteroid orbit"); asteroidMesh.transform.parent = asteroidObject.transform; AsteroidOrbit orbit = asteroidObject.AddComponent <AsteroidOrbit>(); orbit.AsteroidYo = asteroid; go.transform.parent = parentObj.transform; asteroidObject.transform.parent = parentObj.transform; return(parentObj); }