/* ///////////////////////////////////////////////////////////////////////////////////////////////// PluginReloader by VamEssentials - Atom Plugin Version Licensed under CC-BY. (see https://creativecommons.org/licenses/by/4.0/) ///////////////////////////////////////////////////////////////////////////////////////////////// */ using UnityEngine; using UnityEngine.UI; using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using SimpleJSON; namespace VamEssentials { public class PluginReloader : MVRScript { private string selectedAtom = ""; private string selectedPlugin = ""; private string selectedPlugin2 =""; private JSONStorableStringChooser atomChooser; private JSONStorableStringChooser pluginChooser; private JSONStorableAction reloadAction; private JSONStorableBool enableLogging; private JSONStorableStringChooser reloadHotkey; private JSONStorableAction triggerAction; // Trigger Delays private JSONStorableFloat triggerDelay1; private JSONStorableFloat triggerDelay2; private JSONStorableFloat triggerDelay3; private EventTriggerWithCallback trigger1; private EventTriggerWithCallback trigger2; private EventTriggerWithCallback trigger3; private JSONStorableString triggerActionName = new JSONStorableString("Trigger Action Name", "On Reload Complete"); private List triggerList = new List(); private readonly List hotkeyOptions = new List { "None", "Escape", "Space", "Tab", "Alpha1", "Alpha2", "Alpha3", "Alpha4", "Alpha5", "Alpha6", "Alpha7", "Alpha8", "Alpha9", "Alpha0", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M", "Keypad0", "Keypad1", "Keypad2", "Keypad3", "Keypad4", "Keypad5", "Keypad6", "Keypad7", "Keypad8", "Keypad9", "KeypadPlus", "KeypadMinus", "KeypadMultiply", "KeypadDivide", "UpArrow", "DownArrow", "LeftArrow", "RightArrow", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "Home", "End", "PageUp", "PageDown", "Insert", "Delete", "LeftControl", "RightControl", "LeftAlt", "RightAlt", "LeftShift", "RightShift", "Backspace", "Return", "Enter" }; // Start of Init public override void Init() { try { enableLogging = new JSONStorableBool("Enable Logging", false); RegisterBool(enableLogging); CreateToggle(enableLogging, false); if (containingAtom.type == "SessionPluginManager") { SuperController.LogError("PluginReloader is not supported as a Session Plugin. Please use it as a Scene Plugin instead."); return; } Log("PluginReloader loaded as a Scene Plugin."); SimpleTriggerHandler.LoadAssets(); reloadHotkey = new JSONStorableStringChooser("Reload HotKey", hotkeyOptions, "F5", "Reload HotKey"); RegisterStringChooser(reloadHotkey); CreateFilterablePopup(reloadHotkey, false); CreateUI(); CreateActions(); } catch (Exception e) { Log($"Error initializing plugin: {e.Message}"); } } // End of Init private void CreateUI() { // Left Side of UI atomChooser = new JSONStorableStringChooser("SelectedAtom", GetAtomUIDs(), "", "Select Atom", (atom) => { selectedAtom = atom; UpdatePluginsDropdown(); }); RegisterStringChooser(atomChooser); CreateFilterablePopup(atomChooser, false); pluginChooser = new JSONStorableStringChooser("SelectedPlugin", new List(), "", "Select Plugin", (plugin) => { selectedPlugin = plugin; }); RegisterStringChooser(pluginChooser); CreateFilterablePopup(pluginChooser, false); var reloadButton = CreateButton("Reload Plugin"); reloadButton.button.onClick.AddListener(() => ReloadPlugin()); // Right Side of UI triggerDelay1 = new JSONStorableFloat("Trigger Delay 1 (seconds)", 2.0f, 0.0f, 60.0f, true); triggerDelay2 = new JSONStorableFloat("Trigger Delay 2 (seconds)", 3.0f, 0.0f, 60.0f, true); triggerDelay3 = new JSONStorableFloat("Trigger Delay 3 (seconds)", 4.0f, 0.0f, 60.0f, true); RegisterFloat(triggerDelay1); RegisterFloat(triggerDelay2); RegisterFloat(triggerDelay3); trigger1 = new EventTriggerWithCallback(this, "Trigger After Delay 1"); trigger2 = new EventTriggerWithCallback(this, "Trigger After Delay 2"); trigger3 = new EventTriggerWithCallback(this, "Trigger After Delay 3"); trigger1.Callback = () => Log("Delay 1 Triggered"); trigger2.Callback = () => Log("Delay 2 Triggered"); trigger3.Callback = () => Log("Delay 3 Triggered"); CreateSlider(triggerDelay1, true); CreateButton("Edit Delay 1 Trigger", true).button.onClick.AddListener(() => trigger1.OpenPanel()); CreateSlider(triggerDelay2, true); CreateButton("Edit Delay 2 Trigger", true).button.onClick.AddListener(() => trigger2.OpenPanel()); CreateSlider(triggerDelay3, true); CreateButton("Edit Delay 3 Trigger", true).button.onClick.AddListener(() => trigger3.OpenPanel()); } private void CreateActions() { reloadAction = new JSONStorableAction("Reload Plugin", ReloadPlugin); RegisterAction(reloadAction); } private List GetAtomUIDs() { List atomUIDs = new List(); foreach (var atom in SuperController.singleton.GetAtoms()) { atomUIDs.Add(atom.uid); } return atomUIDs; } private void Update() { if (!string.IsNullOrEmpty(reloadHotkey?.val) && Input.GetKeyDown((KeyCode)Enum.Parse(typeof(KeyCode), reloadHotkey.val))) { ReloadPlugin(); StartCoroutine(ExecuteTriggersWithDelay()); } } private void UpdatePluginsDropdown() { Atom atom = SuperController.singleton.GetAtomByUid(selectedAtom); if (atom == null) return; var pluginNames = new List(); var pluginManager = atom.GetStorableByID("PluginManager") as MVRPluginManager; if (pluginManager != null) { foreach (var plugin in pluginManager.GetComponentsInChildren()) { pluginNames.Add(plugin.storeId); } } pluginChooser.choices = pluginNames; pluginChooser.SetVal(pluginNames.Count > 0 ? pluginNames[0] : ""); } private void ReloadPlugin() { removePlugin(selectedPlugin, "Reload"); } void DumpUIHierarchy(Transform root, string indent = "") { if (root == null) { SuperController.LogError("DumpUIHierarchy: root is null!"); return; } string line = indent + "↳ " + root.name; // Optional: Text-Komponente anzeigen Text txt = root.GetComponent(); if (txt != null && !string.IsNullOrEmpty(txt.text)) { line += $" [Text]: \"{txt.text}\""; } // Optional: Button-Komponente markieren Button btn = root.GetComponent