Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
Update Toggle Post Processing.cs
Browse files Browse the repository at this point in the history
Restores default .enabled values instead of true/false values
in the rare chance that a world author uses gameobject.component.enabled instead of gameobject.isactive to toggle their post processing.
  • Loading branch information
Arion-Kun authored and Arion-Kun committed Sep 9, 2020
1 parent f355683 commit f32178a
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions Toggle Post Processing/Toggle Post Processing.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using UnityEngine.Rendering.PostProcessing;

Expand All @@ -16,28 +17,61 @@ public static class BuildInfo
}
public sealed class TogglePostProcessing : MelonMod
{
public bool ToggleHandler;
private static bool ToggleHandler;
private static List<OriginalVolume> OriginalVolumes;
public struct OriginalVolume
{

public PostProcessVolume postProcessVolume;

public bool defaultState;

}
public override void OnApplicationStart()
{
MelonPrefs.RegisterCategory("TogglePostProcessing", "Toggle Post Processing");
MelonPrefs.RegisterBool("TogglePostProcessing", "DisablePostProcessing", false, "Disable Post Processing");
ToggleHandler = MelonPrefs.GetBool("TogglePostProcessing", "DisablePostProcessing");
MelonLogger.Log("Settings can be configured in UserData\\modprefs.ini or through UIExpansionKit");
}
public override void OnLevelWasLoaded(int level)
{
GrabWorldVolumes();
ToggleMethod(ToggleHandler);
}
public override void OnModSettingsApplied()
{
ToggleHandler = MelonPrefs.GetBool("TogglePostProcessing", "DisablePostProcessing");
ToggleMethod(ToggleHandler);
}

private static void GrabWorldVolumes() //Credits to Psychloor for Method
{
OriginalVolumes = new List<OriginalVolume>();
foreach (var volume in UnityEngine.Object.FindObjectsOfType<PostProcessVolume>())
{
OriginalVolumes.Add(new OriginalVolume() { postProcessVolume = volume, defaultState = volume.enabled });
}
}
private static void Reset() //Credits to Psychloor for Method
{
foreach (OriginalVolume originalVolume in OriginalVolumes)
{
originalVolume.postProcessVolume.enabled = originalVolume.defaultState;
}
}
private static void ToggleMethod(bool value)
{
PostProcessVolume[] PostProcessingObjects = UnityEngine.Object.FindObjectsOfType<PostProcessVolume>().ToArray();
foreach (PostProcessVolume List in PostProcessingObjects)
if (value)
{
foreach (OriginalVolume originalVolume in OriginalVolumes)
{
originalVolume.postProcessVolume.enabled = !value;
}
}
else
{
List.GetComponent<PostProcessVolume>().enabled = !value;
Reset();
}
}
}
Expand Down

0 comments on commit f32178a

Please sign in to comment.