Ejemplo n.º 1
0
            /// <summary>
            /// Creates a new Body from a spawned CelestialBody.
            /// </summary>
            public Body(CelestialBody celestialBody)
            {
                this.celestialBody = celestialBody;

                // 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);
                }
                pqs   = new PQSLoader(celestialBody);
                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));
                }
                if (celestialBody.isHomeWorld)
                {
                    spaceCenter = new SpaceCenterLoader(celestialBody);
                }
                debug = new DebugLoader(celestialBody);
            }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
            // Parser Apply Event
            void IParserEventSubscriber.Apply(ConfigNode node)
            {
                // If we have a template, generatedBody *is* the template body
                if (template != null && template.body)
                {
                    generatedBody = template.body;

                    // Patch the game object names in the template
                    generatedBody.name = name;
                    generatedBody.celestialBody.bodyName           = name;
                    generatedBody.celestialBody.transform.name     = name;
                    generatedBody.celestialBody.bodyTransform.name = name;
                    generatedBody.scaledVersion.name = name;
                    if (generatedBody.pqsVersion != null)
                    {
                        generatedBody.pqsVersion.name            = name;
                        generatedBody.pqsVersion.gameObject.name = name;
                        generatedBody.pqsVersion.transform.name  = name;
                        foreach (PQS p in generatedBody.pqsVersion.GetComponentsInChildren <PQS>(true))
                        {
                            p.name = p.name.Replace(template.body.celestialBody.bodyName, name);
                        }
                        generatedBody.celestialBody.pqsController = generatedBody.pqsVersion;
                    }

                    // If we've changed the name, reset use_The_InName
                    if (generatedBody.name != template.originalBody.celestialBody.bodyName)
                    {
                        generatedBody.celestialBody.bodyDisplayName = generatedBody.celestialBody.bodyName;
                    }
                }

                // Otherwise we have to generate all the things for this body
                else
                {
                    // Create the PSystemBody object
                    GameObject generatedBodyGameObject = new GameObject(name);
                    generatedBodyGameObject.transform.parent = Utility.Deactivator;
                    generatedBody = generatedBodyGameObject.AddComponent <PSystemBody>();
                    generatedBody.flightGlobalsIndex = 0;

                    // Create the celestial body
                    GameObject generatedBodyProperties = new GameObject(name);
                    generatedBodyProperties.transform.parent = generatedBodyGameObject.transform;
                    generatedBody.celestialBody = generatedBodyProperties.AddComponent <CelestialBody>();
                    generatedBody.celestialBody.progressTree = null;

                    // Sensible defaults
                    generatedBody.celestialBody.bodyName        = name;
                    generatedBody.celestialBody.bodyDisplayName = name;
                    generatedBody.celestialBody.atmosphere      = false;
                    generatedBody.celestialBody.ocean           = false;

                    // Create the scaled version
                    generatedBody.scaledVersion                  = new GameObject(name);
                    generatedBody.scaledVersion.layer            = Constants.GameLayers.ScaledSpace;
                    generatedBody.scaledVersion.transform.parent = Utility.Deactivator;
                }

                // Create accessors
                debug         = new DebugLoader();
                scaledVersion = new ScaledVersionLoader();

                // Event
                Events.OnBodyApply.Fire(this, node);
            }
