/// <summary> /// Create stuff when the object is live /// </summary> protected override void Start() { // Get the LightShifter shifter = sun.scaledBody.GetComponentsInChildren <LightShifter>(true)?[0]; // Lensflare if (shifter != null) { lensFlare.sunFlare.flare = shifter.sunFlare ? shifter.sunFlare : lensFlare.sunFlare.flare; } // IVA Light if (HighLogic.LoadedScene == GameScenes.FLIGHT) { iva = UnityEngine.Object.Instantiate(Resources.FindObjectsOfTypeAll <IVASun>().Last(), transform, true); 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; Transform scaledLightTransform = scaledSunLight.transform; scaledLightTransform.parent = transform; scaledLightTransform.localPosition = Vector3.zero; scaledLightTransform.localRotation = Quaternion.identity; scaledSunLight.cullingMask = 1 << 10; GameEvents.onGameSceneLoadRequested.Add(SceneLoaded); }
/// <summary> /// Shuts down IVA and restores all game settings /// </summary> public void OnDestroy() { SetSun(true); CachedSun = null; //in case of revert to launch while in IVA, Update() won't detect it //and startIVA(p) will be called without prior stopIVA //which will cause settings to be lost forever //OnDestroy() will be called though if (ProbeControlRoomSettings.Instance.DisableSounds) { ProbeControlRoomUtils.Logger.message("OnDestroy() - DisableSounds - RESTORE"); //re-enable sound GameSettings.SHIP_VOLUME = shipVolumeBackup; GameSettings.AMBIENCE_VOLUME = ambianceVolumeBackup; } if (ProbeControlRoomSettings.Instance.DisableWobble) { ProbeControlRoomUtils.Logger.message("OnDestroy() - DisableWobble - RESTORE"); //re-enable camera wobble GameSettings.FLT_CAMERA_WOBBLE = cameraWobbleBackup; GameSettings.CAMERA_FX_INTERNAL = cameraFXInternalBackup; GameSettings.CAMERA_FX_EXTERNAL = cameraFXExternalBackup; } ProbeControlRoomUtils.Logger.message("OnDestroy() - VesselLabels - " + HasCachedVesselLabelsSetting.ToString() + ", " + VesselLabelKeyDisabled.ToString()); //Restore vessel labels capability. if (HasCachedVesselLabelsSetting) { HasCachedVesselLabelsSetting = false; SetVesselLabelsValue(CachedVesselLabelsSetting); } if (VesselLabelKeyDisabled) { VesselLabelKeyDisabled = false; GameSettings.TOGGLE_LABELS.primary = CachedLabelPrimaryKey; GameSettings.TOGGLE_LABELS.secondary = CachedLabelSecondaryKey; } //Restore part highlighter if (HasCachedHighlightInFlightSetting) { HasCachedHighlightInFlightSetting = false; GameSettings.INFLIGHT_HIGHLIGHT = CachedHighlightInFlightSetting; } ProbeControlRoomUtils.Logger.debug("OnDestroy()"); GameEvents.onVesselChange.Remove(OnVesselChange); GameEvents.onVesselWasModified.Remove(OnVesselModified); //GameEvents.onGUIApplicationLauncherReady.Remove(onGUIApplicationLauncherReady); onGUIApplicationLauncherReady(); GameEvents.onGUIApplicationLauncherDestroyed.Remove(OnGUIAppLauncherDestroyed); GameEvents.OnMapExited.Remove(onMapExited); GameEvents.OnCameraChange.Remove(onCameraChange); GameEvents.onGameSceneSwitchRequested.Remove(OnGameSceneSwitchRequested); if (toolbarControl != null) { #if false ApplicationLauncher.Instance.RemoveModApplication(appLauncherButton); appLauncherButton = null; #endif toolbarControl.OnDestroy(); Destroy(toolbarControl); } Instance = null; }
/// <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); }
/// <summary> /// Updates the light values based on the current scene /// </summary> /// <param name="scene"></param> void SceneLoaded(GameScenes scene) { light.shadowBias = scene != GameScenes.SPACECENTER ? 0.125f : 1f; if (gameObject.GetComponentInChildren<IVASun>() != null) DestroyImmediate(gameObject.GetComponentInChildren<IVASun>().gameObject); // IVA Sun if (HighLogic.LoadedSceneIsFlight) { iva = Instantiate(Resources.FindObjectsOfTypeAll<IVASun>().Last()); iva.transform.parent = transform; iva.sunT = transform; } }