Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Voltstro committed Feb 15, 2024
1 parent d55f8a1 commit 1758da8
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 28 deletions.
8 changes: 7 additions & 1 deletion docs/articles/FAQ.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# FAQ

Here are some common questions we get. As time goes on, and we get asked more common question, we will add them here.
Here are some common questions we get. As time goes on, and we get asked more common questions, we will add them here.

---

Expand All @@ -19,3 +19,9 @@ Here are some common questions we get. As time goes on, and we get asked more co
**Q**: Does UWB support proprietary codecs?

**A**: The build of CEF that UWB uses DOES NOT come with proprietary codecs by default. You can however build CEF yourself with proprietary codecs included. Also have fun doing that. (Support will not be given to those who use a custom build of CEF!)

---

**Q**: Does UWB support mobile or WebGl?

**A**: UWB does not support any other platform that is not a desktop platform (Windows, Linux).
33 changes: 22 additions & 11 deletions docs/articles/dev/How-Things-Work.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
# How Things Work?

So, lets talk about how UWB works.
So, lets talk about how UWB works internally.

UWB is split into 3 sections:

- Core (Unity side)
- Shared (Glues the two sections together)
- Engine (Externally ran process)

All three sections are written in C#. As the engines are standalone applications, they use .NET 6, while the Unity side, is well... Unity.
## The Three Sections

## Core
### Core