Ejemplo n.º 4
0
        // Parser Apply Event
        void IParserEventSubscriber.Apply(ConfigNode node)
        {
            if (Template != null && Template.Body)
            {
                // If we have a template, generatedBody *is* the template body
                GeneratedBody = Template.Body;
                // Patch the game object names in the template
                GeneratedBody.name = Name;
                GeneratedBody.celestialBody.bodyName       = Name;
                GeneratedBody.celestialBody.transform.name = Name;
                GeneratedBody.scaledVersion.name           = Name;
                if (GeneratedBody.pqsVersion != null)
                {
                    GeneratedBody.pqsVersion.name            = Name;
                    GeneratedBody.pqsVersion.gameObject.name = Name;
                    GeneratedBody.pqsVersion.transform.name  = Name;
                    foreach (PQS p in GeneratedBody.pqsVersion.GetComponentsInChildren <PQS>(true))
                    {
                        p.name = p.name.Replace(Template.Body.celestialBody.bodyName, Name);
                    }
                    GeneratedBody.celestialBody.pqsController = GeneratedBody.pqsVersion;
                }
                // If we've changed the name, reset use_The_InName
                if (GeneratedBody.name != Template.OriginalBody.celestialBody.bodyName)
                {
                    GeneratedBody.celestialBody.bodyDisplayName = GeneratedBody.celestialBody.bodyAdjectiveDisplayName = GeneratedBody.celestialBody.bodyName;
                }
                // Create accessors
                Debug         = new DebugLoader();
                ScaledVersion = new ScaledVersionLoader();
                if (Template.OriginalBody.scaledVersion.name.Equals("Jool"))
                {
#if (KSP_VERSION_1_10_1 || KSP_VERSION_1_11_1)
                    if ((!Name.Equals("Jool")) || (Name.Equals("Jool") && (Template.Body.celestialBody.Radius > 6000000))) // This is a Jool-clone, or resized Jool.  We have to handle it special.
                    {
                        //Remove Gas Giant shaders for compatability
                        GasGiantMaterialControls       GGMC  = GeneratedBody.scaledVersion.GetComponent <GasGiantMaterialControls>();
                        MaterialBasedOnGraphicsSetting MBOGS = GeneratedBody.scaledVersion.GetComponent <MaterialBasedOnGraphicsSetting>();
                        GameObject.DestroyImmediate(GGMC);
                        GameObject.DestroyImmediate(MBOGS);
                    }
#endif
                    //We need to destroy the stock GG MSD, it is bugged for our needs.
                    MaterialSetDirection MSD = GeneratedBody.celestialBody.scaledBody.GetComponent <MaterialSetDirection>();
                    GameObject.DestroyImmediate(MSD);
                }
            }
            // Otherwise we have to generate all the things for this body
            else
            {
                // Create the PSystemBody object
                GameObject generatedBodyGameObject = new GameObject(Name);
                generatedBodyGameObject.transform.parent = Utility.Deactivator;
                GeneratedBody = generatedBodyGameObject.AddComponent <PSystemBody>();
                GeneratedBody.flightGlobalsIndex = 0;

                // Create the celestial body
                GameObject generatedBodyProperties = new GameObject(Name);
                generatedBodyProperties.transform.parent = generatedBodyGameObject.transform;
                GeneratedBody.celestialBody = generatedBodyProperties.AddComponent <CelestialBody>();
                GeneratedBody.celestialBody.progressTree = null;

                // Sensible defaults
                GeneratedBody.celestialBody.bodyName        = Name;
                GeneratedBody.celestialBody.bodyDisplayName = GeneratedBody.celestialBody.bodyAdjectiveDisplayName = Name;
                GeneratedBody.celestialBody.atmosphere      = false;
                GeneratedBody.celestialBody.ocean           = false;

                // Create the scaled version
                GeneratedBody.scaledVersion = new GameObject(Name)
                {
                    layer = GameLayers.SCALED_SPACE
                };
                GeneratedBody.scaledVersion.transform.parent = Utility.Deactivator;
                // Create accessors
                Debug         = new DebugLoader();
                ScaledVersion = new ScaledVersionLoader();
            }
            // Event
            Events.OnBodyApply.Fire(this, node);
        }
