Пример #1
0
        public void SetAsActive(bool forcedUpdate = false)
        {
            // Only reset the Sun / SolarPanels if we don't force an update
            if (!forcedUpdate)
            {
                // Set star as active star
                Debug.Log("[Kopernicus]: StarLightSwitcher: Set active star => " + celestialBody.bodyName);

                // Set custom powerCurve for solar panels and reset Radiators
                if (FlightGlobals.ActiveVessel != null)
                {
                    // SoalrPanels
                    foreach (ModuleDeployableSolarPanel sp in FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleDeployableSolarPanel>())
                    {
                        sp.sunTransform = celestialBody.transform;
                    }

                    // Radiators
                    foreach (ModuleDeployableRadiator rad in FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleDeployableRadiator>())
                    {
                        radiatorSun.SetValue(rad, celestialBody.transform);
                    }

                    // Flight Integrator
                    FlightIntegrator.sunBody = celestialBody;
                }
            }

            // Reset the LightShifter
            LightShifter lsc = null;

            LightShifter[] comps = Sun.Instance.sun.scaledBody.GetComponentsInChildren <LightShifter>(true);
            if (comps != null && comps.Length > 0)
            {
                lsc = comps[0];
                lsc.SetStatus(false, HighLogic.LoadedScene);
            }
            Sun.Instance.sun = celestialBody;
            comps            = celestialBody.scaledBody.GetComponentsInChildren <LightShifter>(true);
            if (comps != null && comps.Length > 0)
            {
                lsc = comps[0];
                lsc.SetStatus(true, HighLogic.LoadedScene);

                // Set SunFlare color
                Sun.Instance.sunFlare.color = lsc.sunLensFlareColor;
                Sun.Instance.SunlightEnabled(lsc.givesOffLight);

                // Set other stuff
                Sun.Instance.AU = lsc.AU;
                Sun.Instance.brightnessCurve = lsc.brightnessCurve.Curve;

                // Physics Globals
                PhysicsGlobals.SolarLuminosityAtHome = lsc.solarLuminosity;
                PhysicsGlobals.SolarInsolationAtHome = lsc.solarInsolation;
            }
        }
Пример #2
0
            /// <summary>
            /// Renders the Window
            /// </summary>
            protected override void Render(Int32 id)
            {
                // Call base
                base.Render(id);

                // Scroll
                BeginScrollView(250, Utils.GetScrollSize <LightShifter>() + Utils.GetScrollSize <EmissiveMultiRampSunspots>() + distance * 4, 20);

                // Index
                index = 0;

                // Planet must be a star
                if (Current.scaledBody.GetComponentsInChildren <SunShaderController>(true).Length == 0)
                {
                    Label(Localization.LOC_KITTOPIATECH_STARLIGHTEDITOR_NOSTAR, new Rect(20, 310, 400, 20));
                    return;
                }

                // Get the light components
                if (lsc == null || material == null)
                {
                    lsc      = Current.scaledBody.GetComponentsInChildren <LightShifter>(true).First();
                    material = new EmissiveMultiRampSunspots(Current.scaledBody.GetComponent <Renderer>().sharedMaterial);
                }

                // Render the objects
                RenderObject(material);
                RenderObject(lsc);

                // Space
                index++;

                // Apply
                Button(Localization.LOC_KITTOPIATECH_APPLY, () =>
                {
                    Current.scaledBody.GetComponent <Renderer>().sharedMaterial = material;
                    Current.scaledBody.GetComponentsInChildren <StarComponent>().First().SetAsActive();
                });

                // End Scroll
                EndScrollView();
            }
Пример #3
0
 /// <summary>
 /// Resets objects
 /// </summary>
 protected override void SetEditedObject()
 {
     lsc      = null;
     material = null;
 }
