Пример #1
0
        /// <summary>
        /// Enables the input profile for the currently rendering scene (menu, ksc, editor, tracking, flight, flight-map)
        /// </summary>
        /// <param name="profileName"></param>
        internal void enableProfile(string profileName)
        {
            currentProfile = null;
            Camera activeCam = getActiveCamera();

            Log.debug("TUFX: enableProfile( " + profileName + " )  scene: ( " + HighLogic.LoadedScene + " ) map: ( " + isMapScene + " ) camera: ( " + activeCam?.name + " )");
            Log.debug(System.Environment.StackTrace);
            if (previousCamera != activeCam)
            {
                Log.log("Detected change of active camera; recreating post-process objects.");
                if (volume != null)
                {
                    Log.log("Destroying existing PostProcessVolume (from previous camera).");
                    Component.DestroyImmediate(layer);
                    UnityEngine.Object.DestroyImmediate(volume.sharedProfile);
                    UnityEngine.Object.DestroyImmediate(volume);
                    layer  = null;
                    volume = null;
                }
                previousScene  = HighLogic.LoadedScene;
                wasMapScene    = isMapScene;
                previousCamera = activeCam;
            }

            Log.debug("Active Camera (hashcode): " + activeCam?.GetHashCode());
            if (activeCam == null)
            {
                Log.log("Active camera was null.  Skipping profile setup for scene: " + HighLogic.LoadedScene);
            }
            else if (!string.IsNullOrEmpty(profileName) && Profiles.ContainsKey(profileName))
            {
                Log.log("Enabling profile: " + profileName + ".  Current GameScene: " + HighLogic.LoadedScene);
                TUFXProfile tufxProfile = Profiles[profileName];
                currentProfile = tufxProfile;
                Log.debug("Profile (hashcode): " + tufxProfile?.GetHashCode() + " :: " + tufxProfile?.ProfileName);
                Log.log("Setting HDR for camera: " + activeCam.name + " to: " + tufxProfile.HDREnabled);
                activeCam.allowHDR = tufxProfile.HDREnabled;
                onAntiAliasingSelected(tufxProfile.AntiAliasing, false);
                layer = activeCam.gameObject.AddOrGetComponent <PostProcessLayer>();
                layer.Init(Resources);
                layer.volumeLayer = ~0;//everything //TODO -- fix layer assignment...
                Log.debug("Layer: " + layer?.GetHashCode());
                volume          = activeCam.gameObject.AddOrGetComponent <PostProcessVolume>();
                volume.isGlobal = true;
                volume.priority = 100;
                Log.debug("Volume: " + volume.GetHashCode());
                if (volume.sharedProfile == null)
                {
                    volume.sharedProfile = tufxProfile.GetPostProcessProfile();
                }
                else
                {
                    volume.sharedProfile.settings.Clear();
                    tufxProfile.Enable(volume);
                }
                Log.log("Profile enabled: " + profileName);
                TUFXScatteringManager.INSTANCE.debugProfileSetup(volume, layer);
            }
            else if (string.IsNullOrEmpty(profileName))
            {
                Log.log("Clearing current profile for scene: " + HighLogic.LoadedScene);
            }
            else
            {
                Log.exception("Profile load was requested for: " + profileName + ", but no profile exists for that name.");
            }
        }
Пример #2
0
 public override int GetHashCode()
 {
     return((null == volume) ? 0 : volume.GetHashCode());
 }