public void Remove()
        {
            CelestialBody celestialBody = Tools.GetCelestialBody(body);

            CityLightsManager.Log("Removing City Lights obj");
            Transform transform = Tools.GetScaledTransform(body);

            if (transform != null)
            {
                CityLightsManager.Log("Removing scaled obj");
                OverlayRenderer.Remove(transform.gameObject, scaledMat);

                GameObject.DestroyImmediate(transform.gameObject.GetComponents <ScaledCityComponent>().First(sc => sc.GUID == materialName));

                LocalCityComponent lc = FlightCamera.fetch.mainCamera.gameObject.GetComponents <LocalCityComponent>().FirstOrDefault(sc => sc.GUID == materialName);
                if (lc != null)
                {
                    GameObject.DestroyImmediate(lc);
                }
            }
            if (mainMenuBody != null)
            {
                GameObject.DestroyImmediate(mainMenuBody.GetComponents <ScaledCityComponent>().First(sc => sc.GUID == materialName));
            }
            materialPQS.Remove();

            GameEvents.onGameSceneLoadRequested.Remove(SceneLoaded);
            GameObject.DestroyImmediate(materialPQS);
        }
Ejemplo n.º 2
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!");
                }
            }
        }
        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!");
                }
            }
        }