Hi everyone, total Unity newbie here. This is my first post here.
Recently we acquired a Unity Pro license and I began to experiment with porting some of our work from TGE to Unity. One of the requirements was to display an animated Flash swf file in a texture.
So, I did that. Starting from the TexturePlugin sample, I have created a plugin that creates an offscreen webview, loads it from a URL, and copies the bitmap to an OpenGL texture every update. Animated SWFs play well, and since it’s using webkit, it uses the real Flash plugin and supports Flash video and all actionscript (unlike GameSWF which supports a limited subset). And since it’s just an HTML viewer, you can load HTML into the texture too.
Here are a couple of pictures:
You can see it’s picking up my local google cookies. (Yes, the scrollbars can be hidden.) And…
Since we’re new to Unity, I have no idea if this would to interesting or useful to others. If there is interest, we would be happy to make a release for community.
aaronsullivan: It uses webkit, so it supports whatever Safari can display (HTML+CSS, Quicktime, Flash, Shockwave, etc., even the Unity web player, for the truly insane). It has a function that lets you call into JavaScript on the page, so you can do setVar/getVar for Flash, or play/pause QuickTime movies, although it’s currently not returning a value because the whole string-marshalling-by-casting-to-an-int thing freaked me out.
Today I’ve only done the Mac build (it’s all we needed for this prototype) but it can be extended to Windows without too much trouble. I briefly looked at the webkit for windows project, and the build process looks hellish, so I’d probably just use an offscreen ActiveX IE control to render the content. The usual IE vs. Safari issues would apply.
Here’s another example. The texture displays a Flash SWF that uses your webcam and connects to a remote webconference via the Flash communication server.
(In this case, both of the videos are the same, although obviously it could be any number of remote videos).
By the way, that’s the Avacaster web conferencing system shown in the texture.
Does this mean I can then pull in a simple HTML formatted table in Kevin’s server side php code for high scores???
I couldn’t echo my returns into a table!
That would be awesome!!!
And wait a second, if you can then put a functioning Flash UI on a webpage and pull that onto a texture, you could do Flash-based UIs for the game … or not?
StarManta: Sure, that’s a live flash webcam site in the Avacast screenshot there.
DaveyJJ: yes, you could show any HTML page, so your high scores page would work too.
If you want to give it a try, I finally figured out how to make a working standalone build. Download it from http://robterrell.com/htmlTexture.app.zip. Click the cube to change the web site shown. There’s only a few (my wordpress blog page, these forums, the Otee web page, a YouTube video, a DailyMotion video) in there right now. I was going to add a text entry thingy so you could go to any web page, but I can’t seem to find one in the Unity manual. Any pointers?
This is for demo purposes, only, folks, and it’s not ready for general use, so please don’t go digging the plugin out of the app bundle.
First off, hi Rob! Welcome to the Unity community. 8) I’d like to say kudos for this and ask what performance is like? You mention the rendering of a page with “animated content” (eg: Flash), what sort of frame rates do you get with your plugin (your test app ran great on my MBP)? Also, how large (file size) is your plugin?
To everyone noting that this fits the feature needs folks have been asking for I must say that it doesn’t quite fit the bill. Without a doubt this is a fantastic way to render web pages as an image, but this is does not equate to “support for HTML display”. I say that because folks tend to want text-based HTML display, clickable links, etc (as opposed to rendering a page as an image). This is a fantastic step in the right direction but it’s not quite all the way with respect to the requested feature.
Edit: please note that I don’t mean to take anything away from Rob’s work, quite the opposite, he’s done a great job quite quickly. It’s just that I was trying to measure this against the long-requested feature of HTML rendering support. Sorry if my words above came off wrong to anyone (hope they didn’t!).
Yikes, that is neat. You’ve got to put that out to the community pronto. Can you provide two sample scenes … 1 flat plane and one with the cube? I assume that the GUITexture can also be a simple plane rather than your city-fancy cube, right ?
Oh, text entry found here … it works beautifully …
I added a function to the plugin to send click events. (I know, next you’ll want keypresses… one step at a time.) I figured I could cast a ray, find the texture pixel where the click happened, and pass that back to the plugin. If someone can help me figure out why this code returns (0,0) that is:
if (Input.GetMouseButtonUp(0)) {
RaycastHit hit;
if (Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) {
int x = (int) hit.textureCoord.x * width;
int y = (int) hit.textureCoord.y * height;
htmlTexture_leftclick( x, y );
}
There is a box collider on the cube in the scene. Shouldn’t that do it?