Show a website in Unity

Hi how can i show a webpage in Unity maybe within a GUI

The WWW class provides functions for sending and receiving data from a web site, but it won’t help with the task of displaying one.

Take a look at the htmlTexture plugin. Some downsides are that it’s Mac-only, requires Unity Pro, and won’t work in a web player. If those restrictions aren’t a problem though then it might be what you’re looking for.

Hey thanks Matthew. Sorry to say that I am a windows users. But i am still thankful for the info.

you can get an image of a page I thought but I guess I was wrong. sorry

Isn’t there a standard renderer that the iPhone uses?

Hmm hope someone have a solution to my problem on showing webpage in Unity3D.

My idea is to load the google map window inside unity3D so user can zoom in and out of the map and search too.

1 Like

What about using WebKit? And pass the texture to Unity with browser communication?

1 Like

Unity does not contain a HTML renderer so you cannot, by default, show a web page inside your Unity-authored application. You can create a plugin (desktop and/or iPhone only) and use something like WebKit, but that won’t work for web-based applications. In fact, forum user bliprob has done that already (non-iPhone, Mac-only):

HtmlTexturePlugin

But again, that is a plugin and those are not supported in the web player.

1 Like

So far the only way I’ve seen browser page rendering to an image (other than the mac plugin) is by making your own browser:

webkit:

awesomium:
http://princeofcode.com/awesomium.php

boxee:

Although I’m not sure what it takes to make Unity work in your custom browser.

Btw thanks. I am quite interested in awesomium, it has exactly the function i need. But how exactly can i use it in Unity3D. This is the main thing i have in mind. THanks.

The trick is you can’t use these things inside Unity3d.

But you can pass images to Unity with Javascript.

So if you can get anything on the html page to render an image, you can display that image in your Unity application.

Hi,
well i know a solution that works.
Jaap Kreijkamp has publish a solution for Unity on his Webside
ShowWebpage:
http://ctrl-j.com.au/pages/jcarsrc.html
You need a Webserver with PHP. There you ran a PHP Script to grab a Screenshot from the Webpage you want voila you put then the return’ed jpg into a Texture via the Script.

here is my modified version
all credits goes to Jaap - thxx again for the idea and Solution :slight_smile:

using UnityEngine;
using System.Collections;

public class JLoadPage : MonoBehaviour {

	 // mainTexture of this material will be used to load page into
	public Material pageMaterial;
	
	// url to serverside script which returns the image url with the
	// page converted to image. The page to be converted should be
	// appended to converterURL as an EscapeURLed string.
	public string converterURL = "http://www.xxx/unitycallweb.php?url=";

	private bool loading = false;
	
	private Texture lastTexture = null;


	
	// loads the given page (url) into the mainTexture of the material defined by the
	// pageMaterial property of this object. The loading will be done as coroutine
	// in the background so the function returns immediately.
	public void LoadPageToMaterial(string url) {
		StartCoroutine(MyLoadPage(url));
	}
	
	// isLoading property returns true if page is still loading, otherwise returns
	// false
	public bool isLoading {
		get { return loading; }
	}
	
	// internal coroutine code that does the actual loading
	private IEnumerator MyLoadPage(string url) {
		WWW www = new WWW(converterURL + WWW.EscapeURL(url));
		while (![url]www.isDone[/url]) {
	        yield return www;
		}
		if ([url]www.error[/url] == null) {
			string str = [url]www.data;[/url]
			www.Dispose();
			www = new WWW(str);
			while (![url]www.isDone[/url]) {
	        	yield return www;
			}
			if ([url]www.error[/url] == null) {

				pageMaterial.mainTexture = [url]www.texture;[/url]
				www.Dispose();
				if (lastTexture != null) {
					DestroyImmediate(lastTexture);
				}
				lastTexture = pageMaterial.mainTexture;
			}
			else {
				Debug.Log("error getting img data '" + [url]www.error[/url] + "'");
				www.Dispose();
			}
		}
		else {
			Debug.Log("error getting img url '" + [url]www.error[/url] + "'");
			www.Dispose();
		}
		loading = false;
    }
	
	
	// code below is purely for testing purposes
	float nextUpdate = 0;

	// Update is called once per frame
	void Update() {
		if ((isLoading == false)  (Time.time > nextUpdate)) {
			LoadPageToMaterial("http://en.wikipedia.org/wiki/Special:Random");
			loading = true;			
			nextUpdate = Time.time + 15.0f;
			loading = false;
		}
	}
}

PHP code

<?php
		header('Content-type: text/plain');
		$url = $_GET["url"];
		$query = "http://ipinfo.info/netrenderer/?url=" . urlencode($url);
        $ch = curl_init($query);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);       
        curl_close($ch);
		if (ereg ("\"([url]http://renderer.geotek.de/image.php[/url][^\"]*)", $output, $regs)) {
		    echo "$regs[1]";
		} else {
		    echo "";
		}
?>

http://renderer.geotek.de/image.php is only for test use… for comercial use some other like http://www.thumbalizr.com/index.php
… was also a Suggestion from Jaap !°

ok hope it help’s :wink:

kerstin :sweat_smile:

1 Like

That is a novel approach. Excellent.

That looks interesting. I was thinking that perhaps Flash might have some functions for saving a webpage as an image, but it didn’t cross my mind that PHP could be used to do the job.

Thanks for all the info everyone. To what i can see this still loads only image into the Unity but i actually want to load a google map so i can actually scroll it or drag it within the GUI which means is in real time. I suppose it will be hard.

Anyway thanks again to all.

You can keep track of mouse events in unity and send the mouse state to the php page as url parameters.

Hi,

Can you please share what is the final solution you reached to and your approach for what you asked on the forum. Please share the Solution for maps inside unity3d.

Thanks

Has anyone else tried to use AwesomiumDotNet in Unity?

I’ve just tried it, importing the AwesomiumDotNet .dll, and the Awesomium .dlls, to the assets folder.

It can compile when I call it from a script, but when I run the game It crashes :S

(Filename: Assets/AwesomiumDotNetTest.cs Line: 10)

Stacktrace:

  at AwesomiumDotNetTest.Start () [0x00026] in D:\Users\enrodri86\Documents\Itara Online\Assets\AwesomiumDotNetTest.cs:12
  at AwesomiumDotNetTest.Start () [0x00020] in D:\Users\enrodri86\Documents\Itara Online\Assets\AwesomiumDotNetTest.cs:11
  at (wrapper runtime-invoke) AwesomiumDotNetTest.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
Receiving unhandled NULL exception
unity: Launch crash handler

The line is “WebCore wc = new WebCore();”

Any suggestions? Is it possible that it can’t work because I’m not using the Pro version?

Is it also worked for Android instead for IoS when exported and run?