예제 #1
0
        private void ApplyToMainMenu()
        {
            if (HighLogic.LoadedScene == GameScenes.MAINMENU)
            {
                GameObject go = Tools.GetMainMenuObject(body);

                if (go != mainMenuBody && go != null)
                {
                    mainMenuBody = go;
                    Renderer r = mainMenuBody.GetComponent <Renderer>();
                    if (r != null)
                    {
                        scaledMat.SetTexture("_MainTex", r.material.GetTexture("_MainTex"));
                        Light sunlight = GameObject.FindObjectsOfType <Light>().Last(l => l.isActiveAndEnabled);
                        DeferredRenderer.Add(r.gameObject, scaledMat);

                        ScaledCityComponent sc = r.gameObject.AddComponent <ScaledCityComponent>();
                        sc.Apply(scaledMat, sunlight);

                        CityLightsManager.Log("Applied to main Menu");
                    }
                }
                else if (go == null)
                {
                    CityLightsManager.Log("Cannot Find to apply to main Menu!");
                }
                else if (mainMenuBody == go)
                {
                    CityLightsManager.Log("Already Applied to main Menu!");
                }
            }
        }
예제 #2
0
        public void Apply()
        {
            CelestialBody celestialBody = Tools.GetCelestialBody(body);

            if (celestialBody != null)
            {
                GameObject go = new GameObject();
                materialPQS          = go.AddComponent <MaterialPQS>();
                macroMat             = materialPQS.Apply(celestialBody, cityLightsMaterial, ShaderLoaderClass.FindShader("EVE/TerrainCityLight"), true, false);
                macroMat.name        = materialName;
                macroMat.renderQueue = (int)Tools.Queue.Geometry + 1;
            }
            Transform transform = Tools.GetScaledTransform(body);

            if (transform != null)
            {
                Renderer r = transform.GetComponent <Renderer>();
                if (r != null)
                {
                    scaledMat = new Material(ShaderLoaderClass.FindShader("EVE/PlanetCityLight"));

                    cityLightsMaterial.ApplyMaterialProperties(scaledMat);
                    scaledMat.SetTexture("_MainTex", r.material.GetTexture("_MainTex"));
                    scaledMat.name        = materialName;
                    scaledMat.renderQueue = (int)Tools.Queue.Geometry + 1;
                    OverlayRenderer.Add(r.gameObject, scaledMat);

                    ScaledCityComponent sc    = transform.gameObject.AddComponent <ScaledCityComponent>();
                    FieldInfo           field = typeof(Sun).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).First(
                        f => f.Name == "scaledSunLight");
                    Light slight = (Light)field.GetValue(Sun.Instance);

                    sc.Apply(scaledMat, slight);
                }
            }


            LocalCityComponent lsc = FlightCamera.fetch.mainCamera.gameObject.AddComponent <LocalCityComponent>();
            Light light            = Sun.Instance.GetComponent <Light>();

            lsc.Apply(macroMat, light);

            ApplyToMainMenu();

            GameEvents.onGameSceneLoadRequested.Add(SceneLoaded);
            if (HighLogic.LoadedScene == GameScenes.MAINMENU)
            {
                ApplyToMainMenu();
            }
        }
        private void ApplyToMainMenu()
        {
            if (HighLogic.LoadedScene == GameScenes.MAINMENU)
            {
                GameObject go = Tools.GetMainMenuObject(body);

                if (go != mainMenuBody && go != null)
                {
                    mainMenuBody = go;
                    Renderer r = mainMenuBody.GetComponent <Renderer>();
                    if (r != null)
                    {
                        scaledMat.SetTexture("_MainTex", r.material.GetTexture("_MainTex"));
                        Light sunlight = GameObject.FindObjectsOfType <Light>().Last(l => l.isActiveAndEnabled);
                        DeferredRenderer.Add(r.gameObject, scaledMat);

                        if (mainMenuBody.name.EndsWith("(Clone)"))
                        {
                            // There is a race condition with Kopernicus. Sometimes, it
                            // will have cloned a body that already had clouds. Hide old clouds.
                            for (var c = 0; c < mainMenuBody.transform.childCount; ++c)
                            {
                                var child = mainMenuBody.transform.GetChild(c).gameObject;
                                if (child.name.StartsWith("EVE City Lights") && child.name.EndsWith("(Clone)"))
                                {
                                    child.SetActive(false);
                                }
                            }
                        }

                        ScaledCityComponent sc = r.gameObject.AddComponent <ScaledCityComponent>();
                        sc.Apply(scaledMat, sunlight);

                        CityLightsManager.Log("Applied to main Menu");
                    }
                }
                else if (go == null)
                {
                    CityLightsManager.Log("Cannot Find to apply to main Menu!");
                }
                else if (mainMenuBody == go)
                {
                    CityLightsManager.Log("Already Applied to main Menu!");
                }
            }
        }