### Standalone UnityExplorer Instance Creation (C#) Source: https://github.com/sinai-dev/unityexplorer/blob/master/README.md Demonstrates how to create an instance of UnityExplorer in a standalone application. This requires manually loading dependencies like UniverseLib, HarmonyX, and MonoMod. For IL2CPP, additional setup with Il2CppAssemblyUnhollower is necessary. ```csharp using UnityExplorer; // ... other setup code ... // Create an instance of UnityExplorer ExplorerStandalone.CreateInstance(); // Optionally subscribe to the OnLog event for custom logging ExplorerStandalone.OnLog += (message) => { Console.WriteLine("UnityExplorer Log: " + message); }; ``` -------------------------------- ### Unity Editor Integration (C#) Source: https://github.com/sinai-dev/unityexplorer/blob/master/README.md Instructions for integrating UnityExplorer into the Unity Editor. This involves downloading the editor release, installing it as a package, and then adding the UnityExplorer prefab or script to a GameObject in the scene. ```csharp // After importing the UnityExplorer package or folder: // Option 1: Drag the Runtime/UnityExplorer prefab into your scene. // Option 2: Create a new GameObject and add the 'Explorer Editor Behaviour' script to it. ``` -------------------------------- ### Configuration API Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Access and modify UnityExplorer settings programmatically. This API allows you to get and set various configuration values, subscribe to changes, and access related paths. ```APIDOC ## Configuration API ### Description Access and modify UnityExplorer settings programmatically. ### Methods - **Get Configuration Value**: `ConfigManager.ConfigName.Value` - **Set Configuration Value**: `ConfigManager.ConfigName.Value = newValue;` - **Subscribe to Value Changes**: `ConfigManager.ConfigName.OnValueChanged += (newValue) => { /* handle change */ };` ### Available Configuration Options - **Master Toggle Key**: `ConfigManager.Master_Toggle` (KeyCode) - **Hide On Startup**: `ConfigManager.Hide_On_Startup` (bool) - **Startup Delay Time**: `ConfigManager.Startup_Delay_Time` (float) - **Disable EventSystem Override**: `ConfigManager.Disable_EventSystem_Override` (bool) - **Target Display**: `ConfigManager.Target_Display` (int) - **Force Unlock Mouse**: `ConfigManager.Force_Unlock_Mouse` (bool) - **Default Output Path**: `ConfigManager.Default_Output_Path` (string) - **DnSpy Path**: `ConfigManager.DnSpy_Path` (string) - **World Mouse Inspect Keybind**: `ConfigManager.World_MouseInspect_Keybind` (KeyCode) - **UI Mouse Inspect Keybind**: `ConfigManager.UI_MouseInspect_Keybind` (KeyCode) - **C# Console Assembly Blacklist**: `ConfigManager.CSConsole_Assembly_Blacklist` (string) - **Reflection Signature Blacklist**: `ConfigManager.Reflection_Signature_Blacklist` (string) ### Example Usage ```csharp using UnityExplorer.Config; using UnityEngine; // Get a configuration value KeyCode toggleKey = ConfigManager.Master_Toggle.Value; // Set a configuration value ConfigManager.Hide_On_Startup.Value = true; // Subscribe to a configuration change ConfigManager.Force_Unlock_Mouse.OnValueChanged += (bool value) => { Debug.Log($"Force unlock mouse setting changed to: {value}"); }; ``` ``` -------------------------------- ### C# Console - Script Interaction Helpers Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Provides helper methods directly available within the C# Console REPL environment for interacting with UnityExplorer and game objects. These include getting targets, logging messages, inspecting objects, managing coroutines, and clipboard operations. ```csharp // These helpers are available directly in the C# Console REPL // Get the target of the currently active inspector tab var target = CurrentTarget; // Get all targets from all open inspector tabs object[] allTargets = AllTargets; // Log messages to UnityExplorer's log panel Log("This message appears in the Log panel"); Log(someObject); // Inspect objects programmatically Inspect(GameObject.Find("Player")); Inspect(typeof(Physics)); // Start and stop coroutines IEnumerator MyCoroutine() { yield return new WaitForSeconds(1f); Log("Coroutine finished!"); } Coroutine coro = Start(MyCoroutine()); Stop(coro); // Copy and paste objects via clipboard Copy(someObject); object pasted = Paste(); // View current using directives GetUsing(); // View defined REPL variables GetVars(); // View compiled classes GetClasses(); // Define a class that persists until application closes public class MyHelper { public static void DoSomething() { UnityExplorer.ExplorerCore.Log("Helper called!"); } } // Then call it: MyHelper.DoSomething(); ``` -------------------------------- ### Automatic Startup Script for UnityExplorer Source: https://context7.com/sinai-dev/unityexplorer/llms.txt This C# script is designed to run automatically when UnityExplorer initializes. It logs a startup message, attempts to auto-inspect the main camera, sets up useful session variables by finding game objects, and defines helper classes for debugging tasks like listing all game objects and setting the time scale. ```csharp // Save this file as: sinai-dev-UnityExplorer/Scripts/startup.cs // It will execute automatically when UnityExplorer loads using UnityEngine; // Log startup message Log("UnityExplorer startup script executed!"); // Auto-inspect the main camera if (Camera.main != null) { Inspect(Camera.main.gameObject); Log($"Auto-inspecting main camera: {Camera.main.name}"); } // Set up some useful variables for the session var player = GameObject.Find("Player"); var gameManager = GameObject.FindObjectOfType(); // Log game state Log($"Current scene: {UnityEngine.SceneManagement.SceneManager.GetActiveScene().name}"); Log($"Time scale: {Time.timeScale}"); Log($"Frame rate: {Application.targetFrameRate}"); // Define helper classes for the session public class DebugHelper { public static void ListAllGameObjects() { foreach (var go in GameObject.FindObjectsOfType()) { UnityExplorer.ExplorerCore.Log(go.name); } } public static void SetTimeScale(float scale) { Time.timeScale = scale; UnityExplorer.ExplorerCore.Log($"Time scale set to: {scale}"); } } ``` -------------------------------- ### Standalone Initialization of UnityExplorer Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Initializes UnityExplorer as a standalone component without requiring a mod loader. It supports custom log listeners and specifying a path for unhollowed modules, which is crucial for IL2CPP environments. You can also subscribe to log events after initialization. ```csharp using UnityExplorer; using UnityEngine; // Basic initialization without logging or custom paths ExplorerStandalone.CreateInstance(); // Initialize with a custom log listener ExplorerStandalone.CreateInstance((string message, LogType logType) => { switch (logType) { case LogType.Log: Console.WriteLine($"[UE] {message}"); break; case LogType.Warning: Console.WriteLine($"[UE Warning] {message}"); break; case LogType.Error: Console.WriteLine($"[UE Error] {message}"); break; } }); // Initialize with custom log listener and unhollowed modules path (for IL2CPP) ExplorerStandalone.CreateInstance( logListener: (message, logType) => Debug.Log($"[UnityExplorer] {message}"), unhollowedModulesPath: "C:/MyGame/Modules/" ); // Subscribe to log events after initialization ExplorerStandalone.OnLog += (message, logType) => { File.AppendAllText("explorer.log", $""[{logType}] {message}\n"); }; ``` -------------------------------- ### Access and Modify UnityExplorer Configuration Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Interact with UnityExplorer's settings programmatically using the Configuration API. This allows reading and writing configuration values such as keybinds, startup behavior, display settings, and blacklist configurations. It also supports subscribing to value change events for dynamic updates. ```csharp using UnityExplorer.Config; using UnityEngine; // Access configuration values KeyCode toggleKey = ConfigManager.Master_Toggle.Value; bool hideOnStartup = ConfigManager.Hide_On_Startup.Value; float startupDelay = ConfigManager.Startup_Delay_Time.Value; bool disableEventSystem = ConfigManager.Disable_EventSystem_Override.Value; int targetDisplay = ConfigManager.Target_Display.Value; bool forceUnlockMouse = ConfigManager.Force_Unlock_Mouse.Value; // Modify configuration values ConfigManager.Master_Toggle.Value = KeyCode.F8; ConfigManager.Hide_On_Startup.Value = true; ConfigManager.Startup_Delay_Time.Value = 2.0f; ConfigManager.Force_Unlock_Mouse.Value = false; // Subscribe to config changes ConfigManager.Master_Toggle.OnValueChanged += (KeyCode newKey) => { Debug.Log($"Toggle key changed to: {newKey}"); }; ConfigManager.Force_Unlock_Mouse.OnValueChanged += (bool value) => { Debug.Log($"Force unlock mouse: {value}"); }; // Access paths string defaultOutputPath = ConfigManager.Default_Output_Path.Value; string dnSpyPath = ConfigManager.DnSpy_Path.Value; // Mouse inspect keybinds KeyCode worldInspect = ConfigManager.World_MouseInspect_Keybind.Value; KeyCode uiInspect = ConfigManager.UI_MouseInspect_Keybind.Value; // Blacklists for console and reflection string assemblyBlacklist = ConfigManager.CSConsole_Assembly_Blacklist.Value; string signatureBlacklist = ConfigManager.Reflection_Signature_Blacklist.Value; ``` -------------------------------- ### C# Console API - Execute Runtime Code Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Allows executing C# code at runtime using a built-in REPL console powered by Mono.CSharp. You can evaluate expressions, define and use variables, add custom using directives, and reset the console. It also provides access to the scripts folder for startup scripts. ```csharp using UnityExplorer.CSConsole; // Evaluate simple expressions ConsoleController.Evaluate("Debug.Log(\"Hello from console!\");"); // Evaluate with return values (logged to console) ConsoleController.Evaluate("Time.timeScale"); ConsoleController.Evaluate("Camera.main.transform.position"); // Define and use variables (persist until reset) ConsoleController.Evaluate("var myValue = 42;"); ConsoleController.Evaluate("myValue * 2"); // Add custom using directives ConsoleController.AddUsing("System.Text.RegularExpressions"); ConsoleController.AddUsing("UnityEngine.SceneManagement"); // Reset the console (clears all variables and usings) ConsoleController.ResetConsole(); // Execute code silently (suppress log output) ConsoleController.Evaluate("var silent = true;", supressLog: true); // Access the scripts folder path for startup scripts string scriptsFolder = ConsoleController.ScriptsFolder; // Place a "startup.cs" file here to auto-execute on load ``` -------------------------------- ### Create Runtime Method Hooks with HarmonyX Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Utilize the Hook Manager API to create runtime method hooks using HarmonyX. This allows for debugging method calls by logging parameters, modifying behavior with Prefix/Postfix/Finalizer/Transpiler patches, and dynamically enabling/disabling hooks. Custom patch source code can be provided and compiled. ```csharp using UnityExplorer.Hooks; using System.Reflection; // Create a hook for a method MethodInfo targetMethod = typeof(PlayerController).GetMethod("TakeDamage"); HookInstance hook = new HookInstance(targetMethod); // The hook auto-generates a Postfix that logs all parameters // Toggle hook on/off hook.TogglePatch(); // Enable the hook hook.Patch(); // Disable the hook hook.Unpatch(); // Access hook state bool isEnabled = hook.Enabled; MethodInfo method = hook.TargetMethod; // Custom patch source code (edit via UI or set directly) string customPatch = @" static void Postfix(PlayerController __instance, float __0) { UnityExplorer.ExplorerCore.Log($"Player {__instance.name} took {__0} damage"); }"; hook.PatchSourceCode = customPatch; hook.CompileAndGenerateProcessor(customPatch); hook.Patch(); // Advanced: Define Prefix, Postfix, Finalizer, or Transpiler string advancedPatch = @" static bool Prefix(ref float __0) { // Modify damage before method runs __0 *= 0.5f; // Half damage return true; // Continue to original method } static void Postfix(PlayerController __instance, float __result) { UnityExplorer.ExplorerCore.Log($"Final result: {__result}"); }"; ``` -------------------------------- ### Hook Manager API Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Create runtime method hooks using HarmonyX for debugging method calls. This API allows you to patch methods, toggle hooks, and define custom Prefix, Postfix, Finalizer, or Transpiler logic. ```APIDOC ## Hook Manager API ### Description Create runtime method hooks using HarmonyX for debugging method calls. ### Methods - **Create Hook**: `HookInstance hook = new HookInstance(targetMethod);` - **Toggle Patch**: `hook.TogglePatch();` - **Enable Hook**: `hook.Patch();` - **Disable Hook**: `hook.Unpatch();` - **Access Hook State**: `hook.Enabled` (bool), `hook.TargetMethod` (MethodInfo) - **Set Custom Patch**: `hook.PatchSourceCode = customPatchString;` - **Compile and Generate**: `hook.CompileAndGenerateProcessor(customPatchString);` ### Example Usage ```csharp using UnityExplorer.Hooks; using System.Reflection; // Get the target method MethodInfo targetMethod = typeof(PlayerController).GetMethod("TakeDamage"); // Create a new hook instance HookInstance hook = new HookInstance(targetMethod); // Toggle the hook on/off hook.TogglePatch(); // Enable the hook hook.Patch(); // Disable the hook hook.Unpatch(); // Define custom patch logic string customPatch = @"static void Postfix(PlayerController __instance, float __0) { UnityExplorer.ExplorerCore.Log($"Player {__instance.name} took {__0} damage"); }"; hook.PatchSourceCode = customPatch; hook.CompileAndGenerateProcessor(customPatch); hook.Patch(); // Advanced patch definition (Prefix, Postfix, Finalizer, Transpiler) string advancedPatch = @"static bool Prefix(ref float __0) { __0 *= 0.5f; // Modify damage return true; // Continue execution } static void Postfix(PlayerController __instance, float __result) { UnityExplorer.ExplorerCore.Log($"Final result: {__result}"); }"; ``` ``` -------------------------------- ### Logging API for UnityExplorer Source: https://context7.com/sinai-dev/unityexplorer/llms.txt This snippet demonstrates how to log messages to UnityExplorer's built-in log panel using the ExplorerCore class. It covers standard logging, logging Unity debug messages, accessing explorer information like version and name, and subscribing to log events in standalone mode. ```csharp using UnityExplorer; // Standard logging ExplorerCore.Log("Information message"); ExplorerCore.LogWarning("Warning message"); ExplorerCore.LogError("Error message"); // Log Unity debug messages (if Log_Unity_Debug config is enabled) ExplorerCore.LogUnity("Unity debug message", LogType.Log); ExplorerCore.LogUnity("Unity warning", LogType.Warning); // Access explorer information string version = ExplorerCore.VERSION; // e.g., "4.9.0" string name = ExplorerCore.NAME; // "UnityExplorer" string author = ExplorerCore.AUTHOR; // "Sinai" string guid = ExplorerCore.GUID; // "com.sinai.unityexplorer" // Access explorer folder path string explorerFolder = ExplorerCore.ExplorerFolder; // In standalone mode, subscribe to log events ExplorerStandalone.OnLog += (string message, LogType logType) => { // Handle log output externally Console.WriteLine($"[{logType}] {message}"); }; ``` -------------------------------- ### Control UnityExplorer UI Panels and Visibility Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Programmatically manage the visibility and state of UnityExplorer's UI panels and the main menu. This API allows for direct control over which panels are displayed and whether the entire UI is visible. It also provides access to core UI elements like the root GameObject and Canvas. ```csharp using UnityExplorer.UI; // Show or hide the entire UnityExplorer menu UIManager.ShowMenu = true; UIManager.ShowMenu = false; // Toggle specific panels UIManager.TogglePanel(UIManager.Panels.Inspector); UIManager.TogglePanel(UIManager.Panels.CSConsole); UIManager.TogglePanel(UIManager.Panels.ObjectExplorer); // Set panel active state directly UIManager.SetPanelActive(UIManager.Panels.ConsoleLog, true); UIManager.SetPanelActive(UIManager.Panels.HookManager, false); UIManager.SetPanelActive(UIManager.Panels.Freecam, true); UIManager.SetPanelActive(UIManager.Panels.Clipboard, true); UIManager.SetPanelActive(UIManager.Panels.Options, true); // Get a panel reference UEPanel inspectorPanel = UIManager.GetPanel(UIManager.Panels.Inspector); CSConsolePanel consolePanel = UIManager.GetPanel(UIManager.Panels.CSConsole); // Access UI elements GameObject uiRoot = UIManager.UIRoot; Canvas uiCanvas = UIManager.UICanvas; // Set navbar anchor position UIManager.NavbarAnchor = UIManager.VerticalAnchor.Top; // Default UIManager.NavbarAnchor = UIManager.VerticalAnchor.Bottom; UIManager.SetNavBarAnchor(); ``` -------------------------------- ### Scene Handler API - Access and Traverse Scenes Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Provides methods to access and traverse all loaded scenes in Unity, including special scenes like DontDestroyOnLoad and HideAndDontSave. It allows retrieving the current scene, all loaded scenes, root GameObjects, and checking scene properties. It also supports subscribing to scene change events. ```csharp using UnityExplorer.ObjectExplorer; using UnityEngine; using UnityEngine.SceneManagement; // Get the currently selected/inspected scene Scene? currentScene = SceneHandler.SelectedScene; // Get all currently loaded scenes List loadedScenes = SceneHandler.LoadedScenes; foreach (Scene scene in loadedScenes) { Debug.Log($"Loaded scene: {scene.name} (handle: {scene.handle})"); } // Get root GameObjects in the currently inspected scene IEnumerable rootObjects = SceneHandler.CurrentRootObjects; foreach (GameObject go in rootObjects) { Debug.Log($"Root object: {go.name}"); } // Check if inspecting the HideAndDontSave asset scene bool isAssetScene = SceneHandler.InspectingAssetScene; // Check if DontDestroyOnLoad scene exists bool dontDestroyExists = SceneHandler.DontDestroyExists; // Get all scene names from build settings if (SceneHandler.WasAbleToGetScenesInBuild) { List allScenes = SceneHandler.AllSceneNames; foreach (string scenePath in allScenes) { Debug.Log($"Build scene: {scenePath}"); } } // Subscribe to scene change events SceneHandler.OnInspectedSceneChanged += (Scene newScene) => { Debug.Log($"Now inspecting scene: {newScene.name}"); }; SceneHandler.OnLoadedScenesUpdated += (List scenes) => { Debug.Log($"Loaded scenes updated. Count: {scenes.Count}"); }; ``` -------------------------------- ### Inspect Object and Type using InspectorManager Source: https://github.com/sinai-dev/unityexplorer/blob/master/README.md Demonstrates how to use the InspectorManager class to inspect a given object or a Type from outside the C# console. This is useful for debugging and understanding object structures within Unity. ```csharp UnityExplorer.InspectorManager.Inspect(theObject); UnityExplorer.InspectorManager.Inspect(typeof(SomeClass)); ``` -------------------------------- ### UI Manager API Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Control the UnityExplorer UI panels and visibility programmatically. This API allows you to show/hide the main menu, toggle specific panels, set their active state directly, and retrieve panel references. ```APIDOC ## UI Manager API ### Description Control the UnityExplorer UI panels and visibility programmatically. ### Methods - **Show/Hide Menu**: `UIManager.ShowMenu = true;` / `UIManager.ShowMenu = false;` - **Toggle Panel**: `UIManager.TogglePanel(UIManager.Panels.PanelName);` - **Set Panel Active State**: `UIManager.SetPanelActive(UIManager.Panels.PanelName, bool isActive);` - **Get Panel Reference**: `UIManager.GetPanel(UIManager.Panels.PanelName);` or `UIManager.GetPanel(UIManager.Panels.PanelName);` - **Access UI Root/Canvas**: `UIManager.UIRoot` (GameObject), `UIManager.UICanvas` (Canvas) - **Set Navbar Anchor**: `UIManager.NavbarAnchor = UIManager.VerticalAnchor.Top/Bottom;` followed by `UIManager.SetNavBarAnchor();` ### Available Panel Types - `UIManager.Panels.ObjectExplorer` - `UIManager.Panels.Inspector` - `UIManager.Panels.CSConsole` - `UIManager.Panels.Options` - `UIManager.Panels.ConsoleLog` - `UIManager.Panels.HookManager` - `UIManager.Panels.Clipboard` - `UIManager.Panels.Freecam` ``` -------------------------------- ### Clipboard API - Copy and Paste Objects Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Enables copying and pasting of objects between UnityExplorer inspectors and the C# console. You can copy various object types, retrieve current clipboard contents, attempt to paste with type checking, and clear the clipboard. ```csharp using UnityExplorer.UI.Panels; using UnityEngine; // Copy an object to clipboard GameObject player = GameObject.Find("Player"); ClipboardPanel.Copy(player); // Copy any type of object ClipboardPanel.Copy(new Vector3(1, 2, 3)); ClipboardPanel.Copy("Some string value"); ClipboardPanel.Copy(42); // Get the current clipboard contents object current = ClipboardPanel.Current; // Try to paste with type checking if (ClipboardPanel.TryPaste(typeof(GameObject), out object pastedObject)) { GameObject pastedGO = pastedObject as GameObject; Debug.Log($"Pasted: {pastedGO.name}"); } // Clear the clipboard ClipboardPanel.ClearClipboard(); // In C# Console REPL, use Copy() and Paste() helpers: // Copy(someObject); // var obj = Paste(); ``` -------------------------------- ### Inspect Objects using UnityExplorer Inspector API Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Allows runtime inspection of any object instance to view and modify its properties, fields, and methods. This includes GameObjects, components, collections, primitive types, and complex objects. It also provides access to the active inspector and functionality to close all inspector tabs, along with an event for inspector tab changes. ```csharp using UnityExplorer; using UnityEngine; // Inspect a GameObject GameObject player = GameObject.Find("Player"); InspectorManager.Inspect(player); // Inspect any component Rigidbody rb = player.GetComponent(); InspectorManager.Inspect(rb); // Inspect any object (structs, classes, collections, etc.) var inventory = new Dictionary { { "Sword", 1 }, { "Potion", 5 }, { "Gold", 100 } }; InspectorManager.Inspect(inventory); // Inspect strings, primitives, or complex objects InspectorManager.Inspect("Hello World"); InspectorManager.Inspect(new Vector3(1, 2, 3)); // Access the currently active inspector InspectorBase activeInspector = InspectorManager.ActiveInspector; object currentTarget = activeInspector?.Target; // Close all inspector tabs InspectorManager.CloseAllTabs(); // Listen for inspector tab changes InspectorManager.OnInspectedTabsChanged += () => { Debug.Log($"Inspector tabs changed. Count: {InspectorManager.Inspectors.Count}"); }; ``` -------------------------------- ### Inspect Types using UnityExplorer Inspector API Source: https://context7.com/sinai-dev/unityexplorer/llms.txt Enables runtime inspection of a Type to view its static members, methods, and nested types through reflection. This is useful for examining built-in Unity engine types as well as custom game-defined types, including generic types. ```csharp using UnityExplorer; using UnityEngine; // Inspect a Type to see static members InspectorManager.Inspect(typeof(Application)); // Inspect Unity engine types InspectorManager.Inspect(typeof(Physics)); InspectorManager.Inspect(typeof(Time)); InspectorManager.Inspect(typeof(Screen)); // Inspect custom game types InspectorManager.Inspect(typeof(GameManager)); // Inspect generic types InspectorManager.Inspect(typeof(List<>)); InspectorManager.Inspect(typeof(Dictionary<,>)); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.