void PatchOrUnpatchAll(bool patch) { if (patch) { Patcher.ApplyPatches(); SaveAndRebuildInspectors(); } else { SaveAndRebuildInspectors(); Patcher.UnpatchAll(); } }
public InspectorPatchesUI() { var me = this.Fluent(); var importantBox = me.NewHelpBox(ImportantMessage, HelpMessageType.Important); importantBox.x.content.icon.size = 16; me.Add(importantBox); var toolsIcon = FluentUITK.GetEditorIcon("SceneViewTools"); var group = me.NewHeader("Patches", toolsIcon).Style(Styles.Separator); me.Add(group); var bar = me.NewRow().Add( me.NewFlexibleSpace(), me.NewButton("Enable All").OnClick(_ => AllToggles().ForEach(e => e.value = true)), me.NewButton("Disable All").OnClick(_ => AllToggles().ForEach(e => e.value = false)) ); group.x.content.Add(bar); UQueryBuilder <Toggle> AllToggles() { return(group.x.Query <Toggle>()); } foreach (var patch in Patcher.GetPatches()) { var text = patch.GetType().Name; var toggle = new Toggle(text).Fluent(); toggle.x.value = !patch.state.forceSkip; toggle.OnChange <bool>((evt, c) => { var state = patch.state; state.forceSkip = !evt.newValue; patch.state = state; if (!prefs.enabled) { return; } if (state.forceSkip) { patch.UnpatchAll(); } else { patch.ApplyPatches(PatchBase.Apply.OnLoad); patch.ApplyPatches(PatchBase.Apply.OnGUI); } }); group.Add(toggle); } }