The core is responsible for anything Unity related (such as handling getting Input or rendering to a <xref:UnityEngine.Texture>). It is provided as [standard custom UPM package](https://docs.unity3d.com/Manual/CustomPackages.html).
The core is responsible for anything Unity related (such as handling getting Input, or rendering to a <xref:UnityEngine.Texture>). It is provided as [standard custom UPM package](https://docs.unity3d.com/Manual/CustomPackages.html).

## Engine
### Shared

The engine is an external process that is responsible for taking the abstraction layer, and converting the calls to the calls that a web engine expects. This means that all that the core cares about is that the engine has support for the abstraction layer provided.
The shared library provides the abstraction layer that is used by the two sides.

Modern web engines are quite large (in binary size), and these binaries often have to be shipped with the engine them-selves, making them quite large as well.
There is also a shared library for engines, which provides some shared functions that only engines need.

## Shared
### Engine

The shared library provides the abstraction layer that is used by the two sides.
The engine is an external process that the core starts up. The engine is what runs the actual web browser, and it is responsible for externally managing it outside of Unity.

There is also a shared library for engines, which provides some shared functions that only engines need.
Since the engine is an external process, it has it own set of application files. This application files get packaged into Unity packages that can also be installed via UPM.

## Communication

Ok, so we got the external engine process, and the core (Unity) process. We also have shared abstraction layer between the two. But how do these things talk to each other. Two different processes can't talk to each other, right?
Ok, so we got the external engine process, and the core (Unity) process. We also have shared abstraction layer between the two. But how do these things talk to each other.

Communication is done via [RPC](https://en.wikipedia.org/wiki/Remote_procedure_call)s. We mainly uses RPCs instead of just directly writing data to a IPC pipe because using RPCs make programming and maintaining **a lot** easier. Under the hood, we use our own RPC library called [VoltRpc](https://github.com/Voltstro-Studios/VoltRpc).

## Why not just run the web browser inside of Unity?

Well technically you *could*, but there are two major issues:

1. Modern web browsers run multiple processes them selves, with each process dedicated a task. They often launch these process from their own original application file. In the Unity editor that is essentially impossible, and with the Unity player it would mean having the overhead of Unity for every single sub-process.
2. Most web browser are programmed with running one instance of them selves once, and if the browser needs to shutdown, then it probably means the user has requested to close the app. So the programmers making web browser under that assumption don't cleanup after native resources very well, since the OS will. With Unity, this a major issue. The Unity editor when changing play modes doesn't open and close, plus with Unity, the scene typically changes. This *probably* also wouldn't be an issue if [Unity could unload native binaries](https://docs.unity3d.com/Manual/PluginInspector.html).

An example of this would be a project called [cef-unity-sample](https://github.com/aleab/cef-unity-sample). It runs CEF directly inside of Unity. It avoids the first point by running CEF in "Single Process mode", which is a now removed feature of CEF that allowed running CEF in a single process. But the second issue it suffers from, resulting in Unity crashing when reloading the scene in anyway.

By running the web browser in a separate process, you avoid both issues. Yes it means having an entire second app ship with your Unity project, but you are already trying to run a web browser inside of Unity, so clearly resources are not your biggest concern.
40 changes: 32 additions & 8 deletions docs/articles/dev/Project-Layout.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Project Layout

Lets explain the layout of the project.
Lets explain the layout of the project. UWB is one big mono-repo. Everything you need (other then tools) are contained within the repo. Yes, it means it is a large repo, but it so much easier to develop for.

## Repo Layout

This is the basic layout of repo:

Expand All @@ -23,16 +25,38 @@ src/
- *Misc Stuff*
```

`docs/`, `media/` and `src/` are all fairly explanatory.

`DevScripts/` and `DevTools/` provide developer scripts and other external applications that are needed.
- `docs/`, `media/` and `src/` are all fairly explanatory.

`Docs/` provide a way of building the UWB package as a dll, so docfx can use it.
- `DevScripts/` and `DevTools/` provide developer scripts and other external applications that are needed.

`Imports/` contains shared `.targets` and `.props` files.
- `Imports/` contains shared `.targets` and `.props` files that are used by the .NET projects.

`Packages/` contains the UPM packages.
- `Packages/` contains the UPM packages. The provided Unity project has all packages added locally.

`ThirdParty/` contains stuff that ain't ours.
- `ThirdParty/` contains stuff that ain't ours, and cannot be included by a package management system.

The rest of the folders contain dotnet projects, with their respected code.

## Projects

Quick description of all the individual projects.

### UnityWebBrowser.UnityProject

This is the provided Unity project that can be used for UWB development. It has all of UWB's packages included locally.

### UnityWebBrowser.Pages

NodeJs/Yarn project that used to build out HTML that engines use for internal pages.

### VoltstroStudios.UnityWebBrowser.Shared

.NET project that contains shared code that used by both Engines and Core.

### VoltstroStudios.UnityWebBrowser.Engine.Shared

.NET project that contains shared code that is used by Engines.

### UnityWebBrowser.Engine.Cef

UWB's CEF Engine. .NET project that is built out as an application. In publish mode it will build anything .NET into a single file.
12 changes: 10 additions & 2 deletions docs/articles/dev/Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ These prerequisites are **mandatory** to compile UWB.

```
Unity 2021.3.x
.NET 6 SDK
.NET 8 SDK
PowerShell (formally PowerShell Core)*
Git
```
Expand Down Expand Up @@ -56,7 +56,7 @@ Once in PowerShell, go to the `src/` directory, and run the `setup-all.ps1` scri
./setup-all.ps1
```

Depending on your system, and your download speeds, this script could take upto a minute or longer. You only need to run this once.
Depending on your system, and your download speeds, this script could take upto a minute or even longer. You only need to run the setup script once.

You can now open up the `src/UnityWebBrowser.UnityProject` project with Unity.

Expand All @@ -78,6 +78,14 @@ If you need to, extra controls can be added by modifying the `Assets/Scripts/UWB

(In the future we hope to develop more editor tools to make life easier.)

## Core/Unity Packages Dev Work

Simple open C# project in Unity with your preferred IDE. You should be able to edit the UWB's packages from the same solution that Unity generates. Remember that Unity packages are contained in `src/Packages/`.

## Engine/Shared Project Dev Work

You can open `src/UnityWebBrowser.sln` with your preferred IDE. The rest of the external projects are contained within this solution, including the shared project and engine projects.

## Dev Scripts

There a many dev scripts in the `src/DevScripts` directory. The main ones that you will most likely use are:
Expand Down
4 changes: 4 additions & 0 deletions docs/articles/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ Here are our socials, please don't use these for support!
[![Twitter Follow](https://img.shields.io/twitter/follow/Voltstro?style=social)](https://twitter.com/Voltstro)

[![Twitter Follow](https://img.shields.io/twitter/follow/VoltstroStudios?style=social)](https://twitter.com/VoltstroStudios)

## Legal Disclaimer

These materials are not sponsored by or affiliated with Unity Technologies or its affiliates. “Unity” is a trademark or registered trademark of Unity Technologies or its affiliates in the U.S. and elsewhere.
20 changes: 14 additions & 6 deletions docs/articles/user/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ Alright, lets get to actually using UWB.
UWB aims to support all desktop platforms (Windows, Linux, MacOS). The core currently does support all desktop platforms, however you will have to factor in what engine you want to use. Each engine has their own different platform support. See the [engine page](Engines.md) for each engine's platform support.

> [!WARNING]
> UWB does **NOT** support [IL2CPP](https://docs.unity3d.com/Manual/IL2CPP.html)!
> UWB does **NOT** support [IL2CPP](https://docs.unity3d.com/Manual/IL2CPP.html). This is because UWB requires launching a separate process, which uses System.Diagnostics.Process API that [IL2CPP doesn't support](https://docs.unity3d.com/2021.3/Documentation/Manual/ScriptingRestrictions.html).
>
> UWB does however support being code trimmed.
## Components

By default, UWB provides two different components for handling web viewing from a <xref:UnityEngine.UI.RawImage>:
By default, UWB provides two different components for handling web viewing from a [Raw Image](https://docs.unity3d.com/2021.3/Documentation/Manual/script-RawImage.html):

- <xref:VoltstroStudios.UnityWebBrowser.WebBrowserUIBasic>
- <xref:VoltstroStudios.UnityWebBrowser.WebBrowserUIFull>

While both of these components are fundamentally the same (they both inherit from <xref:VoltstroStudios.UnityWebBrowser.Core.BaseUwbClientManager>), the <xref:VoltstroStudios.UnityWebBrowser.WebBrowserUIFull> has an additional <xref:VoltstroStudios.UnityWebBrowser.Core.FullscreenHandler> for users who want fullscreen controls.

A <xref:VoltstroStudios.UnityWebBrowser.WebBrowserUIControls> components is also provided, to wrap around some methods provided in <xref:VoltstroStudios.UnityWebBrowser.Core.WebBrowserClient> and expose them to Unity's UI system.
A <xref:VoltstroStudios.UnityWebBrowser.WebBrowserUIControls> component is also provided, to wrap around some methods provided in <xref:VoltstroStudios.UnityWebBrowser.Core.WebBrowserClient> and expose them to Unity's UI system.

## Options

Expand All @@ -32,23 +32,31 @@ A lot options are exposed in the editor.

The options are all very self-explanatory. If you need more info about one, hover over it for it's tooltip. Some options are explained in more details further along in the docs.

For calling methods on the engine (such as going back/forward/refresh, loading HTML, executing JS, etc...) are provided by the <xref:VoltstroStudios.UnityWebBrowser.Core.WebBrowserClient> (see the API docs for a full reference). Any component that inherits from <xref:VoltstroStudios.UnityWebBrowser.Core.BaseUwbClientManager> will have the <xref:VoltstroStudios.UnityWebBrowser.Core.WebBrowserClient> exposed via <xref:VoltstroStudios.UnityWebBrowser.Core.BaseUwbClientManager.browserClient> field.
## API

For calling methods on the engine (such as going back/forward/refresh, loading HTML, executing JS, etc...) are provided by the <xref:VoltstroStudios.UnityWebBrowser.Core.WebBrowserClient> (see the API docs for a full reference). The <xref:VoltstroStudios.UnityWebBrowser.Core.WebBrowserClient> lives as a property on <xref:VoltstroStudios.UnityWebBrowser.Core.BaseUwbClientManager>. Any component that inherits from <xref:VoltstroStudios.UnityWebBrowser.Core.BaseUwbClientManager> (such as <xref:VoltstroStudios.UnityWebBrowser.WebBrowserUIFull>) will have the <xref:VoltstroStudios.UnityWebBrowser.Core.WebBrowserClient> exposed via <xref:VoltstroStudios.UnityWebBrowser.Core.BaseUwbClientManager.browserClient> property.

Some example code of loading a website from a method would look like:

```csharp
using UnityEngine;
using VoltstroStudios.UnityWebBrowser;
using VoltstroStudios.UnityWebBrowser.Core;

public class ExampleLoadingSite : MonoBehaviour
{
//SerializeField exposes the control in Unity
[SerializeField] private BaseUwbClientManager clientManager;
//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<BaseUwbClientManager>() method if this script exists on the same object.
//Makes life easier having a local reference to WebBrowserClient
webBrowserClient = clientManager.browserClient;
}
Expand Down

0 comments on commit 1758da8

Please sign in to comment.