How to load html content

Is it possible to load a web page from a Unity3d standalone build?

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."

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.

#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_);// sets textt.text to concat  *.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 which was broken at < too long below========================
if (textt.GetComponent.().text.Length>60){// if the first line is too long… break it
var firsttree: String[]=textt.GetComponent.().text.Concat(tree*).Split(" "[0]);//splits the first broken sting at blank spaces*

textt.GetComponent.().text=“nil”;//sets text to something small so it doesnt trigger trouble for the next step

//below the textt.GetComponent.().text.Length is assumed to be about 1 word long on first itteration, because it was just split
for ( var i0=0; textt.GetComponent.().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.().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.().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.().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.().text.Length<60;j++)//try to concatenate too make a complete line

if (j>20)
break;

textt.GetComponent.().text=textt.GetComponent.().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.().text.Length>60){
Debug.Log("textt.text just passed 60 its at "+textt.GetComponent.().text.Length + “… removing lastword”);
var line1:String= textt.GetComponent.().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.().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.().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.().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.().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.().text=tree2[i2];

for ( i2=0; clone.GetComponent.().text.Length < 60;i2++){
if (i2>clone.GetComponent.().text.Length){
WindowsVoice.theVoice.speak(“clone, too, has maxed its length”);
break;
}//end if i2 greater than clone length bracket
//clone2.GetComponent.().text=tree2[i2].Concat(tree2[i2+1]);
clone.GetComponent.().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.().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.().text.Length<60;i3++){
if (i3==clone3.GetComponent.().text.Length)
break;
clone3.GetComponent.().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.().text;
// }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////printlines code below///////////////////////////////////

if( clonedzero==true){
clonezactive=false;
i++;//counts as a second line
clonezero.transform.position.y-=.2+i*.5;
clonezero.GetComponent.().text=firsttree[i0];
clonedzero=false;
}

if( clonedtwice==false)
clone.transform.position.y-=.2+i*.5;
if( clonedonce==false)
clone.GetComponent.().text=tree*;*

if( clonedonce==true){
clone.GetComponent.().text=tree[i2];
clonedonce=false;
}

if( clonedtwice==true){
i++;//counts as a second line
clone3.transform.position.y-=.2+i*.5;
clone3.GetComponent.().text=tree[i3];
clonedtwice=false;
}

_ //Debug.Log(tree*);
//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