### Standard UWB Package Installation Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/user/setup Example of a basic UWB package installation, including the core package and native Windows binaries for an engine. ```text com.voltstro.uwb.core com.voltstro.uwb.engine.windows ``` -------------------------------- ### Run UWB Setup Script Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/dev/setup Execute the main setup script for Unity Web Browser. This script handles initial project configuration. It may require `python3` on some systems and should only be run once. ```python python src/DevScripts/setup_all.py ``` -------------------------------- ### VoltUPR Registry Configuration Example Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/user/setup Example configuration for Unity's registry settings to include VoltUPR. Ensure the 'com.cysharp.unitask' scope is added if UniTask is not managed separately. ```text { "scopedRegistries": [ { "name": "VoltUPR", "url": "https://registry.voltstro.dev/", "scopes": [ "com.cysharp.unitask", "com.voltstro" ] } ] } ``` -------------------------------- ### Initialize and Update Git Submodules Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/dev/setup If the repository was not cloned recursively, use these commands to initialize and update all submodules. Run these in the root of the repository. ```bash git submodule init git submodule update ``` -------------------------------- ### Unity Version Prerequisite Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/user/setup Specifies the required Unity version for UWB. Newer versions may work but are untested. ```text Unity 2021.3.x ``` -------------------------------- ### Loading a Website with WebBrowserClient Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/user/usage This C# script demonstrates how to load a specific URL using the WebBrowserClient. Ensure you have a reference to a BaseUwbClientManager component, which provides access to the WebBrowserClient. This snippet is useful for programmatically navigating to web pages within your Unity application. ```csharp using UnityEngine; using VoltstroStudios.UnityWebBrowser; using VoltstroStudios.UnityWebBrowser.Core; public class ExampleLoadingSite : MonoBehaviour { //You need a reference to UWB's WebBrowserClient, which is an object kept on BaseUwbClientManager //All of UWB's higher level components (such as WebBrowserUIBasic or WebBrowserUIFull) inherit from BaseUwbClientManager //so we can use that as the data type [SerializeField] //SerializeField allows us to set this in the editor private BaseUwbClientManager clientManager; private WebBrowserClient webBrowserClient; private void Start() { //You could also use Unity's GetComponent() method if this script exists on the same object. //Makes life easier having a local reference to WebBrowserClient webBrowserClient = clientManager.browserClient; } //Call this from were ever, and it will load 'https://voltstro.dev' public void LoadMySite() { webBrowserClient.LoadUrl("https://voltstro.dev"); } } ``` -------------------------------- ### Clone UWB Repository Recursively Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/dev/setup Clone the Unity Web Browser repository including all submodules. This is the primary method for obtaining the project code. ```bash git clone --recursive https://github.com/Voltstro-Studios/UnityWebBrowser.git ``` -------------------------------- ### Subscribe to OnClientInitialized Event Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/user/events Subscribe to the OnClientInitialized event to execute code after the WebBrowserClient has been constructed. This event does not guarantee engine readiness. ```csharp public class UWBPrjDemo : MonoBehaviour { [SerializeField] private WebBrowserUIBasic uiBasic; public void Start() { uiBasic.browserClient.OnClientInitialized += OnClientInitialized; } private void OnClientInitialized() { Debug.Log("BrowserClient initialized..."); } } ``` -------------------------------- ### Execute JavaScript from Unity Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/user/javascript Use the ExecuteJs method to run JavaScript code in the browser. Pass the complete JavaScript code as a string argument. ```csharp browserClient.ExecuteJs("console.log('Hello World');"); ``` -------------------------------- ### UWB Monorepo Directory Structure Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/dev/project-layout This is the basic layout of the UWB monorepo, showing the top-level directories and key subfolders within 'src/'. ```text docs/ media/ src/ - DevScripts/ - DevTools/ - Docs/ - Imports/ - Packages/ - UnityWebBrowser/ - *Other UPM packages*/ - ThirdParty/ - UnityWebBrowser.Pages/ - UnityWebBrowser.Engine.* - UnityWebBrowser.UnityProject/ - VoltstroStudios.* - *Misc Stuff* ``` -------------------------------- ### Registering JS Methods in Unity Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/user/javascript Register .NET methods to be callable from JavaScript using RegisterJsMethod. Overloads support various argument types, including primitive types, DateTime, and custom objects. Ensure registered methods return void. ```csharp public class UWBPrjDemo : MonoBehaviour { [SerializeField] private WebBrowserUIBasic uiBasic; public void Start() { uiBasic.browserClient.RegisterJsMethod("Test", TestMethod); uiBasic.browserClient.RegisterJsMethod("TestInt", TestMethodInt); uiBasic.browserClient.RegisterJsMethod("TestString", TestMethodString); uiBasic.browserClient.RegisterJsMethod("TestDate", TestMethodDate); uiBasic.browserClient.RegisterJsMethod("TestObject", TestMethodObject); uiBasic.browserClient.RegisterJsMethod("TestObjectChild", TestMethodObjectChild); } private void TestMethod() { Debug.Log("Hello from test method!"); } private void TestMethodInt(int value) { Debug.Log($"Hello from test method! Value was {value}."); } private void TestMethodString(string value) { Debug.Log($"Hello from test method! Value was {value}."); } private void TestMethodDate(DateTime value) { DateTime localTime = value.ToLocalTime(); Debug.Log($"Hello from test method! Value in UTC time was {value:yyyy-MM-dd HH:mm:ss zzzz}. Value in local time was {localTime:yyyy-MM-dd HH:mm:ss zzzz}."); } private void TestMethodObject(TestClass? test) { Debug.Log($"Hello from test method! Value on TestClass was {test?.Test}."); } private void TestMethodObjectChild(TestClassChild? test) { Debug.Log($"Hello from test method! Value on TestClassChild was {test?.What}, TestClass was {test?.Test?.Test}."); } } ``` -------------------------------- ### Calling .NET Methods from JavaScript Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/user/javascript Invoke registered .NET methods from JavaScript using uwb.ExecuteJsMethod. Pass the method name as the first argument, followed by any arguments required by the .NET method. Supported types include numbers, strings, Dates, and objects. ```javascript uwb.ExecuteJsMethod('Test'); uwb.ExecuteJsMethod('TestInt', 6969); uwb.ExecuteJsMethod('TestString', 'Hello World!'); uwb.ExecuteJsMethod('TestDate', new Date()); uwb.ExecuteJsMethod('TestObject', {Test: 'Hello World!'}); uwb.ExecuteJsMethod('TestObjectChild', {Test: {Test: 'Hello World!'}, What: 'Voltstro Woz Here'}); ``` -------------------------------- ### JavaScript Object for .NET Conversion Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/user/javascript Define JavaScript objects with nested structures that can be automatically converted to .NET objects. Ensure C# classes use properties, not fields, and handle potential null values. ```javascript { Test: 'Test', Child: { Number: 1234, Test: 'Hello World!' } } ``` -------------------------------- ### C# Class Representation for JS Objects Source: https://projects.voltstro.dev/UnityWebBrowser/latest/articles/user/javascript Define C# classes with properties that match the structure of JavaScript objects passed as arguments. Properties are required for successful deserialization. ```csharp public class ChildClass { public int Number { get; set; } public string Test { get; set; } } public class ObjectClass { public string Test { get; set; } public ChildClass Child { get; set; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.