Пример #1
0
        public OceanLoader(CelestialBody body)
        {
            // Is this a spawned body?
            if (body.scaledBody == null || Injector.IsInPrefab)
            {
                throw new InvalidOperationException("The body must be already spawned by the PSystemManager.");
            }

            if (body.pqsController.GetComponentsInChildren <PQS>(true).Any(p => p.name.EndsWith("Ocean")))
            {
                // Save the PQSVersion
                Value = body.pqsController.GetComponentsInChildren <PQS>(true).First(p => p.name.EndsWith("Ocean"));

                // Get the required PQS information
                SurfaceMaterial = new PQSOceanSurfaceQuadLoader(SurfaceMaterial)
                {
                    name = Guid.NewGuid().ToString()
                };

                // Clone the fallback material of the PQS
                FallbackMaterial = new PQSOceanSurfaceQuadFallbackLoader(FallbackMaterial)
                {
                    name = Guid.NewGuid().ToString()
                };
            }
            else
            {
                // Create a new PQS
                GameObject controllerRoot = new GameObject();
                controllerRoot.transform.parent = body.pqsController.transform;
                Value = controllerRoot.AddComponent <PQS>();

                // I (Teknoman) am at this time unable to determine some of the magic parameters which cause the PQS to work...
                // And I (Thomas) am at this time just too lazy to do it differently...
                PSystemBody laythe = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe");
                foreach (PQS oc in laythe.pqsVersion.GetComponentsInChildren <PQS>(true))
                {
                    if (oc.name != "LaytheOcean")
                    {
                        continue;
                    }

                    // Copying Laythes Ocean-properties
                    Utility.CopyObjectFields(oc, Value);

                    // Load Surface material
                    SurfaceMaterial = new PQSOceanSurfaceQuadLoader(oc.surfaceMaterial);

                    // Load Fallback-Material
                    FallbackMaterial = new PQSOceanSurfaceQuadFallbackLoader(oc.fallbackMaterial);
                    break;
                }

                // Load our new Material into the PQS
                SurfaceMaterial.name = Guid.NewGuid().ToString();

                // Load fallback material into the PQS
                FallbackMaterial.name = Guid.NewGuid().ToString();

                // Create the UV planet relative position
                GameObject mod = new GameObject("_Material_SurfaceQuads");
                mod.transform.parent = controllerRoot.transform;
                PQSMod_UVPlanetRelativePosition uvs = mod.AddComponent <PQSMod_UVPlanetRelativePosition>();
                uvs.sphere       = Value;
                uvs.requirements = PQS.ModiferRequirements.Default;
                uvs.modEnabled   = true;
                uvs.order        = 999999;
            }

            // Assigning the new PQS
            Body = body;
            Transform bodyTransform = body.transform;

            Value.name            = bodyTransform.name + "Ocean";
            Value.transform.name  = bodyTransform.name + "Ocean";
            Value.gameObject.name = bodyTransform.name + "Ocean";
            Value.radius          = body.Radius;
            Value.parentSphere    = body.pqsController;

            // Add the ocean PQS to the secondary renders of the CelestialBody Transform
            PQSMod_CelestialBodyTransform transform = body.pqsController
                                                      .GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true)
                                                      .FirstOrDefault(m => m.transform.parent == body.pqsController.transform);

            if (transform != null)
            {
                transform.planetFade.secondaryRenderers.Add(Value.gameObject);
            }

            // Load existing mods
            foreach (PQSMod mod in Value.GetComponentsInChildren <PQSMod>(true))
            {
                Type modType       = mod.GetType();
                Type modLoaderType = typeof(ModLoader <>).MakeGenericType(modType);
                foreach (Type loaderType in Parser.ModTypes)
                {
                    if (!modLoaderType.IsAssignableFrom(loaderType))
                    {
                        continue;
                    }

                    // We found our loader type
                    IModLoader loader = (IModLoader)Activator.CreateInstance(loaderType);
                    loader.Create(mod, Value);
                    Mods.Add(loader);
                }
            }

            Fog = new FogLoader(body);
        }
