- Home /
How do install a plugin?
So I got the htmlTexturePlugin from the unity wiki here http://wiki.unity3d.com/index.php?title=HtmlTexturePlugin
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; } void Update() { htmlTexture_update( m_Texture.GetInstanceID() ); } void OnApplicationQuit() { htmlTexture_stop(); } }
am also having this same problem. I created a script and added the code provided on the website to the class. I dropped the c# code on the plane and received the following error:
'm_Texture' does not exist in the current context.
Answer by Loius · Jan 17, 2013 at 09:37 PM
You need to declare m_Texture's type.
I hate unofficial tutorials for exactly this reason. Why would someone provide that example code in such a flawed state? O_o
You need this line in your class to make m_Texture a class variable:
Texture2D m_Texture;
Answer by Wiggitamoo · Jan 18, 2013 at 04:26 PM
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
Your answer
Follow this Question
Related Questions
Can Unity utilize textures created by a plugin? 1 Answer
html texture plugin 1 Answer
Problem, Textures updated by plugin won't behave as expected in combination with HLSL shader 2 Answers
Are there any good plugins out there for putting a web page into a unity scene? 1 Answer
LIVETEXTURE FRONT CAMERA BACK, STOP VUFORIA PLUGIN 0 Answers