Search Unity

htmlTexture plugin

Discussion in 'Made With Unity' started by bliprob, May 15, 2007.

  1. willgoldstone

    willgoldstone

    Unity Technologies

    Joined:
    Oct 2, 2006
    Posts:
    794
    Hi!

    again thanks for getting back to me, and as a result of some fiddling based on what i understand from your last post I now have this -

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System;
    5. using System.Runtime.InteropServices;
    6. using System.Text;
    7.  
    8. public class TexturePlayback : MonoBehaviour { 
    9.        
    10.     [DllImport ("htmlTexture")]
    11.     private static extern void htmlTexture_start( int textID, int width, int height, string url );
    12.     //  creates the offscreen window and webview
    13.     //  url: initial URL to display, use null for none
    14.     //  width, height: currently must be a power of 2 (i.e. 128, 256, 512, 1024) due to my using GL_TEXTURE2D
    15.  
    16.     [DllImport ("htmlTexture")]
    17.     private static extern void htmlTexture_stop();
    18.     // releases all windows and webview; use on quit
    19.  
    20.     [DllImport ("htmlTexture")]
    21.     private static extern void htmlTexture_update ( int texID );
    22.     // makes bitmap of the webview and loads it into openGL with the given texture ID
    23.  
    24.     //
    25.     // browser functions
    26.     //
    27.     // as you'd expect, handles any URL, HTML and CSS that webkit can
    28.     //
    29.  
    30.     [DllImport ("htmlTexture")]
    31.     private static extern void htmlTexture_setURL( int texID, string url);
    32.  
    33.     [DllImport ("htmlTexture")]
    34.     private static extern void htmlTexture_getURL( int texID, StringBuilder url, int stringCapacity);
    35.     // to get the current URL, you need to pass in a StringBuilder and its capacity (to
    36.     // avoid buffer overflow errors)
    37.    
    38.     [DllImport ("htmlTexture")]
    39.     private static extern void htmlTexture_goBack( int texID );
    40.        
    41.     [DllImport ("htmlTexture")]
    42.     private static extern void htmlTexture_goForward( int texID );
    43.        
    44.     [DllImport ("htmlTexture")]
    45.     private static extern void htmlTexture_sendJavascript( int texID, string js);
    46.     // sends a string to the webview's javascript interpreter
    47.     // will return a string result as soon as I get the Marshall class figured out
    48.  
    49.     [DllImport ("htmlTexture")]
    50.     private static extern void htmlTexture_sendJavascript( int texID, string js, StringBuilder result, int stringCapacity);
    51.     // sends a string to the webview's javascript interpreter
    52.     // will return a string result
    53.  
    54.        
    55.     [DllImport ("htmlTexture")]
    56.     private static extern void htmlTexture_sendKeypress( int texID, string s);
    57.    
    58.    
    59.     //
    60.     // these functions simulate a mouse event in the webview
    61.     [DllImport ("htmlTexture")]
    62.     private static extern void htmlTexture_mousemoved( int texID, int _x, int _y );
    63.    
    64.     [DllImport ("htmlTexture")]
    65.     private static extern void htmlTexture_mousedown( int texID,  int _x, int _y );
    66.  
    67.     [DllImport ("htmlTexture")]
    68.     private static extern void htmlTexture_mouseup( int texID, int _x, int _y );
    69.    
    70.     [DllImport ("htmlTexture")]
    71.     private static extern void htmlTexture_leftclick( int texID, int _x, int _y );
    72.    
    73.  
    74.    
    75. public int width = 512;
    76. public int height = 512;
    77. private Texture2D m_Texture;
    78.  
    79. void Start() {
    80.     m_Texture = new Texture2D (width, height, TextureFormat.ARGB32, false);
    81.     m_Texture.Apply();
    82.     htmlTexture_start(m_Texture.GetInstanceID(), width, height, "http://google.com");
    83.     // put the texture on something
    84.     transform.renderer.sharedMaterial.mainTexture = m_Texture;
    85. }
    86.    
    87. void Update()
    88.     {
    89.         htmlTexture_update(m_Texture.GetInstanceID());
    90.     }
    91.  
    92. void OnApplicationQuit()
    93.     {
    94.         htmlTexture_stop();
    95.     }
    96.    
    97.    
    98. void OnMouseUp()
    99. {
    100.     //placed this in as I thought it'd make it update on click... doesnt!
    101.     htmlTexture_update(m_Texture.GetInstanceID());
    102.    
    103.     RaycastHit hit;
    104.     if (Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) {
    105.         int x = width - (int) (hit.textureCoord.x * width);
    106.         int y = height - (int) (hit.textureCoord.y * height);
    107.         htmlTexture_mouseup(m_Texture.GetInstanceID(), x, y );
    108.     }
    109.    
    110.    
    111. }
    112.    
    113. }
    Which displays the texture again, and even shows me a hand icon occasionally when hovering over a link, BUT! still no working clicks to navigate.

    I'm used to javascript but don't really ever use C# so excuse my confusion in all of this! Feel like i'm getting somewhere now though... if i'm missing something basic let me know, if i'm way off and you're busy i'll wait til you post on the wiki.

    Cheers again for all your hard work


    Will
     
  2. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    will: As mentioned a page or so ago, stick some debugging info in there:
    Code (csharp):
    1. print("Object: " + hit.collider.gameObject.name +  ", HitPt: " + hit.point + ", Mouse: " + Input.mousePosition + ", textureCoord: " + hit.textureCoord + ", textureCoord2: " + hit.textureCoord2 + ", x: " + x + ", y: "+ y);
    Then you'll be able to see what coordinates are being used. Also, don't forget to do an OnMouseDown() function too. It's quite possible that a mouseup by itself isn't going to fire a click within the browser.

    If you've got more questions, PM or email me (rob@stinkbot.com) to save thread.
     
  3. gazwi86

    gazwi86

    Joined:
    Jan 25, 2008
    Posts:
    21
    Ive got it printing the x and y just not seeing links, nor on mouseup or down having any luck. Will's code above with the hand appearing just made unity crash for me.


    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System;
    4. using System.Runtime.InteropServices;
    5.  
    6. public class PluginTexture : MonoBehaviour
    7. {
    8.     public int width = 512;
    9.     public int height = 512;
    10.  
    11. //   htmlTexture_start() creates the offscreen window and webview
    12. //   url: initial URL to display, use null for none
    13. //   width, height: currently must be a power of 2 (i.e. 128, 256, 512, 1024) due
    14. //    to my using GL_TEXTURE_2D
    15.  
    16. [DllImport ("htmlTexture")]
    17. private static extern void htmlTexture_start( string url, int width, int height);
    18.  
    19. // htmlTexture_stop() releases the window and webview
    20.  
    21. [DllImport ("htmlTexture")]
    22. private static extern void htmlTexture_stop();
    23.  
    24. //
    25. // htmlTexture_update() -- call this in your MonoBehavior::Update()
    26. // loads a bitmap of the webview into openGL with the given texture ID
    27. //
    28.  
    29. [DllImport ("htmlTexture")]
    30. private static extern void htmlTexture_update ( int texID );
    31.  
    32. //
    33. // browser functions
    34. //
    35. // as you'd expect, handles any URL, HTML and CSS that webkit can
    36. //
    37.  
    38. [DllImport ("htmlTexture")]
    39. private static extern void htmlTexture_setURL( string url);
    40.  
    41. [DllImport ("htmlTexture")]
    42. private static extern void htmlTexture_goBack();
    43.    
    44. [DllImport ("htmlTexture")]
    45. private static extern void htmlTexture_goForward();
    46.  
    47. // sends a string to the webview's javascript interpreter
    48. // returns a string ptr result -- use Marshal.PtrToStringAnsi() to read
    49.  
    50. [DllImport ("htmlTexture")]
    51. private static extern void htmlTexture_sendJavascript( string js);
    52.  
    53. //
    54. // these functions simulate a mouse event in the webview
    55. //
    56.  
    57. [DllImport ("htmlTexture")]
    58. private static extern void htmlTexture_mousemoved( int _x, int _y );
    59.  
    60. [DllImport ("htmlTexture")]
    61. private static extern void htmlTexture_mousedown( int _x, int _y );
    62.  
    63. [DllImport ("htmlTexture")]
    64. private static extern void htmlTexture_mouseup( int _x, int _y );
    65.  
    66. // htmlTexture_leftclick() = a mousemoved, mousedown, and mouseup
    67.  
    68. [DllImport ("htmlTexture")]
    69. private static extern void htmlTexture_leftclick( int _x, int _y );
    70.  
    71.     private Texture2D m_Texture;
    72.  
    73.     void Start()
    74.     {  
    75.         m_Texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
    76.         m_Texture.Apply();
    77.         htmlTexture_start("http://impserver.bournemouth.ac.uk/~gwilliams/The%20Buzz%20Online/Images/mic.swf", width, height);
    78.  
    79.         // put the texture on something
    80.         transform.renderer.sharedMaterial.mainTexture = m_Texture;
    81.     }
    82.  
    83.     void Update()
    84.     {
    85.         htmlTexture_update(m_Texture.GetInstanceID());
    86.     }
    87.  
    88.     void OnApplicationQuit()
    89.     {
    90.         htmlTexture_stop();
    91.     }
    92.  
    93. void OnMouseUp()
    94. {
    95.       RaycastHit hit;
    96.       if (Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) {
    97.          int x = width - (int) (hit.textureCoord.x * width);
    98.          int y = height - (int) (hit.textureCoord.y * height);
    99.          print("Object: " + hit.collider.gameObject.name +  ", HitPt: " + hit.point + ", Mouse: " + Input.mousePosition + ", textureCoord: " + hit.textureCoord + ", textureCoord2: " + hit.textureCoord2 + ", x: " + x + ", y: "+ y);
    100.          htmlTexture_mouseup(x, y );
    101.       }
    102. }
    103.  
    104. }
    105.  
    106.  
    Where am i going wrong? It still doesnt send the click events.
     
  4. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Your code above is using the old interface. The new plugin requires you to pass the texture ID to every function, because it can handle more than one HTML texture. If you're using the old interface and the new plugin binary, I'd expect a crash. Look up a couple of posts (or look on the wiki) for the latest interface.

    As for Will's issue, I've sent him my test project and he sees it working, so hopefully he'll be able to compare and figure out the problem is soon. One thing I noticed in his project is that he's trying to get the hit coordinates from a cube; my project is using a plane. There may be something different in how the cube is texture mapped, so give a plane (or a GUI texture) a try to start.
     
  5. flash

    flash

    Joined:
    Jan 26, 2008
    Posts:
    54
    First off, thanks for this plugin (and the Wiimote - planning on working with both of them). I've read all of the posts and spent some time on the IRC channel and I had a friend try it with the same results that I'm getting. It compiles and runs just fine, but the texture is completely black.

    I have the 0.5 plugin in the plugins folder and here's the code I'm using - stripped it down to just the barebones to display a picture and nothing else.


    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System;
    4. using System.Runtime.InteropServices;
    5.  
    6. public class PluginTexture : MonoBehaviour
    7. {
    8.    
    9.  
    10. //   htmlTexture_start() creates the offscreen window and webview
    11. //   url: initial URL to display, use null for none
    12. //   width, height: currently must be a power of 2 (i.e. 128, 256, 512, 1024) due
    13. //    to my using GL_TEXTURE_2D
    14.  
    15. [DllImport ("htmlTexture")]
    16. private static extern void htmlTexture_start( string url, int width, int height);
    17.  
    18. // htmlTexture_stop() releases the window and webview
    19.  
    20. [DllImport ("htmlTexture")]
    21. private static extern void htmlTexture_stop();
    22.  
    23. //
    24. // htmlTexture_update() -- call this in your MonoBehavior::Update()
    25. // loads a bitmap of the webview into openGL with the given texture ID
    26. //
    27.  
    28. [DllImport ("htmlTexture")]
    29. private static extern void htmlTexture_update ( int texID );
    30.  
    31.        
    32.     public int width = 512;
    33.     public int height = 512;    
    34.     private Texture2D m_Texture;
    35.  
    36.     void Start()
    37.     {  
    38.         m_Texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
    39.         m_Texture.Apply();
    40.         htmlTexture_start("http://www.google.com", width, height);
    41.         // put the texture on something
    42.         transform.renderer.sharedMaterial.mainTexture = m_Texture;
    43.     }
    44.  
    45.     void Update()
    46.     {
    47.         htmlTexture_update(m_Texture.GetInstanceID());
    48.     }
    49.  
    50.     void OnApplicationQuit()
    51.     {
    52.         htmlTexture_stop();
    53.     }
    54.  
    55. }
    56.  
    57.  
    58.  
    Are there any settings in Unity that I need to adjust besides the cube scale to -1,-1,-1? My camera is tagged as the main camera. Do I need to add a light?

    Any help would be appriciated
     
  6. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    For the latest version of the plugin, your interface is wrong. Use this:
    Code (csharp):
    1.    private static extern void htmlTexture_start( int textID, int width, int height, string url );
    2.  
    You must pass the texture ID into start; there's a mapping between the texture ID and the URL being displayed. So:
    Code (csharp):
    1.  
    2.   void Start()
    3.     {    
    4.         m_Texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
    5.         m_Texture.Apply();
    6.     htmlTexture_start(m_Texture.GetInstanceID(), width, height, "http://google.com");
    7.         // put the texture on something
    8.         transform.renderer.sharedMaterial.mainTexture = m_Texture;
    9.     }
    That's two in a row with the same error. Maybe I wrote it up wrong on the wiki.... nope, the wiki looks right.
     
  7. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    By the way, I found a bug in htmlTeture_sendJavascriptWithReturn() today, which I've now fixed. New build is online now.

    I've now created a voice-activated game! There's an unseen html texture that contains a tiny Flash SWF. The SWF reports activity on the microphone, which it sends to the HTML page's javascript. The game calls the HTML's javascript asking for the current mic level every Update(). So basically, when you want to fire, you yell "fire!" Or clap your hands. Or whatever.
     
  8. flash

    flash

    Joined:
    Jan 26, 2008
    Posts:
    54
    I guess it would have helped if I had read your last post a little more clearly. Things are always obvious when you see the light.



    A few pages back you mentioned that the plugin now allows for multiple URLs to be handled internally. I have successfully made it work but I have a strange thing happening that I was hoping you could explain whats going on.

    I had to change the Element 0 in the Materials list of the Mesh Renderer in order for the HTML texture to over write it, If I left it alone it would not work. Plus when I loaded in a cube without attaching anything to it, the HTML texture would be automatically loaded on when I hit play.

    I have it working like I want it so far, but these were some strange quirks that I had to work through...maybe it's my lack of knowledge in Unity...I don't know.

    Flash
     
  9. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Any news on the windows port of the plugin ?
    Is everything going the way you would like it to be ?
     
  10. blogbod

    blogbod

    Joined:
    Feb 3, 2008
    Posts:
    4
    I have followed the posts and wiki, I can render the webpage, get the right x,y coordinates, have used the mesh collider on a cube used the -1 scale transform. Can you please post demo code that works. Keep up the great work.

    I want to create a google earth type interface and use kml files and tiles.

    Thanks
     
  11. MrBodean

    MrBodean

    Joined:
    Jan 25, 2008
    Posts:
    103
    Sorry if I missed something but want to make sure

    This html plugin only works in Standalone? Is there no way to use this in the webplayer version?

    If it does not, is there any way of doing that?

    Thanks,
    Jeff
     
  12. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Sounds like it's all working. What demo code do you need?

    That would be nifty. Way beyond my knowledge, mapping coordinates to a sphere, but sounds cool.

    Nope, plugins do not work in the web player. (Requires Unity Pro, too.)

    The only browser plugin I've seen that accepted its own plug-in was Macromedia Shockwave. Making plugins for Shockwave was a hassle -- aside from the crummy COM-derived programming API, you had to sign the code with a verisign code-signing key that verisign would refuse to sell you when you called and asked for it. The user had to click through a dialog acknowledging that they were about to execute your scary signed code (and basically scarily implied your plugin was rarin' to wipe the user's hard drive, all bets were off, don't blame Macromedia, etc.).

    Plugins for plugins, yeah, not so fun. If Unity supported it, I would do it, but it doesn't, so you might have an easier time getting Unity to simply add this functionality to the engine.

    On this note, while working on the Windows versiom, I've seen that I can write most of the code in managed c# and only call out to a few DLLs (most importantly mshtml.dll) to render the page. If it's possible to call a system DLL via DllImport in the web player, I would be able to do that. But it's something I've never tried. You know, I hope it isn't allowed, or there's a huge security hole right there.
     
  13. MrBodean

    MrBodean

    Joined:
    Jan 25, 2008
    Posts:
    103
    I do understand the security issue, but wow the power of this is sooo huge and if Unity really wants this to be the web plugin of choice, I can only pray they add it in. I see soooo many uses for this.

    One of the main reasons I went with Unity was because of the web player. I really don't want to bother with stand alone apps , but since most of my ideas are based around linking this into web applications, it really needs to be a way to do this...

    Fingers crossed on this one.... :)

    Ps I did buy the Pro version, so if no other way maybe I can play with some ideas in stand alone if the web player nevers gets this update...
     
  14. blogbod

    blogbod

    Joined:
    Feb 3, 2008
    Posts:
    4
     
  15. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Pass in a null instead of a URL in htmltexture_Start() to get a debugging "you clicked at X,Y" page. Then click in all four corners of the texture, and see where the HTML page thinks you're clicking. That can help you figure out if there's a weird UV mapping issue.

    What is output by the print() command? Does it seem right?
     
  16. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    The project I use for testing the plugin (which shows all of these features working) can now be downloaded from here:

    http://robterrell.com/htmlTextureProject.zip

    If you're having trouble getting clicks to register, download the test project and see if you've setup your material differently than I have.
     
  17. blogbod

    blogbod

    Joined:
    Feb 3, 2008
    Posts:
    4
    Thanks Rob that really helped, being new to unity it took me a while to figure out how to get rid of the upside down window in the front. It was the script attached to the camera. Traps for new players.

    If you go to a site such as http://www.zoomify.com/ and try to drag the image around the image moves in unpredictable ways such as backwards. This is a mousedown and drag.
     
  18. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Sorry about that! I forgot I had attached a script there to test if the texture worked in one of the new 2.0 GUI objects. (And it does, just upside down.) Thanks for the heads up. I will remove that from the sample project.

    I'll give it a try. Can you make your code dump the coordinates it's sending to the plugin during a drag, so we can look at them and make sure they're all sane? We may need to add some bounds-checking in the case the cast ray doesn't intersect the texture, etc.

    I have noticed that Flash rollovers aren't working properly. I'm planning on fixing that at some point.
     
  19. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    This is VERY nice :D :!: :!: :!:

    But can you post the app again so we who don't have unity pro can see how it works (now the only version is the old one (if i haven't missed something)).
     
  20. blogbod

    blogbod

    Joined:
    Feb 3, 2008
    Posts:
    4
    I was just thinking wouldn't it bee cool to put an opensource vnc into a plugin.
    I wonder is there a way to put the output of a local app into a plugin and control it throuh unity?
     
  21. Ricko

    Ricko

    Joined:
    Dec 9, 2007
    Posts:
    169
    While remote control is a cool idea, it is also part of the reason this plug in will never be allowed in the Web Player version of Unity. At least not in plug-in form.

    Ricko
     
  22. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    You mean, like this?



    That's a real, live usable VNC connection in there. You can double-click icons, move windows, etc. Yes, you could drop a VNC engine into a Unity plugin. But since there are decent browser-based alternatives (the TightVNC and UltraVNC applets and the FlashVNC swf came to mind first) I simply made a web page with one.

    It's easier to see it working in this movie:

    http://robterrell.com/htmlTextureWithVNC.m4v

    Note that the "bookmark" cube also reflects the live changes to the remote screen, since it's also running its own VNC connection.
     
  23. gazwi86

    gazwi86

    Joined:
    Jan 25, 2008
    Posts:
    21
    Rob,

    I'm trying to access a level after having used the html texture and it continues to play the mp3 or youtube vid after ive exited the level and sometimes in the inspector once ive stopped testing. Any reason for this?? Ive tried destroying the object and disabling the component before switching levels but no luck...

    have tried building the level too and it has the same effect, as soon as i hit the next level, sound still plays.. Cant see anything in the script that'll address sound and only know javascript so don't know how to call the commands -

    Code (csharp):
    1.  
    2. renderer.material.mainTexture = oldTexture;
    3.         htmlTexture_stop();
    4.  
    That you use on quit to stop it making sound (I assume! as it works on a built version).

    Any help much appreciated, thanks for all your hard work.

    Cheers

    Gaz
     
  24. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Yeah, if you don't call htmlTexture_stop() the texture will remain in the offscreen buffer, and continue to play.

    Two solutions:

    1. Set the offscreen texture to a blank page (i.e. call htmlTexture_setURL("file:///goes/nowhere") or whatever)

    2. Call htmlTexture_stop() when you're done with the offscreen webview, and htmlTexture_start() again when you need to.

    Also -- in the next build, I will make a new function, htmlTexture_stop( id ) that kills the offscreen webview for the given texture ID. Sound good?
     
  25. gazwi86

    gazwi86

    Joined:
    Jan 25, 2008
    Posts:
    21
    Yeh sounds god to me. Haven't had chance to try that code just yet, since I'm working on other aspects of the game but i'll give it a go soon.

    I have another issue tho. Im trying to use flash games in the texture as well as potentially unity web player elements. I can't do this at the moments sinc they require keyboard button events to operate. I dont suppose you've managed to get the htmlTexture to become the focus of the keyboard events yet have you? would also be good for things such as online forms...
     
  26. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    This plugin won't work in webplayers. So you can't use flash stuff in webgames.

    It can be used however in standalone builds
     
  27. gazwi86

    gazwi86

    Joined:
    Jan 25, 2008
    Posts:
    21
    Thats not what im doing... i have a downloadable full version of the game im working on, im just using it to access other smaller games from inside the main unity build. any chance of key input for html pages then??

    Plus where and how am i supposed to implement the bit of script,

    htmlTexture_stop();

    ?? Im coding in javascript and it wont recognize the command, "unknown identifier". Ie tried including the htmlTexture script to no avail...
     
  28. gazwi86

    gazwi86

    Joined:
    Jan 25, 2008
    Posts:
    21
    Did it!! lol my textureplayback script wasnt in the plugins folder so the script...

    GameObject.Find("htmlTexture").SendMessage("goURL", "http://www.the-buzz-online.co.uk/image-gallery-unity.php", SendMessageOptions.DontRequireReceiver);

    wasnt finding the c sharp script!

    Still trying to hear from the big man on if we can pass GetButtonDown type stuff passed through to flash/browser...
     
  29. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Big man? If you're talking about me, hey, don't be mean, it's glandular!

    Regardless: I think I understand how you got the script working from JavaScript. You've got a C# script that has the DLLInterface to the plugin, right? And then your JavaScript finds that object and sends it a message? That's a nice workaround, but we still should be able to use DLLImport from JavaScript, I just haven't dug the secrets of how out of Google yet. (I've seen that, with both this plugin and the UniWii plugin, making sample scripts in JavaScript will really help folks out.)

    Also: I don't think you should have any scripts in the Plugin folder. Actually the engine will probably find them there, but there's nothing special about that folder for anything that isn't a plugin. The script can be anywhere.

    So for sending mouse downs, if you're main script is JavaScript and you're calling a C# script from it, and letting the C# script handle the whole interface to the plugin, then you just need to add methods to the C# class that do what you want (i.e. sending a mousedown, sending keystrokes, calling JavaScript, etc.) and then call those from the JavaScript. The sample project on the wiki does all of those things in C#, so you should be able to start from there.

    Does sending keystrokes work fast enough to play a Flash game within a texture? Interesting... I've never tried it. I bet it would work fine. I was just using Flash GUIs from within the plugin (i.e.and getting the results out of the GUI through a JavaScript call). And now that Unity 2.0 has all those nice GUI objects we actually don't do that anymore.
     
  30. gazwi86

    gazwi86

    Joined:
    Jan 25, 2008
    Posts:
    21
    Well i must say thats a relief! im half way through a project that hinged on it since i was positive i'd seen it done but couldn't remember how.

    So, are you saying it has to be run from a gui for the keystrokes to work??
     
  31. gazwi86

    gazwi86

    Joined:
    Jan 25, 2008
    Posts:
    21
    Hi there, me again. Im trying to access a php and mysql created gallery through the htmlTexture. Only problem being i have to be logged in. Im using a www script to access a login page to start a session then entering the game going to the particular level, and nothing, no images. any idea why?
     
  32. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Hi all,

    I found a toolkit to playback flash movies and get their gfx as a pixel buffer and all.

    It is available as a .DLL , but also as they say as a .NET component.

    Is there anyone why ever worked with .net in unity capable of looking if this is the kind of material unity needs to interface to ?

    http://www.f-in-box.com/dotnet/


    This is of course only a windows solution, but its a starter.


    Question @ Tom Higgins: Is this the type of .net dll which can even be used in a webplayer ???
     
  33. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Lets try to reply asap to my own thread.

    This toolkit seems not to have ANY interaction for mouseclicks or key events. So probably not even worth the look at it.
     
  34. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    That's cool, but it definitely won't work in a webplayer. It is just a wrapper for the flash player ocx that Macromedia provides. WebPlayers won't import any external code, access an native functions (i.e. P/Invoke) or run any native code.

    I have had a number of inquiries about the Windows version of the HTML version, so I'm hoping to get that releasable this weekend.
     
  35. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    That would ROCK !!!

    Your plugin has such a big potential. Really I can imagine some people are willing to pay nice $$$ just to get such functionality in unity textures... (count me in)

    I am trying to create an educational title , where 3D will be used, but also a lot of flash presentations with drag/drop behaviour and such.

    It would be so great to be able to display the flash movie on a cubes face (or on any other model) and have functionality. You could for example put a 3dbook in your scene and if user clicks on it, it could open and show a flash content in the pages :)


    I don't know if this is the correct word, but I am DREWLING (like a dog who sees a big bone)


    Need testers -> Shoot :)
     
  36. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Rob,

    Today I downloaded http://robterrell.com/htmlTextureProject.zip


    There when I run the "texture playback test" scene it works fine and at quite nice fps rate. Even building a standalone build of it (so not trying in the editor) it works ok.

    However: 2 very strange things occur.


    1) The program starts with a screenshot of google and I can click onto links. But I seem not to be able to enter (by keypresses) a url into the search box of google. Is that functionality not in the http://robterrell.com/htmlTextureProject.zip demo ???
    I see htmlTexture_sendKeypress in the TexturePlayback.cs script atached to the plane, but all I get when I press a key is that I get a little sound, but nothing happens.

    2) My unity editor crashes a hell lot of times. Sometimes it crashes even when you edit a script and return to the editor. Other times it will crash when I try to add any other gameobject to the project and when you try to move the main camera with the selection handles in the scene edit, it ALWAYS crashes. This is strange behaviour, because de compiled version never gave me any problems and works very well. Its just in editing mode that it crashes almost as soon as I want to change anything to the project. Did you also encounter such behavious ?

    I tested this with unity 2.0.2f2 (build 13443) on Mac OS X 10.5.2(9c31)

    Posted my crash report at http://pastebin.com/m77d830de


    It says

    Exception Type: EXC_BAD_ACCESS (SIGABRT)
    Exception Codes: KERN_INVALID_ADDRESS at 0x00000000a1e80875

    Could the plugin be referencing memory which it shouldn't or would you know what happens here ?



    Kind regards,

    Bart
     
  37. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Another small thing

    I tried http://www.robterrell.com/mii-v3.swf directly.
    There I see that your mii movie has a hand cursor following nicely the mousecursor (probably with an onmousemoved)

    If I try your example, then it seems not to register that mousemoved. The hand cursor does not move with it.

    However, your application to demonstrate includes an onmouseover handler which even has a PRINT command which does print correct information to the status line, but the mouse is not moved by the htmlTexture_mousemoved function on the line below.


    An error in the example or do I do something wrong here ?
     
  38. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Okay, an update

    http://robterrell.com/htmlTextureProject.zip contains plugin version 0.3

    I downloaded the plugin from the wiki and tried to make my own project with it. Result: Instead of a crash on every move I make in edit mode I only got 1 crash now in about 2 hours of testing time.

    I tested with your Mii creator swf, and mousedowns + mouseups work fine.

    Only things which doesn't seem to work good is sending keys and mousemove. I found out that mousemove may even not do anything. In the mouseover event handler in unity I tried to put a mouseup or a mousedown event, but that is not realy the solution also.


    Any hints on this ?

    For the rest it works very nicely. Just these 2 things which I don't get working.


    Regards,

    Bart
     
  39. gazwi86

    gazwi86

    Joined:
    Jan 25, 2008
    Posts:
    21
    Just finished my a unity game ive done for my university project. Just thought you might like to see what ive managed. theres a number of bugs but i just ran out of time.

    have a look, check out the web site and download it from the downloads section...

    http://www.the-buzz-online.co.uk
     
  40. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    It looks like some change (perhaps webkit, perhaps one of mine that went unnoticed) is sending keypresses into the wrong view, so they aren't being processed anymore. It's probably the same, or related to, the sending of mouseover events. I will take a look into this.

    I haven't seen a crash with this plugin. If you have a crash, please email me the crash log, so I can dig in deeper. One thing to note is that any inputmanagers that hook into webkit (i.e. Inquisitor) tend to mightily mess up anything that uses webkit that isn't Safari.
     
  41. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Rob,

    We really miss you. I don't hear anything anymore.

    Is HTMLtexture plugin discontinued ?


    Kind regards,

    Bart
     
  42. Mark-Ripley

    Mark-Ripley

    Joined:
    Aug 22, 2007
    Posts:
    148
    Any chance of Unity getting together with Mochi and Google so we can play MochiAds and Google video ads in our games?

    Not much point making games with Unity if there's no real way to monetize them...I know a lot of Flash developers who are considering Unity, but won't make the change until there's a way to make money.

    I've approached Mochi directly, they won't do anything until Unity becomes more mainstream...chicken and egg....
     
  43. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    You have a point there
     
  44. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Oh no! It would be very unforunate if this was discontinued :-( I hope that's just temporary silence?

    I'm still hoping that this functionality will eventually make it into Unity and thus into the Web player, but as long as that's not the case, this would at least enable standalone players...
     
  45. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    Very silent indeed. Looks like htmltexture is dead :(

    UNITY TECHNOLOGIES. I this legally possible to have this in the unity engine ? I thought swf format was open now and you can make you own player upto a certain point ?
     
  46. David-Helgason

    David-Helgason

    Moderator

    Joined:
    Mar 29, 2005
    Posts:
    1,104
    Just because the SWF format is open, that doesn't exactly mean that doing a clean-room implementation isn't several years of work. How many other implementations have you seen come out?

    We think a lot about HTML and Flash (and several other technologies), but the hurdles to support them well are not at all insignificant.

    d.
     
  47. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    I see.

    Well I suppose you'll do whats best for unity3D and if it is possible in future it will arrive to the runtime. If not, then ok, these things can happen.
     
  48. bliprob

    bliprob

    Joined:
    May 13, 2007
    Posts:
    901
    Sorry! For some reason I stopped getting emails when people posted to this thread. I didn't realize there were so many posts! Feel free to email me if I go radio silence again.

    This year I got distracted by various non-Unity projects -- paying projects -- so I wasn't able to dedicate the time to the finish the windows plugin. I'm slowly clearing the decks and could spend more time on it.

    As for rendering Flash to a texture -- I have had good success with the htmlTexture plugin for this. MochiAds work fine through the plugin. (Although plugins don't work in the web player, so this is less useful than you might think.) I have also worked a bit with gnash on my most recent project, and had thought about making a gnash plugin for Unity, although I think it's GPL so it might not be a good fit for everyone. It's based on gameSWF, which as I recall is more liberally licensed, but gameSWF isn't as advanced.

    As I've said before, Unity can *have* my plugin code if they want to integrate this into the engine, but the plugin code is so trivial I'd be surprised that they would need it, so I'm guessing it's not currently a priority for them. (Plus, it would be more difficult to support on all platforms Unity supports, i.e. Wii)
     
  49. EducaSoft

    EducaSoft

    Joined:
    Sep 9, 2007
    Posts:
    650
    I think Unity tech can't do anything with it mainly because your technique relies on the fact that FLASH needs to be installed on the computer before your plugin will work.
    And if UT wants to implement it, I think they don't want to be dependent of any other technology. So if they cannot integrate the flash player INSIDE the unity runtime, then I suppose its a nono for them.

    So are you saying now that you are going to continue on the windows plugin?
    That would be so great, even if it only works on standalones.

    Regards,

    Bart
     
  50. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Personally, while I think Flash is cool, I think this plugin is *much* cooler than just a Flash plugin. After all, it renders pretty much any HTML inside of Unity, not just flash, so you can have a "terminal" in your game with an actual Web browser in there.

    The only thing I'd consider a somewhat severe limitation is that it's a plugin and so it can't be used in Web players. So if there's a convenient way for UT to integrate that into the Web player (maybe when the Windows version of it works smoothly), that would be great!

    I also wouldn't think that not supporting Wii or the iPhone on this would be such a great issue. Of course, it would be nice to have - but there's also a few things that are / will be supported by the Wii / iPhone, which can't be used on the Mac/PC.

    Anyways, I'm always looking forward to progress on this, I think it's a really great project!!!