Exemplo n.º 1
0
            // Constructor for pre-existing PQS
            public PQSLoader(PQS pqsVersion)
            {
                this.pqsVersion = pqsVersion;

                // Get the required PQS information
                transform      = pqsVersion.GetComponentsInChildren <PQSMod_CelestialBodyTransform> (true).Where(mod => mod.transform.parent == pqsVersion.transform).FirstOrDefault();
                lightDirection = pqsVersion.GetComponentsInChildren <PQSMod_MaterialSetDirection>(true).Where(mod => mod.transform.parent == pqsVersion.transform).FirstOrDefault();
                uvs            = pqsVersion.GetComponentsInChildren <PQSMod_UVPlanetRelativePosition>(true).Where(mod => mod.transform.parent == pqsVersion.transform).FirstOrDefault();
                collider       = pqsVersion.GetComponentsInChildren <PQSMod_QuadMeshColliders>(true).Where(mod => mod.transform.parent == pqsVersion.transform).FirstOrDefault();

                // Create physics material editor
                physicsMaterial = new PhysicsMaterialParser(collider.physicsMaterial);

                // Clone the surface material of the PQS
                if (PQSMainOptimised.UsesSameShader(pqsVersion.surfaceMaterial))
                {
                    pqsVersion.surfaceMaterial = new PQSMainOptimisedLoader(pqsVersion.surfaceMaterial);
                    if (((PQSMainOptimisedLoader)pqsVersion.surfaceMaterial).globalDensity < 2)
                    {
                        ((PQSMainOptimisedLoader)pqsVersion.surfaceMaterial).globalDensity = -8E-06f;
                    }
                }
                else if (PQSMainShader.UsesSameShader(pqsVersion.surfaceMaterial))
                {
                    pqsVersion.surfaceMaterial = new PQSMainShaderLoader(pqsVersion.surfaceMaterial);
                    if (((PQSMainShaderLoader)pqsVersion.surfaceMaterial).globalDensity < 2)
                    {
                        ((PQSMainShaderLoader)pqsVersion.surfaceMaterial).globalDensity = -8E-06f;
                    }
                }
                else if (PQSProjectionAerialQuadRelative.UsesSameShader(pqsVersion.surfaceMaterial))
                {
                    pqsVersion.surfaceMaterial = new PQSProjectionAerialQuadRelativeLoader(pqsVersion.surfaceMaterial);
                    if (((PQSProjectionAerialQuadRelativeLoader)pqsVersion.surfaceMaterial).globalDensity < 2)
                    {
                        ((PQSProjectionAerialQuadRelativeLoader)pqsVersion.surfaceMaterial).globalDensity = -8E-06f;
                    }
                }
                else if (PQSProjectionSurfaceQuad.UsesSameShader(pqsVersion.surfaceMaterial))
                {
                    pqsVersion.surfaceMaterial = new PQSProjectionSurfaceQuadLoader(pqsVersion.surfaceMaterial);
                }
                surfaceMaterial      = pqsVersion.surfaceMaterial;
                surfaceMaterial.name = Guid.NewGuid().ToString();

                // Clone the fallback material of the PQS
                fallbackMaterial            = new PQSProjectionFallbackLoader(pqsVersion.fallbackMaterial);
                pqsVersion.fallbackMaterial = fallbackMaterial;
                fallbackMaterial.name       = Guid.NewGuid().ToString();
            }
