Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Show a website in Unity

Discussion in 'Scripting' started by projectD, Sep 20, 2009.

Thread Status:
Not open for further replies.
  1. projectD

    projectD

    Joined:
    Sep 2, 2009
    Posts:
    25
    Hi how can i show a webpage in Unity maybe within a GUI
     
  2. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
  3. matthewminer

    matthewminer

    Joined:
    Aug 29, 2005
    Posts:
    331
    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.
     
  4. projectD

    projectD

    Joined:
    Sep 2, 2009
    Posts:
    25
    Hey thanks Matthew. Sorry to say that I am a windows users. But i am still thankful for the info.
     
  5. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    you can get an image of a page I thought but I guess I was wrong. sorry
     
  6. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Isn't there a standard renderer that the iPhone uses?
     
  7. projectD

    projectD

    Joined:
    Sep 2, 2009
    Posts:
    25
    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.
     
    Ive likes this.
  8. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    What about using WebKit? And pass the texture to Unity with browser communication?

    http://webkit.org/
     
    David_29 likes this.
  9. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    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.
     
    Prakul2006 likes this.
  10. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
  11. projectD

    projectD

    Joined:
    Sep 2, 2009
    Posts:
    25
    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.
     
  12. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    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.
     
  13. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    470
    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 :)

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class JLoadPage : MonoBehaviour {
    5.  
    6.      // mainTexture of this material will be used to load page into
    7.     public Material pageMaterial;
    8.    
    9.     // url to serverside script which returns the image url with the
    10.     // page converted to image. The page to be converted should be
    11.     // appended to converterURL as an EscapeURLed string.
    12.     public string converterURL = "http://www.xxx/unitycallweb.php?url=";
    13.  
    14.     private bool loading = false;
    15.    
    16.     private Texture lastTexture = null;
    17.  
    18.  
    19.    
    20.     // loads the given page (url) into the mainTexture of the material defined by the
    21.     // pageMaterial property of this object. The loading will be done as coroutine
    22.     // in the background so the function returns immediately.
    23.     public void LoadPageToMaterial(string url) {
    24.         StartCoroutine(MyLoadPage(url));
    25.     }
    26.    
    27.     // isLoading property returns true if page is still loading, otherwise returns
    28.     // false
    29.     public bool isLoading {
    30.         get { return loading; }
    31.     }
    32.    
    33.     // internal coroutine code that does the actual loading
    34.     private IEnumerator MyLoadPage(string url) {
    35.         WWW www = new WWW(converterURL + WWW.EscapeURL(url));
    36.         while (![url]www.isDone[/url]) {
    37.             yield return www;
    38.         }
    39.         if ([url]www.error[/url] == null) {
    40.             string str = [url]www.data;[/url]
    41.             www.Dispose();
    42.             www = new WWW(str);
    43.             while (![url]www.isDone[/url]) {
    44.                 yield return www;
    45.             }
    46.             if ([url]www.error[/url] == null) {
    47.  
    48.                 pageMaterial.mainTexture = [url]www.texture;[/url]
    49.                 www.Dispose();
    50.                 if (lastTexture != null) {
    51.                     DestroyImmediate(lastTexture);
    52.                 }
    53.                 lastTexture = pageMaterial.mainTexture;
    54.             }
    55.             else {
    56.                 Debug.Log("error getting img data '" + [url]www.error[/url] + "'");
    57.                 www.Dispose();
    58.             }
    59.         }
    60.         else {
    61.             Debug.Log("error getting img url '" + [url]www.error[/url] + "'");
    62.             www.Dispose();
    63.         }
    64.         loading = false;
    65.     }
    66.    
    67.    
    68.     // code below is purely for testing purposes
    69.     float nextUpdate = 0;
    70.  
    71.     // Update is called once per frame
    72.     void Update() {
    73.         if ((isLoading == false)  (Time.time > nextUpdate)) {
    74.             LoadPageToMaterial("http://en.wikipedia.org/wiki/Special:Random");
    75.             loading = true;        
    76.             nextUpdate = Time.time + 15.0f;
    77.             loading = false;
    78.         }
    79.     }
    80. }
    81.  
    PHP code

    Code (csharp):
    1. <?php
    2.         header('Content-type: text/plain');
    3.         $url = $_GET["url"];
    4.         $query = "http://ipinfo.info/netrenderer/?url=" . urlencode($url);
    5.         $ch = curl_init($query);
    6.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    7.         $output = curl_exec($ch);      
    8.         curl_close($ch);
    9.         if (ereg ("\"([url]http://renderer.geotek.de/image.php[/url][^\"]*)", $output, $regs)) {
    10.             echo "$regs[1]";
    11.         } else {
    12.             echo "";
    13.         }
    14. ?>
    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 :oops:
     
    merlinyx likes this.
  14. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    That is a novel approach. Excellent.
     
  15. matthewminer

    matthewminer

    Joined:
    Aug 29, 2005
    Posts:
    331
    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.
     
  16. projectD

    projectD

    Joined:
    Sep 2, 2009
    Posts:
    25
    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.
     
  17. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    You can keep track of mouse events in unity and send the mouse state to the php page as url parameters.
     
  18. createplayshare

    createplayshare

    Joined:
    Oct 15, 2009
    Posts:
    80
    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
     
  19. enrodri86

    enrodri86

    Joined:
    Jun 19, 2010
    Posts:
    1
    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

    Code (csharp):
    1. (Filename: Assets/AwesomiumDotNetTest.cs Line: 10)
    2.  
    3. Stacktrace:
    4.  
    5.   at AwesomiumDotNetTest.Start () [0x00026] in D:\Users\enrodri86\Documents\Itara Online\Assets\AwesomiumDotNetTest.cs:12
    6.   at AwesomiumDotNetTest.Start () [0x00020] in D:\Users\enrodri86\Documents\Itara Online\Assets\AwesomiumDotNetTest.cs:11
    7.   at (wrapper runtime-invoke) AwesomiumDotNetTest.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
    8. Receiving unhandled NULL exception
    9. 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?
     
  20. David_29

    David_29

    Joined:
    Jan 22, 2014
    Posts:
    12

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

    runner

    Joined:
    Jul 10, 2010
    Posts:
    865
    This uwebkit works well http://uwebkit.com/

    have used awesomium but no multi-threading like uwebkit so suffers performance wise
     
  22. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    Thanks everyone very informative. So the only way in U3D that doesnt require a U3D native html browser to place the images texts gifs buttons backgrounds on a page, is using an external browser to pass an image to U3D...

    There may be some solutions using another program that runs a script minimized and saves the page to a .jpg, if a process exists for that in windows it could be run from a command after the .exe:

    system.diagnostics.switch

    ProcessStartInfo theProcess = new ProcessStartInfo("filename.exe");

    theProcess.WindowStyle = ProcessWindowStyle.Minimized;

    Process.Start(theProcess);
     
  23. grobonom

    grobonom

    Joined:
    Jun 23, 2018
    Posts:
    335
    uwebkit seams dead.
    is there any way to display html webpages in unity today ?
     
    Avalin likes this.
  24. Giannigiardinelli

    Giannigiardinelli

    Joined:
    May 8, 2014
    Posts:
    179
    I'm reviving the subject " Here "
     
Thread Status:
Not open for further replies.