- Home /
How to load html content
Is it possible to load a web page from a Unity3d standalone build?
I also want to do this.. I want to build a browser in unity.. imagine being able to display a webpage on a ball..ins$$anonymous$$d of a window. animated windows that crumple like trash when u close them ect.. lasers and bombs to select links.. full control in a cool environment to build a browser.. it would detroy all other browsers in about a day.. Why is this not a standard unity template?. I want a dynamic webrowser under my control that can be its own search engine ect. and I can create my tabbed windows in Blender and script all their functions myself. i think building an operation system in unity would also be amazing.. but daunting due to file types. If anyone has the power to implement this please do so.
Answer by burnumd · Mar 03, 2010 at 10:04 PM
Unity does not have a built-in HTML parser/renderer. That said, you have a couple options.
- If you're using Unity Pro (and building a standalone, as your question suggests), you can use the HtmlTexturePlugin to display a web page on some surface. This solution has some limitations (described in the wiki page).
- You can always pull raw HTML content using the WWW class, and render it as best you can. AFAIK, there are no publicly available HTML renderer scripts.
So the short answer is, "Yes it's possible to load a web page; but what you do with it is another, more difficult matter."
The HtmlTexturePlugin is $$anonymous$$ac only. Is there anything similar to this for Windows?
Not that I know of. I haven't looked at the HT$$anonymous$$L Texture Plugin in a while, but if I remember correctly, it used Webkit which is embeddable in OS X. So you'd have to wrap some HT$$anonymous$$L rendering engine for it to work in Windows.
See also this thread, which mentions use of Web$$anonymous$$it and other possible techniques. http://forum.unity3d.com/threads/30677-Show-a-website-in-Unity
Adding a bit more to this: http://labs.awesomium.com/unity3d-integration-tutorial-part-1/
I was looking for similar feature and most of the lines I ran down called for Unity Pro which I don't yet have. The link I provided there sugests it works Basic or Pro
Sadly, awesomium doesn't seem to work anymore since they upgraded to 1.7...
Answer by springwater · Oct 27, 2015 at 11:55 AM
Well, I started writing my own parser/3d browser, it doesn't do much yet. it gets an URL, splits it into sub blocks of text and displays them. in theory if the sub block is too long it will shorten them, if they are to short it will lengthen them. then it runs through the program to the end one time printing out (again in theory) the first fifteen lines.. its buggy and I need to drink coffee to fix it. the next step will be to identify tags/attributes within it, remove them.. put info in proper field variables and so on.. it is attached to a background image plane and needs a starting 3dtext object in the scene.( and a light and camera.) my script uses a voice synthesizer.. you can remove the associated code from it regarding that.. but it seems like I have my foot in the door. or nose in the door of this process.(maybe I'm doing it wrong... going about it in a backwards manner.. ) but I'll share it with you guys. also, the GUI in the picture is separate and nonfunctional so far.
[1]: /storage/temp/57035-htm1.png
#pragma strict
// this script attaches to the background plane object in truedragon unityproject..by Aaron McCue oct 2015
var url: String;
var www: WWW;
var a=0;
www = new WWW( "https://www.yahoo.com/");
var textt:GameObject;
var texta:String;
var k=0; //keeps track of how many lines were too long
var clonedonce=false;
var clonedtwice=false;
var clonezactive=false;
var clonedzero=false;//print overflown first line of html
var printoriginal=false;//print first line of html
var g=0;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////START FUNCTION BELOW////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Start() {
WindowsVoice.theVoice.speak("Welcome to true dragon, the browser of tomorrow");
//www = new WWW( "file:///C://Users/dell/Desktop/dragontest.htm");
//texta= textt.GetComponent.<TextMesh>().text;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////===============================//UPDATE FUNCTION BELOW///================================================
/////////////////////////////////////////////////////////////////////////////////////////////////////
function Update(){////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//-solid never changes region-------------------------------this code below should be stable and mostly unchangin-------------
if (www.isDone==true&& a==0){//wait for www to load... var a prevents this from occuring more than once
var readout=www.text ;//readout is now the string html object
var tree : String[] = readout.Split("<"[0]);// break the original html at all <characters
// var renderer: Renderer = GetComponent.<Renderer>(); //saving these for later implementation
//renderer.material.mainTexture = www.texture; //saving these for later implementation
/////////////////////////////////solid never changes region above///////////////////////////////////////
/////////////////////////////////////no/low change above ///////////////////////////////////////////////////////
//////////////////////////////////////////////parse lines code below////////////////////////////////////
for (var i=0; i<=15; i++){ // do everything in this loop 15 times (print 15 lines of html)
if (!(i > tree.Length))
textt.GetComponent.<TextMesh>().text= textt.GetComponent.<TextMesh>().text.Concat(tree[i]);// sets textt.text to concat [i] .but does not check to see if its too long!
//printoriginal=true;// this doesnt do anything.. because at the end the var a is set to 1.. stopping this from happening each time continued below
//~cont. everything here runs once!
//--------------------split the original string if neccesary
//===============================================================tree [i] which was broken at < too long below========================
if (textt.GetComponent.<TextMesh>().text.Length>60){// if the first line is too long.. break it
var firsttree: String[]=textt.GetComponent.<TextMesh>().text.Concat(tree[i]).Split(" "[0]);//splits the first broken sting at blank spaces
textt.GetComponent.<TextMesh>().text="nil";//sets text to something small so it doesnt trigger trouble for the next step
//below the textt.GetComponent.<TextMesh>().text.Length is assumed to be about 1 word long on first itteration, because it was just split
for ( var i0=0; textt.GetComponent.<TextMesh>().text.Length <= 60; i0++){// i0 will count up each time concatenatin words as long as the str lgnth<60
if (i0>=firsttree.Length){//stops the for loop from going over firsttrees[] length and will reset i0 to zero
i0=0;//resets i0 for use in the next line
WindowsVoice.theVoice.speak("eye, o, is greater or equal to first tree dot length property");
break;
} //breaks out of the loop if i0 (current itteration) is greater than
if( clonezactive==false)//the next line should only concatenate until full.. this should solve that
Debug.Log("fisttreelength minus 1="+(firsttree.Length-1));
Debug.Log("io="+i0);
if (i0<firsttree.Length-1){//i0 should not exceed firttreelength
textt.GetComponent.<TextMesh>().text= firsttree[i0].Concat(firsttree[i0+1]);
clonedonce=true;//first tier line that was broken is being concatenated
}// end (i0<=firsttree.Length-1) bracket
if (textt.GetComponent.<TextMesh>().text.Length>=60){//if/when concatenation itteration is greater than the halfed string length
if( clonezactive==false)
clonezactive=true;
WindowsVoice.theVoice.speak("original line, has maxed its length");
var clonezero =Instantiate(textt,textt.transform.position, textt.transform.rotation);// creates a clone for the next line after line 1
clonedzero=true;
clonezero.GetComponent.<TextMesh>().text=firsttree[i0].Concat(firsttree[i0+1]);
} //if/when concatenation itteration is greater than the halfed string length end bracket
}//for i0 loop bracket
}//end original text too long
//=======================================first line of < broken text was ok as far as length is concerned======================================================================
else//textt.text not greater than 60!! first line was not too long.. need to concat
{ for (var j=0;textt.GetComponent.<TextMesh>().text.Length<60;j++)//try to concatenate too make a complete line
if (j>20)
break;
textt.GetComponent.<TextMesh>().text=textt.GetComponent.<TextMesh>().text.Concat(tree[g]);
if (g<tree.Length)
g++;
else
break;
//--------------this next area shoud make a short text longerbut not longer than 60 chars
if (textt.GetComponent.<TextMesh>().text.Length>60){
Debug.Log("textt.text just passed 60 its at "+textt.GetComponent.<TextMesh>().text.Length + ".. removing lastword");
var line1:String= textt.GetComponent.<TextMesh>().text;
var index= line1.LastIndexOf(" \\b\\s*");// removes the word on the right ans any righthand blankspace to the edge i think!to shortena line thats gone over
line1.Replace(line1.Substring(index),"");
var textty:String[] = textt.GetComponent.<TextMesh>().text.Split(" "[0]);
Debug.Log("The last word in textt.text was: " + textty[textty.Length - 2] );
// for( var o = 0; o < textty.Length - 1; o++)
//Debug.Log(textty[o] + " " );
//i0--; <----- something must be done to account for bites eaten here from the begging of the readout, readout neads to be recalculated i suppose.
Debug.Log("textt.text now sits at "+textt.GetComponent.<TextMesh>().text.Length);
g=0;
break;
}
}
//========================================================================================================================
var clone =Instantiate(textt,textt.transform.position, textt.transform.rotation);// creates a clone for the next line after line 1
//-------------------------------------------------------------------------------------------------------------------
//-----------------------primary string full and breaks
if (clone.GetComponent.<TextMesh>().text.Length>60){//if the clone is too long we split it
WindowsVoice.theVoice.speak("line"+i+ "was too long" );
k++;//keeps track of how many lines were too long
clonedonce=true;// this sends a message to print the output to line a line when the 15x loop is done with an itteration
var tree2 : String[] = clone.GetComponent.<TextMesh>().text.Split(" "[0]);//tree2 is the new split array
// var clone2=Instantiate (textt,textt.transform.position, textt.transform.rotation);//instanciate a clone2 that have up to 30 char
// clone2.transform.position.y-=.2+i*.5;//position clone2 for concatenation
var i2=0;
clone.GetComponent.<TextMesh>().text=tree2[i2];
for ( i2=0; clone.GetComponent.<TextMesh>().text.Length < 60;i2++){
if (i2>clone.GetComponent.<TextMesh>().text.Length){
WindowsVoice.theVoice.speak("clone, too, has maxed its length");
break;
}//end if i2 greater than clone length bracket
//clone2.GetComponent.<TextMesh>().text=tree2[i2].Concat(tree2[i2+1]);
clone.GetComponent.<TextMesh>().text=tree2[i2].Concat(tree2[i2+1]);
//-----------------------------------------------------------------------------------------------------------
if(i2==60){//first substring broke and is overflowing
i2=0;//reset i2 for next primarystring
clonedonce=false;//stops the message from the first clone from getting printed
clonedtwice=true;//starts the message from the clone for getting printed
var tree3 : String[] = clone.GetComponent.<TextMesh>().text.Split(" "[0]);
var clone3=Instantiate (textt,textt.transform.position, textt.transform.rotation);//instanciate a clone2 that have up to 30 char
//clone3.transform.position.y-=.2+i*.5;//position clone3 for concatenation
for (var i3=0;clone3.GetComponent.<TextMesh>().text.Length<60;i3++){
if (i3==clone3.GetComponent.<TextMesh>().text.Length)
break;
clone3.GetComponent.<TextMesh>().text=tree3[i3].Concat(tree3[i3+1]);
if(i3==60)
i3=0;
}//end fo i3=0 loop
}//end first substring broke bracket
} //for i2=0 bracket
Destroy(clone);
}//end first clone too long bracket
/////////////////////////////////////////////////////////////parse lines code above////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// if( printoriginal==true){//none of this was needed because the oeriginal runs once and always prints itself then a is set to one below stopping other itterations
// printoriginal=false;
// i++;//one of the 15 iterations goes up
// textt.GetComponent.<TextMesh>().text;
// }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////printlines code below///////////////////////////////////
if( clonedzero==true){
clonezactive=false;
i++;//counts as a second line
clonezero.transform.position.y-=.2+i*.5;
clonezero.GetComponent.<TextMesh>().text=firsttree[i0];
clonedzero=false;
}
if( clonedtwice==false)
clone.transform.position.y-=.2+i*.5;
if( clonedonce==false)
clone.GetComponent.<TextMesh>().text=tree[i];
if( clonedonce==true){
clone.GetComponent.<TextMesh>().text=tree[i2];
clonedonce=false;
}
if( clonedtwice==true){
i++;//counts as a second line
clone3.transform.position.y-=.2+i*.5;
clone3.GetComponent.<TextMesh>().text=tree[i3];
clonedtwice=false;
}
//Debug.Log(tree[i]);
//if (i==20)
//if (i==readout.Length-1)
}//end i<15 bracket
a=1;
WindowsVoice.theVoice.speak("A, equals one, vaariable eye, has, surpassed fifteen, program complete");
}//end isdone bracket
}//end update
Your answer
Follow this Question
Related Questions
Alternative to WWW Loading 2 Answers
Images added to the Resource folder should reflect in thee build? 0 Answers
Saving and loading data from file 0 Answers
how to load random level but one? 3 Answers
WaitForSeconds 1 Answer