Exemplo n.º 2
0
            public PQSLoader(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 != null)
                {
                    // Save the PQSVersion
                    Value = body.pqsController;

                    // Get the required PQS information
                    _transform = Value.GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true)
                                 .FirstOrDefault(Mod => Mod.transform.parent == Value.transform);
                    _collider = Value.GetComponentsInChildren <PQSMod_QuadMeshColliders>(true)
                                .FirstOrDefault(Mod => Mod.transform.parent == Value.transform);

                    // Clone the surface material of the PQS
                    if (PQSMainOptimised.UsesSameShader(surfaceMaterial))
                    {
                        PQSMainOptimisedLoader loader = new PQSMainOptimisedLoader(surfaceMaterial);
                        loader.globalDensity = loader.globalDensity < 2 ? (Single)(-8E-06) : loader.globalDensity;
                        surfaceMaterial      = loader;
                    }
                    else if (PQSMainShader.UsesSameShader(surfaceMaterial))
                    {
                        PQSMainShaderLoader loader = new PQSMainShaderLoader(surfaceMaterial);
                        loader.globalDensity = loader.globalDensity < 2 ? (Single)(-8E-06) : loader.globalDensity;
                        surfaceMaterial      = loader;
                    }
                    else if (PQSProjectionAerialQuadRelative.UsesSameShader(surfaceMaterial))
                    {
                        PQSProjectionAerialQuadRelativeLoader loader =
                            new PQSProjectionAerialQuadRelativeLoader(surfaceMaterial);
                        loader.globalDensity = loader.globalDensity < 2 ? (Single)(-8E-06) : loader.globalDensity;
                        surfaceMaterial      = loader;
                    }
                    else if (PQSProjectionSurfaceQuad.UsesSameShader(surfaceMaterial))
                    {
                        surfaceMaterial = new PQSProjectionSurfaceQuadLoader(surfaceMaterial);
                    }
                    surfaceMaterial.name = Guid.NewGuid().ToString();

                    // Clone the fallback material of the PQS
                    fallbackMaterial      = new PQSProjectionFallbackLoader(fallbackMaterial);
                    fallbackMaterial.name = Guid.NewGuid().ToString();
                }
                else
                {
                    // Create a new PQS
                    GameObject controllerRoot = new GameObject();
                    controllerRoot.transform.parent = body.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");
                    Utility.CopyObjectFields(Laythe.pqsVersion, Value);
                    Value.surfaceMaterial = Laythe.pqsVersion.surfaceMaterial;

                    // Create the fallback material (always the same shader)
                    fallbackMaterial       = new PQSProjectionFallbackLoader();
                    Value.fallbackMaterial = fallbackMaterial;
                    fallbackMaterial.name  = Guid.NewGuid().ToString();

                    // Create the celestial body transform
                    GameObject mod = new GameObject("_CelestialBody");
                    mod.transform.parent                     = controllerRoot.transform;
                    _transform                               = mod.AddComponent <PQSMod_CelestialBodyTransform>();
                    _transform.sphere                        = Value;
                    _transform.forceActivate                 = false;
                    _transform.deactivateAltitude            = 115000;
                    _transform.forceRebuildOnTargetChange    = false;
                    _transform.planetFade                    = new PQSMod_CelestialBodyTransform.AltitudeFade();
                    _transform.planetFade.fadeFloatName      = "_PlanetOpacity";
                    _transform.planetFade.fadeStart          = 100000.0f;
                    _transform.planetFade.fadeEnd            = 110000.0f;
                    _transform.planetFade.valueStart         = 0.0f;
                    _transform.planetFade.valueEnd           = 1.0f;
                    _transform.planetFade.secondaryRenderers = new List <GameObject>();
                    _transform.secondaryFades                = new PQSMod_CelestialBodyTransform.AltitudeFade[0];
                    _transform.requirements                  = PQS.ModiferRequirements.Default;
                    _transform.modEnabled                    = true;
                    _transform.order                         = 10;

                    // Create the material direction
                    mod = new GameObject("_Material_SunLight");
                    mod.transform.parent = controllerRoot.gameObject.transform;
                    PQSMod_MaterialSetDirection lightDirection = mod.AddComponent <PQSMod_MaterialSetDirection>();
                    lightDirection.sphere       = Value;
                    lightDirection.valueName    = "_sunLightDirection";
                    lightDirection.requirements = PQS.ModiferRequirements.Default;
                    lightDirection.modEnabled   = true;
                    lightDirection.order        = 100;

                    // Create the UV planet relative position
                    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;

                    // Crete the quad mesh colliders
                    mod = new GameObject("QuadMeshColliders");
                    mod.transform.parent     = controllerRoot.gameObject.transform;
                    _collider                = mod.AddComponent <PQSMod_QuadMeshColliders>();
                    _collider.sphere         = Value;
                    _collider.maxLevelOffset = 0;
                    _collider.requirements   = PQS.ModiferRequirements.Default;
                    _collider.modEnabled     = true;
                    _collider.order          = 100;
                }

                // Assing the new PQS
                body.pqsController                 = Value;
                body.pqsController.name            = body.transform.name;
                body.pqsController.transform.name  = body.transform.name;
                body.pqsController.gameObject.name = body.transform.name;
                body.pqsController.radius          = body.Radius;

                // Add an OnDemand Handler
                if (Value.GetComponentsInChildren <PQSMod_OnDemandHandler>(true).Length == 0)
                {
                    OnDemandStorage.AddHandler(Value);
                }

                // Load existing mods
                foreach (PQSMod mod in Value.GetComponentsInChildren <PQSMod>(true)
                         .Where(m => m.sphere == Value))
                {
                    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);
                    }
                }
            }