Пример #4
0
        void IParserEventSubscriber.PostApply(ConfigNode node)
        {
            // Apply changes to the Material
            Material material = generatedBody.scaledVersion.GetComponent <Renderer>()?.sharedMaterial;

            if (material != null)
            {
                if (emitColor0?.value != null)
                {
                    Color color = Pick(emitColor0);

                    material.SetColor("_EmitColor0", color);

                    if (emitColorMult != null)
                    {
                        material.SetColor("_EmitColor1", color * emitColorMult);
                    }

                    if (rimColorMult != null)
                    {
                        material.SetColor("_RimColor", color * rimColorMult);
                    }
                }

                if (emitColor1 != null)
                {
                    material.SetColor("_EmitColor1", Pick(emitColor1));
                }

                if (sunspotColor == null)
                {
                    sunspotColor = emitColor0;
                }

                if (sunspotTemp == null)
                {
                    sunspotTemp = temperature;
                }

                material.SetColor("_SunspotColor", Pick(sunspotColor, sunspotTemp) * sunspotColorMult);

                if (type == StarType.WhiteDwarf)
                {
                    material.SetColor("_EmitColor0", new Color(0.9f, 0.9f, 0.9f, 1));
                    material.SetColor("_EmitColor1", material.GetColor("_EmitColor1") * 0.925f);
                }
            }


            // Apply changes to the LightShifter
            LightShifter light = generatedBody.scaledVersion.GetComponentInChildren <LightShifter>();

            if (light != null)
            {
                if (lightColors == null)
                {
                    lightColors = emitColor0;
                }

                Color color = Pick(lightColors) * lightColorMult;

                light.ambientLightColor   = new Color(0, 0, 0, 1);
                light.IVASunColor         = color;
                light.scaledSunlightColor = color;
                light.sunlightColor       = color;
            }


            // Set Orbit Color
            if (setOrbit.value && emitColor0 != null)
            {
                generatedBody.orbitRenderer.SetColor(Pick(emitColor0));
            }
        }
Пример #5
0
            /// <summary>
            /// Create stuff when the object is live
            /// </summary>
            protected override void Start()
            {
                // Get the LightShifter
                shifter = sun.scaledBody.GetComponentsInChildren<LightShifter>(true)?[0];

                // Lensflare
                sunFlare.flare = shifter.sunFlare ?? sunFlare.flare;

                // IVA Light
                if (HighLogic.LoadedScene == GameScenes.FLIGHT)
                {
                    iva = Instantiate(Resources.FindObjectsOfTypeAll<IVASun>().Last());
                    iva.transform.parent = transform;
                    iva.sunT = transform;
                }

                // Scaled Space Light
                if (!useLocalSpaceSunLight) return;
                scaledSunLight = (new GameObject("Scaledspace SunLight " + sun.name)).AddComponent<Light>();
                scaledSunLight.type = LightType.Directional;
                scaledSunLight.intensity = light.intensity;
                scaledSunLight.color = light.color;
                scaledSunLight.transform.parent = transform;
                scaledSunLight.transform.localPosition = Vector3.zero;
                scaledSunLight.transform.localRotation = Quaternion.identity;
                scaledSunLight.cullingMask = 1 << 10;
                GameEvents.onGameSceneLoadRequested.Add(SceneLoaded);
            }
Пример #6
0
            /// <summary>
            /// Create stuff when the object is live
            /// </summary>
            protected override void Start()
            {
                // Get the LightShifter
                shifter = sun.scaledBody.GetComponentsInChildren<LightShifter>(true)?[0];

                // Lensflare
                sunFlare.flare = shifter.sunFlare ?? sunFlare.flare;

                // Gah
                typeof(Sun).GetField("lgt", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(this, light);

                // Scaled Space Light
                if (!useLocalSpaceSunLight) return;
                scaledSunLight = (new GameObject("Scaledspace SunLight " + sun.name)).AddComponent<Light>();
                scaledSunLight.type = LightType.Directional;
                scaledSunLight.intensity = light.intensity;
                scaledSunLight.color = light.color;
                scaledSunLight.transform.parent = transform;
                scaledSunLight.transform.localPosition = Vector3.zero;
                scaledSunLight.transform.localRotation = Quaternion.identity;
                scaledSunLight.cullingMask = 1024;
                light.cullingMask = light.cullingMask ^ 1024;
                GameEvents.onGameSceneLoadRequested.Add(SceneLoaded);
            }