Skip to main content

Virtual Domain

This system allows you to set a virtual domain name through code and specify a local directory. When accessing this domain name internally in UWebView2, it will be redirected to a local website. This is very useful for offline deployment, such as with Vue, allowing you to access your website without uploading it to a web server.

tip

This feature is very useful. Highly recommended!!!

1. Create your Unity Script

This will load the HTML file from G:\My\EDGE\WWW\uwebview\build\index.html.

Create Virtual Domain
public class TestScript : MonoBehaviour
{
public EdgeCanvas m_edgeCanvas;

private async void Awake()
{
await m_edgeCanvas.WaitInitialize();

m_edgeCanvas.SetVirtualHostNameMapping(
"hello.com",
@"G:\My\EDGE\WWW\uwebview\build",
WebviewHostResourceAccessKind.Allow
);

m_edgeCanvas.LoadUrl("https://hello.com/index.html");
}
}

virtual1

Unity StreamingAssetsPath

Create Virtual Domain
public class TestScript : MonoBehaviour
{
public EdgeCanvas m_edgeCanvas;

private async void Awake()
{
await m_edgeCanvas.WaitInitialize();

m_edgeCanvas.SetVirtualHostNameMapping(
"hello.com",
$"{System.IO.Path.Combine(Application.streamingAssetsPath,"www")}",
WebviewHostResourceAccessKind.Allow);

m_edgeCanvas.LoadUrl("https://hello.com/index.html");
}
}
This will load the HTML file from "Application.streamingAssetsPath/www/index.html".