Unity3D Integration Tutorial – Part 1

Introduction:

This a quick introductory tutorial to using Awesomium with Unity3D.

We’ll walk you through the basics and demonstrate how to display a simple web-page in your 3D scene.

Web-Page Displayed in Unity3D using Awesomium

Checklist

Before we start, you will need the following things:

 

Adding Awesomium to Unity3D on Windows:

We will first need to install the Awesomium SDK and then copy over some files so our scripts will run within the Unity3D editor:

  1. Install the Awesomium SDK using the default settings (should create a new folder on your Desktop)
  2. Open the awesomium_v1.6.x_sdk_win folder and navigate to build\bin\release.
  3. Copy everything from the release folder  to C:\Program Files\Unity\Editor (or for 64-bit Windows, copy it to C:\Program Files (x86)\Unity\Editor)

Now the Unity Editor has access to Awesomium, allowing you to use it while you debug scenes.

Adding Awesomium to Unity3D on Mac:

We will first need to install the Awesomium SDK and then copy over some files so our scripts will run within the Unity3D editor:

  1. Install and mount the Awesomium SDK
  2. Open up the mounted SDK folder and navigate to build/bin/release
  3. Copy Awesomium.framework to /Applications/Unity/Unity.app/Contents/Frameworks (you’ll need to right-click Unity -> Show Package Contents)

Now the Unity Editor has access to Awesomium, allowing you to use it while you debug scenes.

Setting Up Your Unity3D Project:

Now it’s time to setup a new Unity3D project, add our plane object and directional light object.

  1. Create a new folder on your Desktop and name it UnityAweDemo
  2. Open Unity3D, go to File -> New Project -> Browse -> select the UnityAweDemo folder -> Create
  3. Create a plane object by clicking GameObject -> Create Other -> Plane
  4. Edit the plane’s properties in the Inspector pane (see screenshot below)

The plane's Inspector properties

We now need to create a light source for our scene.

  1. Click GameObject -> Create Other -> Directional Light
  2. Edit the directional light’s properties in the Inspector pane (see screenshot below)

The directional light's Inspector properties

 

Adding Our Scripts:

Last, we’ll need to add AwesomiumMono.dll and the C# scripts included in the UnityAwe wrapper to our Unity3D project.

  1. Download UnityAwe from https://github.com/khrona/UnityAwe/zipball/master
  2. Unzip the UnityAwe archive.
  3. Open it up and find the correct AwesomiumMono.dll for your platform (we have two separate builds for Windows and Mac).
  4. Click and drag AwesomiumMono.dll to the Project pane in the Unity Editor.
  5. Click and drag WebTexture.cs and WebCoreHelper.cs to the Project pane in the Unity3D editor.

Sweet, now your project is all set-up to use Awesomium! To actually make our plane display a web-page we just need to do two final steps:

  1. Click and drag the WebTexture.cs script from the Project pane onto the Plane game object in the Hierarchy pane.
  2. You should now see a Web Texture (Script) section in the Inspector pane, feel free to modify any of the default fields (such as Initial URL).

Awesome, you’re done!

Press the Play button and you should see a your Plane displaying a web-page. You should be able to interact with it like normal (mouse clicks, keyboard, etc.).

An Interactive webpage inside the Unity Editor

Deploying your Application

When you build your scene for the standalone player, you’ll need to copy over the Awesomium SDK files to your application (just like how you copied them to the Unity Editor path).

Known Issues

Awesomium doesn’t like to be initialized more than once per-process, so some web-pages will not display twice in a row inside the Editor (eg, pushing play, stop, play, stop).

Extra Tips and Tricks:

  • You can click and drag WebTexture.cs to almost any Game Object to make it display a web-page as its texture.
  • When adding it to a GUI Element make sure to make the Width and Height (see the Pixel Inset) matches the values defined in your Web Texture (Script).
  • When adding it to any other object (like a Cylinder or Sphere), make sure that it uses a Mesh Collider so that mouse input works correctly.

We will be continuing this tutorial in Part 2 with a more advanced example (scripting and HTML GUI goodness).

If you need any help, drop us a line in our support forum: http://support.awesomium.com

Also read...

Comments

  1. Really nice! Would like to see how far this plugin could push unity’s web browsing capabilities such as embedding mini flash games within a unity game?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>