/AwesomiumUnity

Third-party Awesomium wrapper for Unity3D, wrapping Awesomium's C++ API with a custom C# API and accompanying Unity MonoBehaviour components.

Primary LanguageC#

AwesomiumUnity

AwesomiumUnity is a third-party Awesomium wrapper intended for use with Unity3D.

AwesomiumUnity allows you to display and use HTML documents in your Unity3D application. HTML5, CSS, and JavaScript are supported, and rendered views can be displayed anywhere a regular Unity Texture2D can be used. Possibilities for your application include:

  • Fully interactive live browsing of the internet, in-game.
  • Rich, complex 2D or 3D UI's created using HTML, CSS, and JavaScript.
  • Quick iteration times and result. Just edit your HTML, CSS, or JavaScript and reload!
  • Fully functional in the Unity Editor. Don't restrict yourself to just a standalone game!

The wrapper consist of a custom native code C++ DLL which simply wraps Awesomium's C++ API (requires Unity Pro to use) and a set of C# scripts that interface with this DLL.

The current state of the project is:

Stable, the majority of important features implemented. Other functionality in development, code structure and architecture not completely final.

Projects using AwesomiumUnity

Besides individual users, AwesomiumUnity is also used by some game developers or other companies to integrate the power of HTML5 and web browsing in their application.

The developers of TableTop Simulator by Berserk Games are using AwesomiumUnity in their game for an in-game tablet in the 3D game world, which users can interact with and use to browse the web.

Folders

CppDLL

