/** * Constructor for pre-existing PQS * * @param pqsVersion Existing PQS to augment **/ 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 (PQSMainOptimisedLoader.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSMainOptimisedLoader(pqsVersion.surfaceMaterial); } else if (PQSMainShaderLoader.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSMainShaderLoader(pqsVersion.surfaceMaterial); } else if (PQSProjectionAerialQuadRelativeLoader.UsesSameShader(pqsVersion.surfaceMaterial)) { pqsVersion.surfaceMaterial = new PQSProjectionAerialQuadRelativeLoader(pqsVersion.surfaceMaterial); } else if (PQSProjectionSurfaceQuadLoader.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(); }
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 (MaterialType == SurfaceMaterialType.AtmosphericOptimized) { SurfaceMaterial = new PQSMainOptimisedLoader(SurfaceMaterial); } else if (MaterialType == SurfaceMaterialType.AtmosphericMain) { SurfaceMaterial = new PQSMainShaderLoader(SurfaceMaterial); } else if (MaterialType == SurfaceMaterialType.AtmosphericBasic) { SurfaceMaterial = new PQSProjectionAerialQuadRelativeLoader(SurfaceMaterial); } else if (MaterialType == SurfaceMaterialType.Vacuum) { SurfaceMaterial = new PQSProjectionSurfaceQuadLoader(SurfaceMaterial); } else if (MaterialType == SurfaceMaterialType.AtmosphericExtra) { SurfaceMaterial = new PQSMainExtrasLoader(SurfaceMaterial); } SurfaceMaterial.name = Guid.NewGuid().ToString(); // Clone the fallback material of the PQS FallbackMaterial = new PQSProjectionFallbackLoader(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 { fadeFloatName = "_PlanetOpacity", fadeStart = 100000.0f, fadeEnd = 110000.0f, valueStart = 0.0f, valueEnd = 1.0f, 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 // ReSharper disable Unity.InefficientPropertyAccess 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; // ReSharper restore Unity.InefficientPropertyAccess } // Assigning the new PQS body.pqsController = Value; Transform transform = body.transform; body.pqsController.name = transform.name; body.pqsController.transform.name = transform.name; body.pqsController.gameObject.name = 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(); 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); } } }
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); } } }