Exemplo n.º 3
0
            /**
             * Constructor for new PQS
             **/
            public PQSLoader()
            {
                if (generatedBody.pqsVersion != null)
                {
                    // Save the PQSVersion
                    pqsVersion = generatedBody.pqsVersion;

                    // Get the required PQS information
                    transform      = pqsVersion.GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true).Where(Mod => Mod.transform.parent == pqsVersion.transform).FirstOrDefault();
                    lightDirection = pqsVersion.GetComponentsInChildren <PQSMod_MaterialSetDirection>(true).Where(Mod => Mod.transform.parent == pqsVersion.transform).FirstOrDefault();
                    uvs            = pqsVersion.GetComponentsInChildren <PQSMod_UVPlanetRelativePosition>(true).Where(Mod => Mod.transform.parent == pqsVersion.transform).FirstOrDefault();
                    collider       = pqsVersion.GetComponentsInChildren <PQSMod_QuadMeshColliders>(true).Where(Mod => Mod.transform.parent == pqsVersion.transform).FirstOrDefault();

                    // Create physics material editor
                    physicsMaterial = new PhysicsMaterialParser(collider.physicsMaterial);

                    // Clone the surface material of the PQS
                    if (PQSMainOptimised.UsesSameShader(pqsVersion.surfaceMaterial))
                    {
                        pqsVersion.surfaceMaterial = new PQSMainOptimisedLoader(pqsVersion.surfaceMaterial);
                        if (((PQSMainOptimisedLoader)pqsVersion.surfaceMaterial).globalDensity < 2)
                        {
                            ((PQSMainOptimisedLoader)pqsVersion.surfaceMaterial).globalDensity = (float)-8E-06;
                        }
                    }
                    else if (PQSMainShader.UsesSameShader(pqsVersion.surfaceMaterial))
                    {
                        pqsVersion.surfaceMaterial = new PQSMainShaderLoader(pqsVersion.surfaceMaterial);
                        if (((PQSMainShaderLoader)pqsVersion.surfaceMaterial).globalDensity < 2)
                        {
                            ((PQSMainShaderLoader)pqsVersion.surfaceMaterial).globalDensity = (float)-8E-06;
                        }
                    }
                    else if (PQSProjectionAerialQuadRelative.UsesSameShader(pqsVersion.surfaceMaterial))
                    {
                        pqsVersion.surfaceMaterial = new PQSProjectionAerialQuadRelativeLoader(pqsVersion.surfaceMaterial);
                        if (((PQSProjectionAerialQuadRelativeLoader)pqsVersion.surfaceMaterial).globalDensity < 2)
                        {
                            ((PQSProjectionAerialQuadRelativeLoader)pqsVersion.surfaceMaterial).globalDensity = (float)-8E-06;
                        }
                    }
                    else if (PQSProjectionSurfaceQuad.UsesSameShader(pqsVersion.surfaceMaterial))
                    {
                        pqsVersion.surfaceMaterial = new PQSProjectionSurfaceQuadLoader(pqsVersion.surfaceMaterial);
                    }
                    surfaceMaterial      = pqsVersion.surfaceMaterial;
                    surfaceMaterial.name = Guid.NewGuid().ToString();

                    // Clone the fallback material of the PQS
                    fallbackMaterial            = new PQSProjectionFallbackLoader(pqsVersion.fallbackMaterial);
                    pqsVersion.fallbackMaterial = fallbackMaterial;
                    fallbackMaterial.name       = Guid.NewGuid().ToString();
                    return;
                }

                // Create a new PQS
                GameObject controllerRoot = new GameObject();

                controllerRoot.transform.parent = Utility.Deactivator;
                pqsVersion = controllerRoot.AddComponent <PQS> ();

                // I am at this time unable to determine some of the magic parameters which cause the PQS to work...
                PSystemBody Laythe = Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, "Laythe");

                Utility.CopyObjectFields(Laythe.pqsVersion, pqsVersion);
                pqsVersion.surfaceMaterial = Laythe.pqsVersion.surfaceMaterial;

                // Create the fallback material (always the same shader)
                fallbackMaterial            = new PQSProjectionFallbackLoader();
                pqsVersion.fallbackMaterial = fallbackMaterial;
                fallbackMaterial.name       = Guid.NewGuid().ToString();

                // Create the celestial body transform
                GameObject mod = new GameObject("_CelestialBody");

                mod.transform.parent                    = controllerRoot.transform;
                transform                               = mod.AddComponent <PQSMod_CelestialBodyTransform>();
                transform.sphere                        = pqsVersion;
                transform.forceActivate                 = false;
                transform.deactivateAltitude            = 115000;
                transform.forceRebuildOnTargetChange    = false;
                transform.planetFade                    = new PQSMod_CelestialBodyTransform.AltitudeFade();
                transform.planetFade.fadeFloatName      = "_PlanetOpacity";
                transform.planetFade.fadeStart          = 100000.0f;
                transform.planetFade.fadeEnd            = 110000.0f;
                transform.planetFade.valueStart         = 0.0f;
                transform.planetFade.valueEnd           = 1.0f;
                transform.planetFade.secondaryRenderers = new List <GameObject>();
                transform.secondaryFades                = new PQSMod_CelestialBodyTransform.AltitudeFade[0];
                transform.requirements                  = PQS.ModiferRequirements.Default;
                transform.modEnabled                    = true;
                transform.order                         = 10;

                // Create the material direction
                mod = new GameObject("_Material_SunLight");
                mod.transform.parent        = controllerRoot.gameObject.transform;
                lightDirection              = mod.AddComponent <PQSMod_MaterialSetDirection>();
                lightDirection.sphere       = pqsVersion;
                lightDirection.valueName    = "_sunLightDirection";
                lightDirection.requirements = PQS.ModiferRequirements.Default;
                lightDirection.modEnabled   = true;
                lightDirection.order        = 100;

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

                // Crete the quad mesh colliders
                mod = new GameObject("QuadMeshColliders");
                mod.transform.parent                     = controllerRoot.gameObject.transform;
                collider                                 = mod.AddComponent <PQSMod_QuadMeshColliders>();
                collider.sphere                          = pqsVersion;
                collider.maxLevelOffset                  = 0;
                collider.physicsMaterial                 = new PhysicMaterial();
                collider.physicsMaterial.name            = "Ground";
                collider.physicsMaterial.dynamicFriction = 0.6f;
                collider.physicsMaterial.staticFriction  = 0.8f;
                collider.physicsMaterial.bounciness      = 0.0f;
                collider.physicsMaterial.frictionCombine = PhysicMaterialCombine.Maximum;
                collider.physicsMaterial.bounceCombine   = PhysicMaterialCombine.Average;
                collider.requirements                    = PQS.ModiferRequirements.Default;
                collider.modEnabled                      = true;
                collider.order                           = 100;

                // Create physics material editor
                physicsMaterial = new PhysicsMaterialParser(collider.physicsMaterial);

                // Assing the new PQS
                generatedBody.pqsVersion = pqsVersion;
            }