public RingLoader(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 = new GameObject(body.transform.name + "Ring").AddComponent <Ring>(); Value.transform.parent = body.scaledBody.transform; Value.planetRadius = (Single)body.Radius; // Need to check the parent body's rotation to orient the LAN properly Value.referenceBody = body; // Create the Component callback Components = new CallbackList <ComponentLoader <Ring> > (e => { Value.Components = Components.Select(c => c.Value).ToList(); }); // Load existing Modules foreach (IComponent <Ring> component in Value.Components) { Type componentType = component.GetType(); foreach (Type loaderType in Parser.ModTypes) { if (loaderType.BaseType == null) { continue; } if (loaderType.BaseType.Namespace != "Kopernicus.Configuration") { continue; } if (!loaderType.BaseType.Name.StartsWith("ComponentParser")) { continue; } if (loaderType.BaseType.GetGenericArguments()[0] != Value.GetType()) { continue; } if (loaderType.BaseType.GetGenericArguments()[1] != componentType) { continue; } // We found our loader type ComponentLoader <Ring> loader = (ComponentLoader <Ring>)Activator.CreateInstance(loaderType); loader.Create(component); Components.Add(loader); } } }
public RingLoader(Ring value) { Value = value; // Create the Component callback Components = new CallbackList <ComponentLoader <Ring> > (e => { Value.Components = Components.Select(c => c.Value).ToList(); }); // Load existing Modules foreach (IComponent <Ring> component in Value.Components) { Type componentType = component.GetType(); foreach (Type loaderType in Parser.ModTypes) { if (loaderType.BaseType == null) { continue; } if (loaderType.BaseType.Namespace != "Kopernicus.Configuration") { continue; } if (!loaderType.BaseType.Name.StartsWith("ComponentParser")) { continue; } if (loaderType.BaseType.GetGenericArguments()[0] != Value.GetType()) { continue; } if (loaderType.BaseType.GetGenericArguments()[1] != componentType) { continue; } // We found our loader type ComponentLoader <Ring> loader = (ComponentLoader <Ring>)Activator.CreateInstance(loaderType); loader.Create(component); Components.Add(loader); } } if (Value.innerMultCurve == null) { Value.innerMultCurve = new FloatCurve(new Keyframe[] { new Keyframe(0, 1), new Keyframe(1, 1) }); } if (Value.outerMultCurve == null) { Value.outerMultCurve = new FloatCurve(new Keyframe[] { new Keyframe(0, 1), new Keyframe(1, 1) }); } }
public RingLoader(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 = new GameObject(body.transform.name + "Ring").AddComponent <Ring>(); Value.transform.parent = body.scaledBody.transform; Value.planetRadius = (Single)body.Radius; // Need to check the parent body's rotation to orient the LAN properly Value.referenceBody = body; // Create the Component callback Components = new CallbackList <ComponentLoader <Ring> >(e => { Value.Components = Components.Select(c => c.Value).ToList(); }); // Load existing Modules foreach (IComponent <Ring> component in Value.Components) { Type componentType = component.GetType(); Type componentLoaderType = typeof(ComponentLoader <,>).MakeGenericType(typeof(Ring), componentType); foreach (Type loaderType in Parser.ModTypes) { if (!componentLoaderType.IsAssignableFrom(loaderType)) { continue; } // We found our loader type ComponentLoader <Ring> loader = (ComponentLoader <Ring>)Activator.CreateInstance(loaderType); loader.Create(component); Components.Add(loader); } } if (Value.innerMultCurve == null) { Value.innerMultCurve = new FloatCurve(new [] { new Keyframe(0, 1), new Keyframe(1, 1) }); } if (Value.outerMultCurve == null) { Value.outerMultCurve = new FloatCurve(new [] { new Keyframe(0, 1), new Keyframe(1, 1) }); } }
// Initialize the RingLoader public RingLoader(Ring value) { Value = value; // Create the Component callback Components = new CallbackList <ComponentLoader <Ring> >(e => { Value.Components = Components.Select(c => c.Value).ToList(); }); // Load existing Modules foreach (IComponent <Ring> component in Value.Components) { Type componentType = component.GetType(); Type componentLoaderType = typeof(ComponentLoader <,>).MakeGenericType(typeof(Ring), componentType); foreach (Type loaderType in Parser.ModTypes) { if (!componentLoaderType.IsAssignableFrom(loaderType)) { continue; } // We found our loader type ComponentLoader <Ring> loader = (ComponentLoader <Ring>)Activator.CreateInstance(loaderType); loader.Create(component); Components.Add(loader); } } if (Value.innerMultCurve == null) { Value.innerMultCurve = new FloatCurve(new[] { new Keyframe(0, 1), new Keyframe(1, 1) }); } if (Value.outerMultCurve == null) { Value.outerMultCurve = new FloatCurve(new[] { new Keyframe(0, 1), new Keyframe(1, 1) }); } }
// Runtime constructor public LandClassScatterLoader(PQSLandControl.LandClassScatter value) { Value = value; if (CustomMaterial) { if (NormalDiffuse.UsesSameShader(CustomMaterial)) { CustomMaterial = new NormalDiffuseLoader(CustomMaterial); } else if (NormalBumped.UsesSameShader(CustomMaterial)) { CustomMaterial = new NormalBumpedLoader(CustomMaterial); } else if (NormalDiffuseDetail.UsesSameShader(CustomMaterial)) { CustomMaterial = new NormalDiffuseDetailLoader(CustomMaterial); } else if (DiffuseWrap.UsesSameShader(CustomMaterial)) { CustomMaterial = new DiffuseWrapLoader(CustomMaterial); } else if (AlphaTestDiffuse.UsesSameShader(CustomMaterial)) { CustomMaterial = new AlphaTestDiffuseLoader(CustomMaterial); } else if (AerialTransCutout.UsesSameShader(CustomMaterial)) { CustomMaterial = new AerialTransCutoutLoader(CustomMaterial); } else if (Standard.UsesSameShader(CustomMaterial)) { CustomMaterial = new StandardLoader(CustomMaterial); } } // Get the Scatter-Parent GameObject scatterParent = typeof(PQSLandControl.LandClassScatter) .GetFields(BindingFlags.Instance | BindingFlags.NonPublic) .FirstOrDefault(f => f.FieldType == typeof(GameObject))?.GetValue(Value) as GameObject; // If the GameObject is null, create one if (scatterParent == null) { scatterParent = new GameObject("Scatter"); scatterParent.transform.parent = Utility.Deactivator; } // Add the scatter module Scatter = scatterParent.AddOrGetComponent <ModularScatter>(); Scatter.scatter = Value; // Create the Component callback Components = new CallbackList <ComponentLoader <ModularScatter> >(e => { Scatter.Components = Components.Select(c => c.Value).ToList(); }); // Load existing Modules foreach (IComponent <ModularScatter> component in Scatter.Components) { Type componentType = component.GetType(); Type componentLoaderType = typeof(ComponentLoader <>).MakeGenericType(Value.GetType(), componentType); foreach (Type loaderType in Parser.ModTypes) { if (!componentLoaderType.IsAssignableFrom(loaderType)) { continue; } // We found our loader type ComponentLoader <ModularScatter> loader = (ComponentLoader <ModularScatter>)Activator.CreateInstance(loaderType); loader.Create(component); Components.Add(loader); } } }