Пример #2
0
        public OceanLoader(CelestialBody body)
        {
            // Is this a spawned body?
            if (body.scaledBody == null || Injector.IsInPrefab)
            {
                throw new InvalidOperationException("The body must be already spawned by the PSystemManager.");
            }


            Value = body.pqsController.GetComponentsInChildren <PQS>(true)
                    .FirstOrDefault(p => p.name.EndsWith("Ocean"));

            if (!Value)
            {
                // Create a new PQS
                GameObject controllerRoot = new GameObject();
                controllerRoot.transform.parent = body.pqsController.transform;
                Value = controllerRoot.AddComponent <PQS>();

                // I (Teknoman) am at this time unable to determine some of the magic parameters which cause the PQS to work...
                // And I (Thomas) am at this time just too lazy to do it differently...
                PSystemBody laythe = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe");
                PQS[]       oceans = laythe.pqsVersion.GetComponentsInChildren <PQS>(true);
                for (Int32 i = 0; i < oceans.Length; i++)
                {
                    if (oceans[i].name != "LaytheOcean")
                    {
                        continue;
                    }

                    Utility.CopyObjectFields(oceans[i], Value);

                    // Create the material (always the same shader)
                    SurfaceMaterial  = new PQSOceanSurfaceQuadLoader(oceans[i].surfaceMaterial);
                    FallbackMaterial = new PQSOceanSurfaceQuadFallbackLoader(oceans[i].fallbackMaterial);

                    break;
                }

                // Create the UV planet relative position
                Utility.AddMod <PQSMod_UVPlanetRelativePosition>(Value, 9999999);
            }

            // Assigning the new PQS
            Body = body;
            Transform bodyTransform = body.transform;

            Value.name            = bodyTransform.name + "Ocean";
            Value.transform.name  = bodyTransform.name + "Ocean";
            Value.gameObject.name = bodyTransform.name + "Ocean";
            Value.radius          = body.Radius;
            Value.parentSphere    = body.pqsController;
            MapOcean = true;

            // Add the ocean PQS to the secondary renders of the CelestialBody Transform
            PQSMod_CelestialBodyTransform transform =
                Utility.GetMod <PQSMod_CelestialBodyTransform>(body.pqsController);

            if (transform != null)
            {
                transform.planetFade.secondaryRenderers.Add(Value.gameObject);
            }

            // Load existing mods
            PQSMod[] mods = Utility.GetMods <PQSMod>(Value);
            for (Int32 i = 0; i < mods.Length; i++)
            {
                Type modType       = mods[i].GetType();
                Type modLoaderType = typeof(ModLoader <>).MakeGenericType(modType);

                for (Int32 j = 0; j < Parser.ModTypes.Count; j++)
                {
                    if (!modLoaderType.IsAssignableFrom(Parser.ModTypes[j]))
                    {
                        continue;
                    }

                    IModLoader loader = (IModLoader)Activator.CreateInstance(Parser.ModTypes[j]);
                    loader.Create(mods[i], Value);
                    Mods.Add(loader);
                }
            }

            Fog = new FogLoader(body);
        }
