and I’m not sure how to get it to work. I dropped the bundle I downloaded into unity and I got it to install something called htmlTexture. Then I placed the sample code they have on the wiki into a script and placed that script on a plane. But I got back a bunch of errors. One error was" ‘m_Texture’ does not exist in the current context". Here is the code I used. `using UnityEngine;
using System.Collections;
public class htmlTexture : MonoBehaviour {
public int width =512;
public int height = 512;
void Start() {
m_Texture = new Texture2D (width, height, TextureFormat.ARGB32, false);
m_Texture.Apply();
htmlTexture_start(m_Texture.GetInstanceID(), width, height, "http://google.com");
// put the texture on something
transform.renderer.sharedMaterial.mainTexture = m_Texture;
I’m still having problems getting this code to work. Is this how you setup the code?
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
using System.Text;
public class DisplayWebpage : MonoBehaviour {
[DllImport ("htmlTexture")]
private static extern void htmlTexture_start( int textID, int width, int height, string url );
// creates the offscreen window and webview
// url: initial URL to display, use null for none
// width, height: currently must be a power of 2 (i.e. 128, 256, 512, 1024) due to my using GL_TEXTURE2D
[DllImport ("htmlTexture")]
private static extern void htmlTexture_stop();
// releases all windows and webview; use on quit
[DllImport ("htmlTexture")]
private static extern void htmlTexture_update ( int texID );
// makes bitmap of the webview and loads it into openGL with the given texture ID
//
// browser functions
//
// as you'd expect, handles any URL, HTML and CSS that webkit can
//
[DllImport ("htmlTexture")]
private static extern void htmlTexture_setURL( int texID, string url);
[DllImport ("htmlTexture")]
private static extern void htmlTexture_getURL( int texID, StringBuilder url, int stringCapacity);
// to get the current URL, you need to pass in a StringBuilder and its capacity (to
// avoid buffer overflow errors)
[DllImport ("htmlTexture")]
private static extern void htmlTexture_goBack( int texID );
[DllImport ("htmlTexture")]
private static extern void htmlTexture_goForward( int texID );
[DllImport ("htmlTexture")]
private static extern void htmlTexture_sendJavascript( int texID, string js);
// sends a string to the webview's javascript interpreter
// will return a string result as soon as I get the Marshall class figured out
[DllImport ("htmlTexture")]
private static extern void htmlTexture_sendJavascript( int texID, string js, StringBuilder result, int stringCapacity);
// sends a string to the webview's javascript interpreter
// will return a string result
[DllImport ("htmlTexture")]
private static extern void htmlTexture_sendKeypress( int texID, string s);
//
// these functions simulate a mouse event in the webview
//
[DllImport ("htmlTexture")]
private static extern void htmlTexture_mousemoved( int texID, int _x, int _y );
[DllImport ("htmlTexture")]
private static extern void htmlTexture_mousedown( int texID, int _x, int _y );
[DllImport ("htmlTexture")]
private static extern void htmlTexture_mouseup( int texID, int _x, int _y );
[DllImport ("htmlTexture")]
private static extern void htmlTexture_leftclick( int texID, int _x, int _y );
// leftclick = a mousemoved, mousedown, and mouseup
//
public int width =512;
public int height = 512;
Texture2D m_Texture;
void Start() {
m_Texture = new Texture2D (width, height, TextureFormat.ARGB32, false);
m_Texture.Apply();
htmlTexture_start(m_Texture.GetInstanceID(), width, height, "http://google.com");
// put the texture on something
transform.renderer.sharedMaterial.mainTexture = m_Texture;
}
void Update() {
htmlTexture_update( m_Texture.GetInstanceID() );
}
void OnApplicationQuit() {
htmlTexture_stop();
}
void OnMouseUp()
{
RaycastHit hit;
if (Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) {
int x = width - (int) (hit.textureCoord.x * width);
int y = height - (int) (hit.textureCoord.y * height);
htmlTexture_mouseup(m_Texture.GetInstanceID(), x, y );
}
}
//
}
Please let me know if you have any differences / suggestions