Ejemplo n.º 5
0
        // Parser Apply Event
        void IParserEventSubscriber.Apply(ConfigNode node)
        {
            if (Template != null && Template.Body)
            {
                // If we have a template, generatedBody *is* the template body
                GeneratedBody = Template.Body;
                // Patch the game object names in the template
                GeneratedBody.name = Name;
                GeneratedBody.celestialBody.bodyName       = Name;
                GeneratedBody.celestialBody.transform.name = Name;
                GeneratedBody.scaledVersion.name           = Name;
                if (GeneratedBody.pqsVersion != null)
                {
                    GeneratedBody.pqsVersion.name            = Name;
                    GeneratedBody.pqsVersion.gameObject.name = Name;
                    GeneratedBody.pqsVersion.transform.name  = Name;
                    foreach (PQS p in GeneratedBody.pqsVersion.GetComponentsInChildren <PQS>(true))
                    {
                        p.name = p.name.Replace(Template.Body.celestialBody.bodyName, Name);
                    }
                    GeneratedBody.celestialBody.pqsController = GeneratedBody.pqsVersion;
                }
                // If we've changed the name, reset use_The_InName
                if (GeneratedBody.name != Template.OriginalBody.celestialBody.bodyName)
                {
                    GeneratedBody.celestialBody.bodyDisplayName = GeneratedBody.celestialBody.bodyAdjectiveDisplayName = GeneratedBody.celestialBody.bodyName;
                }
                if (Template.OriginalBody.scaledVersion.name.Equals("Jool"))
                {
                    if (Versioning.version_minor > 9)
                    {
                        if ((!Name.Equals("Jool")) || (Name.Equals("Jool") && (Template.Body.celestialBody.Radius > 6000000))) // This is a Jool-clone, or resized Jool.  We have to handle it special.
                        {
                            try
                            {
                                //Remove Gas Giant shaders for compatability
                                MonoBehaviour GGMC  = GasGiantMaterialControls(GeneratedBody);
                                MonoBehaviour MBOGS = MaterialBasedOnGraphicsSetting(GeneratedBody);
                                GameObject.DestroyImmediate(GGMC);
                                GameObject.DestroyImmediate(MBOGS);
                                UnityEngine.Debug.Log("[Kopernicus] New Jool detected, shaders stripped!");
                            }
                            catch
                            {
                                UnityEngine.Debug.Log("[Kopernicus] Old Jool detected, leaving shaders alone!");
                            }
                        }
                    }
                }
                // Create accessors
                Debug         = new DebugLoader();
                ScaledVersion = new ScaledVersionLoader();
            }
            // Otherwise we have to generate all the things for this body
            else
            {
                // Create the PSystemBody object
                GameObject generatedBodyGameObject = new GameObject(Name);
                generatedBodyGameObject.transform.parent = Utility.Deactivator;
                GeneratedBody = generatedBodyGameObject.AddComponent <PSystemBody>();
                GeneratedBody.flightGlobalsIndex = 0;

                // Create the celestial body
                GameObject generatedBodyProperties = new GameObject(Name);
                generatedBodyProperties.transform.parent = generatedBodyGameObject.transform;
                GeneratedBody.celestialBody = generatedBodyProperties.AddComponent <CelestialBody>();
                GeneratedBody.celestialBody.progressTree = null;

                // Sensible defaults
                GeneratedBody.celestialBody.bodyName        = Name;
                GeneratedBody.celestialBody.bodyDisplayName = GeneratedBody.celestialBody.bodyAdjectiveDisplayName = Name;
                GeneratedBody.celestialBody.atmosphere      = false;
                GeneratedBody.celestialBody.ocean           = false;

                // Create the scaled version
                GeneratedBody.scaledVersion = new GameObject(Name)
                {
                    layer = GameLayers.SCALED_SPACE
                };
                GeneratedBody.scaledVersion.transform.parent = Utility.Deactivator;
                // Create accessors
                Debug         = new DebugLoader();
                ScaledVersion = new ScaledVersionLoader();
            }
            // Event
            Events.OnBodyApply.Fire(this, node);
        }
Ejemplo n.º 6
0
            // Parser Post Apply Event
            void IParserEventSubscriber.PostApply(ConfigNode node)
            {
                // If Debug Mode is null, create default values
                if (debug == null)
                {
                    debug = new DebugLoader();
                }
                if (scaledVersion == null)
                {
                    scaledVersion = new ScaledVersionLoader();
                }

                // PQS
                if (generatedBody.pqsVersion)
                {
                    // Adjust the radius of the PQSs appropriately
                    foreach (PQS p in generatedBody.pqsVersion.GetComponentsInChildren <PQS>(true))
                    {
                        p.radius = generatedBody.celestialBody.Radius;
                    }
                }

                // Create a barycenter
                if (barycenter.value)
                {
                    // Register the body for post-spawn patching
                    generatedBody.Set("barycenter", true);

                    // Nuke the PQS
                    if (generatedBody.pqsVersion != null)
                    {
                        generatedBody.pqsVersion.transform.parent = null;
                        UnityEngine.Object.Destroy(generatedBody.pqsVersion);
                        generatedBody.pqsVersion = null;
                    }

                    // Stop ScaledSpace Cache
                    scaledVersion.deferMesh = true;
                }

                // We need to generate new scaled space meshes if
                //   a) we are using a template and we've change either the radius or type of body
                //   b) we aren't using a template
                //   c) debug mode is active
                if (!scaledVersion.deferMesh &&
                    (((template != null) && (Math.Abs(template.radius - generatedBody.celestialBody.Radius) > 1.0 || template.type != scaledVersion.type.value)) ||
                     template == null || debug.update))
                {
                    Utility.UpdateScaledMesh(generatedBody.scaledVersion,
                                             generatedBody.pqsVersion,
                                             generatedBody.celestialBody,
                                             ScaledSpaceCacheDirectory,
                                             cacheFile,
                                             debug.exportMesh,
                                             scaledVersion.sphericalModel);
                }

                // Visualize the SOI
                if (debug.showSOI)
                {
                    generatedBody.celestialBody.gameObject.AddComponent <Wiresphere>();
                }

                // Loads external parser targets
                Parser.LoadExternalParserTargets(node, "Kopernicus");

                // Post gen celestial body
                Utility.DumpObjectFields(generatedBody.celestialBody, " Celestial Body ");
            }