This folder contains a MSVC solution for the C++ DLL that wraps the Awesomium C++ API. To compile this solution you need to:

  • Have the Awesomium SDK installed. If you install it somewhere other than C:\Program Files (x86)\Awesomium Technologies LLC\Awesomium SDK\1.7.5.0, you will have to change the project's include directory (currently set to C:\Program Files (x86)\Awesomium Technologies LLC\Awesomium SDK\1.7.5.0\include) and the library directory (currently set to C:\Program Files (x86)\Awesomium Technologies LLC\Awesomium SDK\1.7.5.0\build\lib).
  • Have OpenGL installed (The project links with 'opengl32.lib').
  • Have the DirectX SDK installed and "DXSDK_DIR" as an environment variable (the project's include directories currently have $(DXSDK_DIR)\include set).

If succesfully built, the output will be located at either:

  • CppDLL\bin\Debug\AwesomiumUnity.dll

or

  • CppDLL\bin\Release\AwesomiumUnity.dll

AwesomiumUnityScripts

This folder contains the Unity scripts that interact with the native code (C++) DLL and the scripts that are actually attached to components in order to get webpages to render.

The files serve the following purposes:

  • AwesomiumUnityScripts\AwesomiumUnityError.cs :
    • Provides a binary-compatible structure to represent Awesomium errors.
  • AwesomiumUnityScripts\AwesomiumUnityVirtualKey.cs :
    • Provides a binary-compatible structure to represent Awesomium virtual keys.
  • AwesomiumUnityScripts\AwesomiumUnityWebCore.cs :
    • Provides a class with static functions that interface with the C++ DLL. This class is used for talking to the Awesomium::WebCore C++ class. Initialization and shutdown of the WebCore is handled automatically when needed.
  • AwesomiumUnityScripts\AwesomiumUnityWebCoreHelper.cs :
    • Contains a class that derives from MonoBehaviour which is created automatically and updates the WebCore each frame.
  • AwesomiumUnityScripts\AwesomiumUnityWebKeyboardEvent :
    • Provides a binary-compatible structure to represent Awesomium's _WebKeyboardEvent_s.
  • AwesomiumUnityScripts\AwesomiumUnityWebKeyModifiers :
    • Provides a binary-compatible structure to represent Awesomium's WebKeyModifiers.
  • AwesomiumUnityScripts\AwesomiumUnityWebKeyType :
    • Provides a binary-compatible structure to represent Awesomium's WebKeyType.
  • AwesomiumUnityScripts\AwesomiumUnityWebView :
    • Provides a class that interfaces with the C++ DLL. This class is used for talking to instances of the Awesomium::WebView C++ class.
  • AwesomiumUnityScripts\AwesomiumUnityWebTexture :
    • Contains the main class you need to use to render webpages. The class derives from MonoBehaviour and should be attached to a GameObject. A single instance of this class represent a single webpage. Input, interactiveness, etc. are all handled by this class. Note that this class acts as a wrapper to a WebView and can serve as an example of how you could implement such logic yourself. The WebTexture utilizes the WebView's API to control the view.
  • AwesomiumUnityScripts\AwesomiumUnityWebSession.cs :
    • Provides an interface and data to customize certain settings that influence the session. Settings include things as switching on or off web audio, WebGL, HTML5 local storage, JavaScript, plugins (such as Flash), but also whether the session cache should be stored in memory or on disk, and in what exact location.

AwesomiumUnityScripts\Examples

This folder contains simple examples to get you going. In most cases you can simply add one of these example scripts to a GameObject that has been set up to render webpages to see it working.

If an example is accompanied by a folder with the same name as the example script, it means that there is some HTML/CSS/JavaScript code that goes with it. These are generally loaded directly off of GitHub from within the example script.

Using AwesomiumUnity

Getting it to work in the Unity Editor

Note: Due to limitations of Awesomium, AwesomiumUnity requires a 32-bit Unity editor. The 32-bit Unity editor can be selected and downloaded through a dropdown list on the Unity download page.

  • Do one of the following two options:
      1. Copy the pre-built AwesomiumUnity.dll file from either CppDLL\bin\Debug or CppDLL\bin\Release to your Unity project's Assets\Plugins folder. OR
      1. Build the MSVC project and copy the resulting .DLL file (AwesomiumUnity.dll) to your Unity project's Assets\Plugins folder.
  • Copy the following files from your Awesomium SDK installation directory's build\bin folder to your Unity installation directory's Editor folder (NOT your project Assets\Editor folder!).
    • awesomium_process.exe
    • awesomium.dll
    • icudt.dll
    • libEGL.dll
    • libGLESv2.dll
    • xinput9_1_0.dll
    • avcodec-53.dll
    • avformat-53.dll
    • avutil-51.dll
  • Copy the folder AwesomiumUnityScripts to your Unity project's Assets folder (or any subdirectory within it).
  • Open your Unity project
  • Create a GameObject
  • Add either a GUITexture component or a Renderer component with a material and a MeshCollider component to your GameObject
  • Add the AwesomiumUnityWebTexture component to your GameObject
  • Hit play

Getting it to work for a standalone .exe

Note: Due to limitations of Awesomium, AwesomiumUnity requires a 32-bit application (built with a 32-bit editor). The 32-bit Unity editor can be selected and downloaded through a dropdown list on the Unity download page.

  • Do one of the following two options:
      1. Copy the pre-built AwesomiumUnity.dll file from either CppDLL\bin\Debug or CppDLL\bin\Release to the same folder as your executable. OR
      1. Build the MSVC project and copy the resulting .DLL file (AwesomiumUnity.dll) to the same folder as your executable.
  • Copy the following files from your Awesomium SDK installation directory's build\bin folder to the same folder as your executable.
    • awesomium_process.exe
    • awesomium.dll
    • icudt.dll
    • libEGL.dll
    • libGLESv2.dll
    • xinput9_1_0.dll
    • avcodec-53.dll
    • avformat-53.dll
    • avutil-51.dll
  • Copy the folder AwesomiumUnityScripts to your Unity project's Assets folder (or any subdirectory within it).
  • Open your Unity project
  • Create a GameObject
  • Add either a GUITexture component or a Renderer component with a material and a MeshCollider component to your GameObject
  • Add the AwesomiumUnityWebTexture component to your GameObject
  • Build an executable (NOTE: You'll probably have to have AwesomiumUnity.dll in your Assets\Plugins folder as well before the build process will succeed).

External Links