Example #1
0
        /// <summary>
        /// Creates a new Body from a spawned CelestialBody.
        /// </summary>
        public Body(CelestialBody celestialBody)
        {
            CelestialBody = celestialBody;
            Name          = celestialBody.transform.name;

            // Create the accessors
            Properties = new PropertiesLoader(celestialBody);
            if (celestialBody.orbitDriver != null)
            {
                Orbit = new OrbitLoader(celestialBody);
            }

            ScaledVersion = new ScaledVersionLoader(celestialBody);
            if (celestialBody.atmosphere)
            {
                Atmosphere = new AtmosphereLoader(celestialBody);
            }

            if (celestialBody.pqsController != null)
            {
                Pqs = new PQSLoader(celestialBody);
                if (celestialBody.pqsController.GetComponentsInChildren <PQS>(true)
                    .Any(p => p.name.EndsWith("Ocean")))
                {
                    Ocean = new OceanLoader(celestialBody);
                }
            }

            Rings = new List <RingLoader>();
            foreach (Ring ring in celestialBody.scaledBody.GetComponentsInChildren <Ring>(true))
            {
                Rings.Add(new RingLoader(ring));
            }

            Particles = new List <ParticleLoader>();
            foreach (PlanetParticleEmitter particle in celestialBody.scaledBody
                     .GetComponentsInChildren <PlanetParticleEmitter>(true))
            {
                Particles.Add(new ParticleLoader(particle));
            }

            HazardousBody = new List <HazardousBodyLoader>();
            foreach (HazardousBody body in celestialBody.GetComponents <HazardousBody>())
            {
                HazardousBody.Add(new HazardousBodyLoader(body));
            }

            if (celestialBody.isHomeWorld)
            {
                SpaceCenter = new SpaceCenterLoader(celestialBody);
            }

            Debug = new DebugLoader(celestialBody);
        }