Пример #3
0
            /// <summary>
            /// Creates a new Ocean Loader from the Injector context.
            /// </summary>
            public OceanLoader()
            {
                // Is this the parser context?
                if (!Injector.IsInPrefab)
                {
                    throw new InvalidOperationException("Must be executed in Injector context.");
                }

                if (generatedBody.pqsVersion.GetComponentsInChildren <PQS>(true).Any(p => p.name.EndsWith("Ocean")))
                {
                    // Save the PQSVersion
                    Value = generatedBody.pqsVersion.GetComponentsInChildren <PQS>(true).First(p => p.name.EndsWith("Ocean"));

                    // Get the required PQS information
                    surfaceMaterial      = new PQSOceanSurfaceQuadLoader(surfaceMaterial);
                    surfaceMaterial.name = Guid.NewGuid().ToString();

                    // Clone the fallback material of the PQS
                    fallbackMaterial      = new PQSOceanSurfaceQuadFallbackLoader(fallbackMaterial);
                    fallbackMaterial.name = Guid.NewGuid().ToString();
                }
                else
                {
                    // Create a new PQS
                    GameObject controllerRoot = new GameObject();
                    controllerRoot.transform.parent = generatedBody.pqsVersion.transform;
                    Value = controllerRoot.AddComponent <PQS>();

                    // I (Teknoman) am at this time unable to determine some of the magic parameters which cause the PQS to work...
                    // And I (Thomas) am at this time just too lazy to do it differently...
                    PSystemBody Laythe = Utility.FindBody(Injector.StockSystemPrefab.rootBody, "Laythe");
                    foreach (PQS oc in Laythe.pqsVersion.GetComponentsInChildren <PQS>(true))
                    {
                        if (oc.name == "LaytheOcean")
                        {
                            // Copying Laythes Ocean-properties
                            Utility.CopyObjectFields(oc, Value);

                            // Load Surface material
                            surfaceMaterial = new PQSOceanSurfaceQuadLoader(oc.surfaceMaterial);

                            // Load Fallback-Material
                            fallbackMaterial = new PQSOceanSurfaceQuadFallbackLoader(oc.fallbackMaterial);
                            break;
                        }
                    }

                    // Load our new Material into the PQS
                    surfaceMaterial.name = Guid.NewGuid().ToString();

                    // Load fallback material into the PQS
                    fallbackMaterial.name = Guid.NewGuid().ToString();

                    // Create the UV planet relative position
                    GameObject mod = new GameObject("_Material_SurfaceQuads");
                    mod.transform.parent = controllerRoot.transform;
                    PQSMod_UVPlanetRelativePosition uvs = mod.AddComponent <PQSMod_UVPlanetRelativePosition>();
                    uvs.sphere       = Value;
                    uvs.requirements = PQS.ModiferRequirements.Default;
                    uvs.modEnabled   = true;
                    uvs.order        = 999999;
                }

                // Assing the new PQS
                body                  = generatedBody.celestialBody;
                Value.name            = generatedBody.name + "Ocean";
                Value.transform.name  = generatedBody.name + "Ocean";
                Value.gameObject.name = generatedBody.name + "Ocean";
                Value.radius          = generatedBody.celestialBody.Radius;
                Value.parentSphere    = generatedBody.pqsVersion;

                // Add the ocean PQS to the secondary renders of the CelestialBody Transform
                PQSMod_CelestialBodyTransform transform = generatedBody.pqsVersion.GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true).FirstOrDefault(m => m.transform.parent == generatedBody.pqsVersion.transform);

                transform.planetFade.secondaryRenderers.Add(Value.gameObject);

                // Load existing mods
                foreach (PQSMod mod in Value.GetComponentsInChildren <PQSMod>(true))
                {
                    Type modType = mod.GetType();
                    foreach (Type loaderType in Parser.ModTypes)
                    {
                        if (loaderType.BaseType == null)
                        {
                            continue;
                        }
                        if (loaderType.BaseType.Namespace != "Kopernicus.Configuration.ModLoader")
                        {
                            continue;
                        }
                        if (!loaderType.BaseType.Name.StartsWith("ModLoader"))
                        {
                            continue;
                        }
                        if (loaderType.BaseType.GetGenericArguments()[0] != modType)
                        {
                            continue;
                        }

                        // We found our loader type
                        IModLoader loader = (IModLoader)Activator.CreateInstance(loaderType);
                        loader.Create(mod, Value);
                        mods.Add(loader);
                    }
                }
            }