Hi everybody!
I’m new in Unity and the community, I’m trying to display an HTML page as a texture, and i found the htmltexture plugin.
I install it, (put in the Plugins folder of the project) and i wrote a C sharp code to make it work.
Now the code is not getting me any more error but Unity crashes any time I try to test it…
Any suggestion?
I have Unity PRO, I’m not making a web project.
Thanks!
Cecilia
I post the code below…
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
using System.Text;
public class TexturePlayback : 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 );
public int width = 512;
public int height = 512;
private 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();
}
}